Connecting Databend With Grafana
What is Grafana?
The open-source platform for monitoring and observability.
Grafana allows you to query, visualize, alert on and understand your metrics no matter where they are stored. Create, explore, and share dashboards with your team and foster a data-driven culture.
-- From Grafana Project
Grafana
Create a Databend User
Connect to Databend server with BendSQL:
❯ bendsql
Welcome to BendSQL.
Trying connect to localhost:8000 as user root.
Connected to DatabendQuery v1.1.2-nightly-8ade21e4669e0a2cc100615247705feacdf76c5b(rust-1.70.0-nightly-2023-04-15T16:08:52.195357424Z)
Create a user:
CREATE USER grafana IDENTIFIED BY 'grafana_password';
Grant privileges for the user:
GRANT SELECT ON *.* TO grafana;
Install Grafana
Please refer Grafana Installation
Install Grafana Datasource Plugin
Go to grafana plugin page: https://grafana.yourdomain.com/plugins.
Search for
Altinity plugin for ClickHouse
, click install.Go to grafana datasource page: https://grafana.yourdomain.com/datasources.
Click
Add data source
, select previously installed source typeAltinity plugin for ClickHouse
.Configure the datasource:
Necessary fields:
HTTP -> URL
Your databend query clickhouse endpoint, for example:http://localhost:8124
Auth -> Basic auth
enabledBasic Auth Details -> User, Password
previously created grafana userAdditional -> Use POST method to send queries
enabled
tipFor Databend Cloud users, use the endpoint in
connect
, for example:https://tnxxx--small-xxx.ch.aws-us-east-2.default.databend.com
- click
Save & Test
to verify datasource working.
Graphing with Databend
Here we use an existing nginx.access_logs
as an example:
CREATE TABLE `access_logs` (
`timestamp` TIMESTAMP,
`client` VARCHAR,
`method` VARCHAR,
`path` VARCHAR,
`protocol` VARCHAR,
`status` INT,
`size` INT,
`referrer` VARCHAR,
`agent` VARCHAR,
`request` VARCHAR
);
Create a new dashboard with a new panel, select the Datasource created in previous step.
Select
FROM
with database & table and clickGo to Query
:
Input the query with some template variables:
SELECT
(to_int64(timestamp) div 1000000 div $interval * $interval) * 1000 as t, status,
count() as qps
FROM $table
WHERE timestamp >= to_datetime($from) AND timestamp <= to_datetime($to)
GROUP BY t, status
ORDER BY ttipYou can click
Show Help
for available macros, some frequently used are:$interval
replaced with selected "Group by time interval" value (as a number of seconds)$table
replaced with selected table name from Query Builder$from
replaced with (timestamp with ms)/1000 value of UI selected "Time Range:From"$to
replaced with (timestamp with ms)/1000 value of UI selected "Time Range:To"
Then you should be able to see the graph showing:
Adding more panels with this step, we could then have an example dashboard: