Connecting Grafana to ClickHouse
With Grafana you can create, explore and share all of your data through dashboards. Grafana requires a plugin to connect to ClickHouse, which is easily installed within their UI.
1. Install the Grafana Plugin for ClickHouse
Before Grafana can talk to ClickHouse, you need to install the appropriate Grafana plugin. Assuming you are logged in to Grafana, follow these steps:
From the Configuration page, select the Plugins tab.
Search for ClickHouse and click on the Signed plugin by Grafana Labs:
On the next screen, click the Install button:
2. Define a ClickHouse data source
Once the installation is complete, click the Create a ClickHouse data source button. (You can also add a data source from the Data sources tab on the Configuration page.)
Either scroll down and find the ClickHouse data source type, or you can search for it in the search bar of the Add data source page. Either way, select the ClickHouse data source type and the following dialog appears:
Enter your server settings and credentials. The key settings are:
- Name: a Grafana setting - give your data source any name you like
- Server address: the URL of your ClickHouse service
- Server port: 9000 for unsecure, 9440 for secure (unless you modified the ClickHouse ports)
- Username and Password: enter your ClickHouse user credentials. If you have not configured users and passwords, then try default for the username and leave the password empty.
- Default database: a Grafana setting - you can specify a database that Grafana defaults to when using this data source (this property can be left blank)
Click the Save & test button to verify that Grafana can connect to your ClickHouse service. If successful, you will see a Data source is working message:
3. Build a dashboard
From the left menu, click on the Dashboards icon and select Browse. Then select the New Dashboard button:
Click the Add a new panel button.
From here, you can build a visualization based on a query. From the Data source dropdown, select your ClickHouse data source that you defined earlier. Then you can either use the Query Builder to build a query visually, or switch to the SQL Editor and enter a SQL query (as shown here):