> ## Documentation Index
> Fetch the complete documentation index at: https://docs.trench.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Grafana

> Step-by-step guide to setup Trench with Grafana dashboard

# Setting up Grafana with Trench

This guide will walk you through setting up Grafana with Trench to visualize your analytics data.

## Prerequisites

* Docker installed
* Trench running locally follow [Self-host Quickstart](/quickstart)

## Setup Steps

<Steps>
  <Step title="Run Grafana Container">
    Run the following command to start Grafana. This will make Grafana available at [http://localhost:3001](http://localhost:3001) and connect it to your Trench installation.

    ```bash theme={null}
    docker run -d \
      --name grafana-trench \
      --network trench_app-network \
      -p 3001:3000 \
      grafana/grafana:latest
    ```
  </Step>

  <Step title="Login to Grafana, use default credentials:">
    * Username: `admin`
    * Password: `admin`

    <img src="https://mintcdn.com/frigade-v2-docs/FxFHpZ8uaGl7Kvi_/images/grafana-login.jpeg?fit=max&auto=format&n=FxFHpZ8uaGl7Kvi_&q=85&s=153c7675d1365d8bbf902dddfe3345ce" alt="Grafana Login" width="3248" height="2112" data-path="images/grafana-login.jpeg" />
  </Step>

  <Step title="Install the ClickHouse plugin in Grafana.">
    Go to plugins section and install the ClickHouse plugin.

    <img src="https://mintcdn.com/frigade-v2-docs/FxFHpZ8uaGl7Kvi_/images/grafana-plugin-install.png?fit=max&auto=format&n=FxFHpZ8uaGl7Kvi_&q=85&s=7c13a04a22a6d6a92ce8223b662b445c" alt="Grafana Install ClickHouse" width="3248" height="2112" data-path="images/grafana-plugin-install.png" />
  </Step>

  <Step title="Configure ClickHouse Data Source">
    1. Go to Data Sources section and click on `Add data source`.
    2. Select `ClickHouse` as the data source.
    3. Configure the data source with these settings:
       * Host: `clickhouse`
       * Port: `8123`
       * Protocol: `http`
       * Username: `user`
       * Password: `password`

    <img src="https://mintcdn.com/frigade-v2-docs/FxFHpZ8uaGl7Kvi_/images/grafana-config-datasource.png?fit=max&auto=format&n=FxFHpZ8uaGl7Kvi_&q=85&s=5458c4a2253e33ff56263bb15b7d6742" alt="Grafana ClickHouse Config" width="3248" height="2112" data-path="images/grafana-config-datasource.png" />
  </Step>

  <Step title="Setup Grafana Dashboard">
    You can import the pre-built dashboard using the JSON configuration provided. Download the [JSON configuration](https://raw.githubusercontent.com/FrigadeHQ/trench/refs/heads/main/apps/docs/json/grafana-dashboard.json) and import it into Grafana.

    The Dashboard includes:

    * Unique pageviews over time
    * Time series visualization
    * 6-hour time window by default
  </Step>

  <Step title="Test Setup">
    Here's an example of sending pageview data:

    ```bash theme={null}
    curl --location 'http://localhost:4000/events' \
    --header 'Authorization: Bearer public-d613be4e-di03-4b02-9058-70aa4j04ff28' \
    --header 'Content-Type: application/json' \
    --data '{
    "events": [
        {
          "userId": "550e8400-e29b-41d4-a716-4466554400",
          "type": "track",
          "event": "$pageview",
          "properties": {
            "totalAccounts": 4,
            "country": "Denmark"
          }
        }
      ]
    }'
    ```
  </Step>

  <Step title="View the dashboard">
    New pageviews should be visible in the dashboard.

    <img src="https://mintcdn.com/frigade-v2-docs/FxFHpZ8uaGl7Kvi_/images/grafana-dashboard.png?fit=max&auto=format&n=FxFHpZ8uaGl7Kvi_&q=85&s=5aff48fca25bdae47be41590761f8ffb" alt="Grafana Pageviews" width="3248" height="2112" data-path="images/grafana-dashboard.png" />

    #### Next Steps

    * Customize the dashboard based on your needs
    * Add more panels for different metrics
    * Set up alerts
  </Step>
</Steps>
