|
| 1 | +--- |
| 2 | +title: Prometheus & Grafana |
| 3 | +--- |
| 4 | + |
| 5 | +Databend captures real-time metrics of the meta and query services, which you can access through a web browser using the following URLs: |
| 6 | + |
| 7 | +- Meta Metrics: `http://<admin_api_address>/v1/metrics` |
| 8 | +- Query Metrics: `http://<metric_api_address>/metrics` |
| 9 | + |
| 10 | +Alternatively, you can use Prometheus to capture and store the metrics data from Databend. Then, you can visualize the captured time series data on a dashboard with Grafana. |
| 11 | + |
| 12 | +[Prometheus](https://prometheus.io/) is an open-source monitoring system with a dimensional data model, flexible query language, efficient time series database and modern alerting approach. [Grafana](https://grafana.com/grafana) is an open-source tool used for analyzing and visualizing metrics. |
| 13 | + |
| 14 | +This following tutorial guides you through deploying and integrating Databend, Prometheus, and Grafana. In this tutorial, you'll deploy a local Databend and install Prometheus and Grafana with Docker. Before you start, ensure that you have Docker installed. |
| 15 | + |
| 16 | +## Tutorial: Monitor Databend with Prometheus & Grafana |
| 17 | + |
| 18 | +### Step 1. Deploy Databend |
| 19 | + |
| 20 | +Follow the [Deployment Guide](https://databend.rs/doc/deploy) to deploy a standalone Databend. |
| 21 | + |
| 22 | +:::tip |
| 23 | +This tutorial uses the [default configuration files](https://github.com/datafuselabs/databend/tree/main/scripts/distribution/configs) in the `configs` folder of the install package. The metrics API for databend-meta is `0.0.0.0:28101/v1/metrics`, and the metrics API for databend-query is `0.0.0.0:7070/metrics`. |
| 24 | +::: |
| 25 | + |
| 26 | +### Step 2. Deploy Prometheus |
| 27 | + |
| 28 | +The steps below describe how to install and deploy Prometheus using Docker. |
| 29 | + |
| 30 | +1. Pull the latest Docker image of Prometheus from the Docker Hub registry. |
| 31 | + |
| 32 | + ```bash |
| 33 | + docker pull prom/prometheus |
| 34 | + ``` |
| 35 | + |
| 36 | +2. Edit the configuration file **prometheus.yml**. |
| 37 | + |
| 38 | + Add the following script to the end of the file prometheus.yml that can be found in the `/etc/prometheus/prometheus.yml` directory. Please note that, with Docker, there are multiple ways to modify a file for a container. In this tutorial, we demonstrate how to achieve this by saving the file to a local folder and mapping it when running the Prometheus image. |
| 39 | + |
| 40 | + :::tip |
| 41 | + Docker containers can connect to local services running on the host by using `host.docker.internal`. This feature is available by default only on Docker for Windows/Mac. However, it is also available on Linux starting from version **20.03**. |
| 42 | + ::: |
| 43 | + |
| 44 | + ```yaml |
| 45 | + - job_name: "databend-query" |
| 46 | + |
| 47 | + # metrics_path defaults to '/metrics' |
| 48 | + # scheme defaults to 'http'. |
| 49 | + |
| 50 | + static_configs: |
| 51 | + - targets: ["host.docker.internal:7070"] |
| 52 | + |
| 53 | + - job_name: "databend-meta" |
| 54 | + |
| 55 | + metrics_path: "/v1/metrics" |
| 56 | + # scheme defaults to 'http'. |
| 57 | + |
| 58 | + static_configs: |
| 59 | + - targets: ["host.docker.internal:28101"] |
| 60 | + ``` |
| 61 | +
|
| 62 | +3. Deploy Prometheus. |
| 63 | +
|
| 64 | + If you saved and edited the file `prometheus.yml` in a local folder, you need to create a mapping using the `-v` option in the command. To do so, replace `/path/to/prometheus.yml` in the command below with the path to your local `prometheus.yml`. |
| 65 | + |
| 66 | + ```bash |
| 67 | + docker run \ |
| 68 | + -p 9090:9090 \ |
| 69 | + --add-host=host.docker.internal:host-gateway \ |
| 70 | + -v /path/to/prometheus.yml:/etc/prometheus/prometheus.yml \ |
| 71 | + prom/prometheus |
| 72 | + ``` |
| 73 | + |
| 74 | +4. Check Metrics Status |
| 75 | + |
| 76 | + Check the value on the right of each instance. `1` means the instance is healthy, and `0` means that the scrape failed. |
| 77 | + |
| 78 | +  |
| 79 | + |
| 80 | +### Step 3. Deploy Grafana |
| 81 | + |
| 82 | +The steps below describe how to install and deploy Grafana using Docker. |
| 83 | + |
| 84 | +1. Pull the latest Docker image of Grafana from the Docker Hub registry. |
| 85 | + |
| 86 | + ```bash |
| 87 | + docker pull grafana/grafana |
| 88 | + ``` |
| 89 | + |
| 90 | +2. Deploy Grafana. |
| 91 | + |
| 92 | + ```bash |
| 93 | + docker run \ |
| 94 | + -p 3000:3000 \ |
| 95 | + --add-host=host.docker.internal:host-gateway \ |
| 96 | + grafana/grafana |
| 97 | + ``` |
| 98 | + |
| 99 | +3. Add a data source of Prometheus type. |
| 100 | + |
| 101 | + Open your web browser and go to `http://0.0.0.0:3000`. Log in with the user name `admin` and password `admin` first, and then add a data source of Prometheus type on **Configuration** > **Data Sources** > **Add data source**. |
| 102 | + |
| 103 | + Please note that set the URL to `http://host.docker.internal:9090` for the data source. |
| 104 | + |
| 105 | +  |
| 106 | + |
| 107 | +4. Create dashboards. |
| 108 | + |
| 109 | + Databend recommend import the files in [datafuselabs/helm-charts - dashboards](https://github.com/datafuselabs/helm-charts/tree/main/dashboards) to create your dashboards. To do so, download the files first, then go to `http://0.0.0.0:3000/dashboard/import` to import the downloaded files one by one and select the `Prometheus` data source for each dashboard. |
| 110 | + |
| 111 | +  |
| 112 | + |
| 113 | +  |
0 commit comments