Menu
Grafana Cloud

ClickHouse integration for Grafana Cloud

ClickHouse is an open-source column-oriented database management system that allows generating analytical data reports in real-time. The ClickHouse integration uses the Grafana agent to collect metrics to monitor a ClickHouse cluster that can be used to easily select metrics via cluster instance. The integration also supports the ClickHouse error logs being scraped by the agent using Promtail. An accompanying dashboard is provided to visualize these metrics and logs.

This integration supports ClickHouse 22.6.8.35+.

This integration includes 4 useful alerts and 4 pre-built dashboards to help monitor and visualize ClickHouse metrics and logs.

Before you begin

ClickHouse supports multi-file configurations using either a /etc/clickhouse-server/config.xml or /etc/clickhouse-server/config.yaml. This example shows config.xml snippets required to collect metrics and logs.

Prometheus metrics are scraped using the ClickHouse Exporter that must be configured in the config.xml file. Some ClickHouse installations have the prometheus exporter commented out, else include this snippet:

xml
    <prometheus>
        <endpoint>/metrics</endpoint>
        <port>9363</port>
        <metrics>true</metrics>
        <events>true</events>
        <asynchronous_metrics>true</asynchronous_metrics>
        <status_info>true</status_info>
    </prometheus>

For more information please check out Prometheus.

ClickHouse error logs are scraped using a Promtail agent that targets the default /var/log/clickhouse-server/clickhouse-server.err.log path. Logs are enabled by including the target path inside the <errorlog> within the config.xml file. Some ClickHouse installations have the error log set by default, which would be located at the top of the config.xml file.

xml
    <logger>
        <errorlog>/var/log/clickhouse-server/clickhouse-server.err.log</errorlog>
    </logger>

For more information please check ClickHouse logger settings.

After editing the config.xml file, restart the ClickHouse server:

sh
sudo service clickhouse-server restart

Install ClickHouse integration for Grafana Cloud

  1. In your Grafana Cloud stack, click Connections in the left-hand menu.
  2. Find ClickHouse and click its tile to open the integration.
  3. Review the prerequisites in the Configuration Details tab and set up Grafana Agent to send ClickHouse metrics and logs to your Grafana Cloud instance.
  4. Click Install to add this integration’s pre-built dashboards and alerts to your Grafana Cloud instance, and you can start monitoring your ClickHouse setup.

Post-install configuration for the ClickHouse integration

This integration supports metrics and logs from a ClickHouse instance. The Grafana Agent config is stored in /etc/grafana-agent.yaml.

Enable the integration by adding the snippets above to your agent configuration file.

If you want to show logs and metrics signals correlated in your dashboards, as a single pane of glass, ensure the following:

  • job and instance label values must match for metrics and logs scrape configs in your agent configuration file.
  • job label must be set to integrations/clickhouse (already configured in the snippets).
  • instance label must be set to a value that uniquely identifies your ClickHouse Node. Please replace the default <your-instance-name> value according to your environment - it should be set manually. Note that if you use localhost for multiple nodes, the dashboards will not be able to filter correctly by instance.

Additionally, to gather logs from a Linux host using the Grafana Agent, add the Grafana Agent user as an owner of your ClickHouse instance logs. For example, if you are running on Debian and the default clickhouse group is being used:

sh
sudo usermod -a -G clickhouse grafana-agent

Configuration snippets for Grafana Agent

Below metrics.configs.scrape_configs, insert the following lines and change the URLs according to your environment:

yaml
    - job_name: integrations/clickhouse
      relabel_configs:
        - replacement: '<your-instance-name>'
          target_label: instance
      static_configs:
        - targets: ['localhost:9363']

Below logs.configs.scrape_configs, insert the following lines according to your environment.

yaml
    - job_name: integrations/clickhouse
      static_configs:
      - targets:
        - localhost
        labels:
          instance: '<your-instance-name>'
          job: integrations/clickhouse
          __path__: /var/log/clickhouse-server/clickhouse-server.log
      pipeline_stages:
      - multiline:
          firstline: '^([\d]{4}).([\d]{1,2}).([\d]{1,2}) (([\d]+):([\d]+):([\d]+).([\d]+))'
      - regex:
          expression: '(?P<timestamp>([\d]{4}).([\d]{1,2}).([\d]{1,2}) (([\d]+):([\d]+):([\d]+).([\d]+))) \[ \d+ \] \{.*\} <(?P<level>.+)> (?P<message>(?s:.*))$'
      - labels:
          level:

Full example configuration for Grafana Agent

Refer to the following Grafana Agent configuration for a complete example that contains all the snippets used for the ClickHouse integration. This example also includes metrics that are sent to monitor your Grafana Agent instance.

yaml
integrations:
  prometheus_remote_write:
  - basic_auth:
      password: <your_prom_pass>
      username: <your_prom_user>
    url: <your_prom_url>
  agent:
    enabled: true
    relabel_configs:
    - action: replace
      source_labels:
      - agent_hostname
      target_label: instance
    - action: replace
      target_label: job
      replacement: "integrations/agent-check"
    metric_relabel_configs:
    - action: keep
      regex: (prometheus_target_sync_length_seconds_sum|prometheus_target_scrapes_.*|prometheus_target_interval.*|prometheus_sd_discovered_targets|agent_build.*|agent_wal_samples_appended_total|process_start_time_seconds)
      source_labels:
      - __name__
  # Add here any snippet that belongs to the `integrations` section.
  # For a correct indentation, paste snippets copied from Grafana Cloud at the beginning of the line.
logs:
  configs:
  - clients:
    - basic_auth:
        password: <your_loki_pass>
        username: <your_loki_user>
      url: <your_loki_url>
    name: integrations
    positions:
      filename: /tmp/positions.yaml
    scrape_configs:
      # Add here any snippet that belongs to the `logs.configs.scrape_configs` section.
      # For a correct indentation, paste snippets copied from Grafana Cloud at the beginning of the line.
    - job_name: integrations/clickhouse
      static_configs:
      - targets:
        - localhost
        labels:
          instance: '<your-instance-name>'
          job: integrations/clickhouse
          __path__: /var/log/clickhouse-server/clickhouse-server.log
      pipeline_stages:
      - multiline:
          firstline: '^([\d]{4}).([\d]{1,2}).([\d]{1,2}) (([\d]+):([\d]+):([\d]+).([\d]+))'
      - regex:
          expression: '(?P<timestamp>([\d]{4}).([\d]{1,2}).([\d]{1,2}) (([\d]+):([\d]+):([\d]+).([\d]+))) \[ \d+ \] \{.*\} <(?P<level>.+)> (?P<message>(?s:.*))$'
      - labels:
          level:
metrics:
  configs:
  - name: integrations
    remote_write:
    - basic_auth:
        password: <your_prom_pass>
        username: <your_prom_user>
      url: <your_prom_url>
    scrape_configs:
      # Add here any snippet that belongs to the `metrics.configs.scrape_configs` section.
      # For a correct indentation, paste snippets copied from Grafana Cloud at the beginning of the line.
    - job_name: integrations/clickhouse
      relabel_configs:
        - replacement: '<your-instance-name>'
          target_label: instance
      static_configs:
        - targets: ['localhost:9363']
  global:
    scrape_interval: 60s
  wal_directory: /tmp/grafana-agent-wal

Dashboards

The ClickHouse integration installs the following dashboards in your Grafana Cloud instance to help monitor your system.

  • ClickHouse latency
  • ClickHouse logs
  • ClickHouse overview
  • ClickHouse replica

ClickHouse Overview Dashboard 1

ClickHouse Overview Dashboard 1

ClickHouse Overview Dashboard 2

ClickHouse Overview Dashboard 2

ClickHouse Latency Dashboard

ClickHouse Latency Dashboard

Alerts

The ClickHouse integration includes the following useful alerts:

AlertDescription
ClickHouseReplicationQueueBackingUpWarning: ClickHouse replica max queue size backing up.
ClickHouseRejectedInsertsCritical: ClickHouse has too many rejected inserts.
ClickHouseZookeeperSessionsCritical: ClickHouse has too many Zookeeper sessions.
ClickHouseReplicasInReadOnlyCritical: ClickHouse has too many replicas in read only state.

Metrics

The most important metrics provided by the ClickHouse integration, which are used on the pre-built dashboards and Prometheus alerts, are as follows:

  • ClickHouseAsyncMetrics_OSMemoryTotal
  • ClickHouseAsyncMetrics_ReplicasMaxQueueSize
  • ClickHouseMetrics_HTTPConnection
  • ClickHouseMetrics_InterserverConnection
  • ClickHouseMetrics_MemoryTracking
  • ClickHouseMetrics_MySQLConnection
  • ClickHouseMetrics_PostgreSQLConnection
  • ClickHouseMetrics_ReadonlyReplica
  • ClickHouseMetrics_TCPConnection
  • ClickHouseMetrics_ZooKeeperRequest
  • ClickHouseMetrics_ZooKeeperSession
  • ClickHouseMetrics_ZooKeeperWatch
  • ClickHouseProfileEvents_AsyncInsertQuery
  • ClickHouseProfileEvents_DiskReadElapsedMicroseconds
  • ClickHouseProfileEvents_DiskWriteElapsedMicroseconds
  • ClickHouseProfileEvents_FailedInsertQuery
  • ClickHouseProfileEvents_FailedQuery
  • ClickHouseProfileEvents_FailedSelectQuery
  • ClickHouseProfileEvents_InsertQuery
  • ClickHouseProfileEvents_NetworkReceiveBytes
  • ClickHouseProfileEvents_NetworkSendBytes
  • ClickHouseProfileEvents_NetworkSendElapsedMicroseconds
  • ClickHouseProfileEvents_Query
  • ClickHouseProfileEvents_RejectedInserts
  • ClickHouseProfileEvents_ReplicatedPartChecks
  • ClickHouseProfileEvents_ReplicatedPartFetches
  • ClickHouseProfileEvents_ReplicatedPartMerges
  • ClickHouseProfileEvents_ReplicatedPartMutations
  • ClickHouseProfileEvents_SelectQuery
  • ClickHouseProfileEvents_ZooKeeperWaitMicroseconds

Changelog

md
# 1.0.0 - November 2023

* Added Grafana Agent Operator configuration snippet to support Clickhouse in kubernetes cluster
* Added cluster selector to dashboard for kubernetes support
* Update Grafana Agent configuration snippets to include filtered metrics used in gauge panels

# 0.1.2 - September 2023

* New Filter Metrics option for configuring the Grafana Agent, which saves on metrics cost by dropping any metric not used by this integration. Beware that anything custom built using metrics that are not on the snippet will stop working.
* New hostname relabel option, which applies the instance name you write on the text box to the Grafana Agent configuration snippets, making it easier and less error prone to configure this mandatory label.

# 0.1.1 - August 2023

* Add regex filter for logs datasource

# 0.1.0 - July 2023

* Update logs
  * Move logs panel to separate dashboard
  * Update agent logs snippet to extract level label and collect all logs

# 0.0.2 - May 2023

* Update legends for latency metrics

# 0.0.1 - February 2023

* Initial release

Cost

By connecting your ClickHouse instance to Grafana Cloud, you might incur charges. To view information on the number of active series that your Grafana Cloud account uses for metrics included in each Cloud tier, see Active series and dpm usage and Cloud tier pricing.