Skip to content

Commit aeb8329

Browse files
authored
docs: prioritize Loki protocol for Grafana integration with Databend Cloud (#3061)
1 parent b52407b commit aeb8329

File tree

8 files changed

+146
-14
lines changed

8 files changed

+146
-14
lines changed

docs/en/guides/35-connect/02-visualization/grafana.md

Lines changed: 146 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,140 @@ title: Grafana
33
sidebar_position: 1
44
---
55

6-
[Grafana](https://grafana.com/) is a monitoring dashboard system, which is an open-source monitoring tool developed by Grafana Labs. It can greatly simplify the complexity of monitoring by allowing us to provide the data to be monitored, and it generates various visualizations. Additionally, it has an alarm function that sends notifications when there is an issue with the system. Databend and Databend Cloud can integrate with Grafana through the [Grafana Databend Data Source Plugin](https://github.com/databendlabs/grafana-databend-datasource).
6+
[Grafana](https://grafana.com/) is a monitoring dashboard system, which is an open-source monitoring tool developed by Grafana Labs. It can greatly simplify the complexity of monitoring by allowing us to provide the data to be monitored, and it generates various visualizations. Additionally, it has an alarm function that sends notifications when there is an issue with the system.
77

8-
## Tutorial: Integrating with Grafana
8+
Databend Cloud and Databend can integrate with Grafana in two ways:
99

10-
This tutorial guides you through the process of integrating Databend / Databend Cloud with Grafana using the Grafana Databend Data Source Plugin.
10+
- **Loki Protocol (Recommended for Databend Cloud)**: Use Grafana's built-in Loki data source to connect to Databend Cloud via Loki-compatible API endpoints.
11+
- **Custom Plugin**: Use the [Grafana Databend Data Source Plugin](https://github.com/databendlabs/grafana-databend-datasource) for direct SQL access.
1112

12-
### Step 1. Set up Environment
13+
## Using Loki Protocol (Recommended)
14+
15+
Databend Cloud provides a Loki-compatible API that allows you to use Grafana's native Loki data source without installing additional plugins. This is the recommended approach for most use cases.
16+
17+
:::note
18+
The Loki protocol feature requires activation. Please contact support to enable this feature for your account.
19+
:::
20+
21+
### Step 1. Configure Table
22+
23+
Before connecting to Grafana, configure your Databend Cloud table for log data visualization. Below are two recommended schema types:
24+
25+
#### Loki Schema
26+
27+
This schema stores labels as a VARIANT/MAP alongside the log body:
28+
29+
```sql
30+
CREATE TABLE logs (
31+
`timestamp` TIMESTAMP NOT NULL,
32+
`labels` VARIANT NOT NULL,
33+
`line` STRING NOT NULL,
34+
`stream_hash` UInt64 NOT NULL AS (city64withseed(labels, 0)) STORED
35+
) CLUSTER BY (to_start_of_hour(timestamp), stream_hash);
36+
37+
CREATE INVERTED INDEX logs_line_idx ON logs(line);
38+
REFRESH INVERTED INDEX logs_line_idx ON logs;
39+
```
40+
41+
- `timestamp`: log event timestamp
42+
- `labels`: VARIANT storing serialized Loki labels
43+
- `line`: raw log line
44+
- `stream_hash`: computed hash for clustering
45+
46+
#### Flat Schema
47+
48+
This schema uses a wide table where each attribute is a separate column:
49+
50+
```sql
51+
CREATE TABLE nginx_logs (
52+
`agent` STRING,
53+
`client` STRING,
54+
`host` STRING,
55+
`path` STRING,
56+
`request` STRING,
57+
`status` INT,
58+
`timestamp` TIMESTAMP NOT NULL
59+
) CLUSTER BY (to_start_of_hour(timestamp), host, status);
60+
61+
CREATE INVERTED INDEX nginx_request_idx ON nginx_logs(request);
62+
REFRESH INVERTED INDEX nginx_request_idx ON nginx_logs;
63+
```
64+
65+
Every column except the timestamp and line column becomes a LogQL label.
66+
67+
![Configure Table](/img/connect/grafana-configure-table.png)
68+
69+
### Step 2. Get Connection Information
70+
71+
1. Log in to your Databend Cloud account.
72+
73+
2. On the dashboard, click **Connect** to view the connection information. Note down:
74+
- **Host**: The warehouse endpoint (e.g., `tnxxxxxxx.gw.aws-us-east-2.default.databend.com`)
75+
- **User**: Your username (typically `cloudapp`)
76+
- **Password**: Your password or API key
77+
- **Database**: The database name containing your log table
78+
- **Warehouse**: The warehouse name
79+
80+
![Get Connection Info](/img/connect/grafana-get-connect-info.png)
81+
82+
For detailed information on obtaining connection details, see [Connecting to a Warehouse](/guides/cloud/resources/warehouses#connecting).
83+
84+
### Step 3. Configure Grafana Data Source
1385

14-
Before you start, please refer to the official installation guide to install Grafana: [https://grafana.com/docs/grafana/latest/setup-grafana/installation](https://grafana.com/docs/grafana/latest/setup-grafana/installation).
86+
1. In Grafana, navigate to **Connections** > **Data sources** > **Add data source**.
1587

16-
For this tutorial, you can integrate either with Databend or Databend Cloud:
88+
2. Search for and select **Loki**.
1789

18-
- If you choose to integrate with a local Databend instance, follow the [Deployment Guide](/guides/self-hosted) to deploy it if you don't have one already.
19-
- If you prefer to integrate with Databend Cloud, make sure you can log in to your account and obtain the connection information for a warehouse. For more details, see [Connecting to a Warehouse](/guides/cloud/resources/warehouses#connecting).
90+
3. Configure the basic settings:
91+
- **Name**: Give your data source a descriptive name (e.g., "Databend Cloud Logs")
92+
- **URL**: Enter `https://<host>` using the host from Step 2
93+
94+
![Configure Loki Data Source - Basic](/img/connect/grafana-configure-loki-datasource-basic.png)
95+
96+
4. Configure authentication:
97+
- Enable **Basic auth** under the Authentication section
98+
- **User**: Enter your username (typically `cloudapp`)
99+
- **Password**: Enter your password or API key
100+
101+
5. Add custom HTTP headers. Under **Custom HTTP Headers**, add the following:
102+
- **Header**: `X-Databend-Warehouse`, **Value**: Your warehouse name
103+
- **Header**: `X-Databend-Database`, **Value**: Your database name
104+
- **Header**: `X-Databend-Table`, **Value**: Your table name
105+
106+
![Configure Loki Data Source - Headers](/img/connect/grafana-configure-loki-datasource-header.png)
107+
108+
6. Click **Save & test** to verify the connection.
109+
110+
![Configure Loki Data Source - Complete](/img/connect/grafana-configure-loki-datasource-complete.png)
111+
112+
### Step 4. Test Queries
113+
114+
1. Navigate to **Explore** in Grafana.
115+
116+
2. Select your Databend Cloud Loki data source.
117+
118+
3. Use LogQL queries to visualize your data. For example:
119+
- `{service="api"}` - Filter logs by service label
120+
- `{level="error"}` - Show only error-level logs
121+
- `{service="api"} |= "timeout"` - Search for specific text in logs
122+
- `count_over_time({status="500"}[5m])` - Count errors over time
123+
124+
4. Customize the visualization as needed using Grafana's panel options.
125+
126+
![Test Loki Query with Explore](/img/connect/grafana-test-loki-query-with-explore.png)
127+
128+
## Using Custom Plugin (Alternative)
129+
130+
For advanced use cases requiring direct SQL access or when working with self-hosted Databend, you can use the Grafana Databend Data Source Plugin.
131+
132+
### Step 1. Set up Environment
133+
134+
Before you start, ensure you have:
135+
136+
- Grafana installed. Refer to the official installation guide: [https://grafana.com/docs/grafana/latest/setup-grafana/installation](https://grafana.com/docs/grafana/latest/setup-grafana/installation)
137+
- Either:
138+
- A local Databend instance (follow the [Deployment Guide](/guides/self-hosted) to deploy)
139+
- Or Databend Cloud access with connection information for a warehouse (see [Connecting to a Warehouse](/guides/cloud/resources/warehouses#connecting))
20140

21141
### Step 2. Modify Grafana Configuration
22142

@@ -33,7 +153,7 @@ allow_loading_unsigned_plugins = databend-datasource
33153

34154
2. Get the download URL for the plugin zip package, for example, `https://github.com/databendlabs/grafana-databend-datasource/releases/download/v1.0.2/databend-datasource-1.0.2.zip`.
35155

36-
3. Get the Grafana plugins folder and unzip the downloaded zip package into it.
156+
3. Get the Grafana plugins folder and unzip the downloaded zip package into it:
37157

38158
```shell
39159
curl -fLo /tmp/grafana-databend-datasource.zip https://github.com/databendlabs/grafana-databend-datasource/releases/download/v1.0.2/databend-datasource-1.0.2.zip
@@ -48,14 +168,26 @@ rm /tmp/grafana-databend-datasource.zip
48168
![Plugins](/img/integration/grafana-plugins.png)
49169
![Plugin detail](/img/integration/grafana-plugin-detail.png)
50170

51-
### Step 3. Create Data Source
171+
### Step 4. Configure Data Source
52172

53-
1. Goto the `Add new connection` page, for example, `http://localhost:3000/connections/add-new-connection?search=databend`, search for `databend`, and select it.
173+
1. Go to the `Add new connection` page, for example, `http://localhost:3000/connections/add-new-connection?search=databend`, search for `databend`, and select it.
54174

55175
2. Click **Add new data source** on the top right corner of the page.
56176

57-
3. Input the `DSN` field for your Databend instance. For example, `databend://root:@localhost:8000?sslmode=disable`, or `databend://cloudapp:******@tnxxxxxxx.gw.aws-us-east-2.default.databend.com:443/default?warehouse=xsmall-fsta`.
177+
3. Input the `DSN` field for your Databend instance. For example:
178+
- Self-hosted: `databend://root:@localhost:8000?sslmode=disable`
179+
- Databend Cloud: `databend://cloudapp:******@tnxxxxxxx.gw.aws-us-east-2.default.databend.com:443/default?warehouse=xsmall-fsta`
180+
181+
4. Optionally, input the `SQL User Password` field to override the password in the `DSN` field.
182+
183+
5. Click **Save & test**. If the page displays "Data source is working", the data source has been successfully created.
184+
185+
### Step 5. Test Queries
186+
187+
1. Create a new dashboard and add a panel.
188+
189+
2. Select your Databend data source.
58190

59-
4. Alternatively, input the `SQL User Password` field to override the default password in the `DSN` field.
191+
3. Write SQL queries to retrieve and visualize your data.
60192

61-
5. Click **Save & test**. If the page displays "Data source is working", it indicates that the data source has been successfully created.
193+
4. Configure the panel visualization options as needed.
262 KB
Loading
57.5 KB
Loading
72.1 KB
Loading
412 KB
Loading
135 KB
Loading
118 KB
Loading
999 KB
Loading

0 commit comments

Comments
 (0)