Skip to main content

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

  1. Go to grafana plugin page: https://grafana.yourdomain.com/plugins.

  2. Search for Altinity plugin for ClickHouse, click install.

  3. Go to grafana datasource page: https://grafana.yourdomain.com/datasources.

  4. Click Add data source, select previously installed source type Altinity plugin for ClickHouse.

  5. Configure the datasource:

    Necessary fields:

    • HTTP -> URL Your databend query clickhouse endpoint, for example: http://localhost:8124
    • Auth -> Basic auth enabled
    • Basic Auth Details -> User, Password previously created grafana user
    • Additional -> Use POST method to send queries enabled
    tip

    For Databend Cloud users, use the endpoint in connect, for example:

    https://tnxxx--small-xxx.ch.aws-us-east-2.default.databend.com

  1. 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
);
  1. Create a new dashboard with a new panel, select the Datasource created in previous step.

  2. Select FROM with database & table and click Go to Query:

  1. 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 t
    tip

    You 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: