Prometheus

In this section, we will collect system metric data, such as CPU and memory usage, and sends them to local GreptimeDB.

Write data

Configure

We use Prometheus node_exporter as an example to collect data. To do this, create a file named prometheus.yml and copy the following content into it.

  1. global:
  2. scrape_interval: 10s # The default is every 1 minute.
  3. evaluation_interval: 10s # The default is every 1 minute.
  4. # scrape_timeout is set to the global default (10s).
  5. scrape_configs:
  6. # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  7. - job_name: "node"
  8. static_configs:
  9. - targets: ["node_exporter:9100"]
  10. remote_write:
  11. - url: http://greptimedb:4000/v1/prometheus/write?db=public

The configuration sets the remote_write URL to the Greptime URL and sets the interval for collecting metrics to 10 seconds. The host greptimedb in the URL is the service name of GreptimeDB in the Docker network.

Start Services

We use Docker Compose to start GreptimeDB, Prometheues, node_exporter and Grafana. To do this, create a docker-compose.yml file with the following content:

  1. services:
  2. grafana:
  3. image: grafana/grafana-oss:9.5.15
  4. container_name: grafana
  5. ports:
  6. - 3000:3000
  7. greptime:
  8. image: greptime/greptimedb:v0.7.2
  9. container_name: greptimedb
  10. ports:
  11. - 4000:4000
  12. - 4001:4001
  13. - 4002:4002
  14. - 4003:4003
  15. command: "standalone start --http-addr 0.0.0.0:4000 --rpc-addr 0.0.0.0:4001 --mysql-addr 0.0.0.0:4002 --postgres-addr 0.0.0.0:4003"
  16. volumes:
  17. - ./greptimedb:/tmp/greptimedb
  18. prometheus:
  19. image: prom/prometheus:v2.52.0
  20. container_name: prometheus
  21. depends_on:
  22. - node_exporter
  23. ports:
  24. - 9090:9090
  25. volumes:
  26. - ./prometheus.yml:/etc/prometheus/prometheus.yml:ro
  27. node_exporter:
  28. image: quay.io/prometheus/node-exporter:v1.8.0
  29. container_name: node_exporter_local
  30. ports:
  31. - 9100:9100
  32. command:
  33. - '--path.rootfs=/'
  34. networks: {}

Then run the following command:

  1. docker-compose up

After every service starts successfully, the host metrics will be collected and sent to GreptimeDB.

Visualize Data with Grafana

Add Data Source

You can access Grafana at http://localhost:3000. Use admin as both the username and password to log in.

GreptimeDB can be configured as a Prometheus data source in Grafana. Click the Add data source button and select Prometheus as the type.

add-prometheus-data-source

Fill in the following information:

  • Name: GreptimeDB
  • Prometheus server URL in HTTP: http://greptimedb:4000/v1/prometheus
  • Custom HTTP headers: Click “Add header” and fill in the header x-greptime-db-name with the value public, which is the name of the database.

grafana-prometheus-config.jpg

Then click Save & Test button to test the connection.

For more information on using Prometheus as a data source for GreptimeDB, please refer to Grafana-Prometheus.

Create a Dashboard

To create a new dashboard in Grafana, click the Create your first dashboard button on the home page. Then, click Add visualization and select GreptimeDB as the data source.

To view the metric data on the panel page, select a metric from the Metric drop-down list in the Query tab, and then click Run query. Once you have reviewed the data, click Save to save the panel.

grafana-create-panel-with-selecting-metric

You can also use PromQL to create panels. Click the code button on the right side of the Query tab to switch to the PromQL editor. Then, enter a PromQL statement, such as system_memory_usage{state="used"}, and click Run query to view the metric data.

grafana-create-panel-with-promql

Prometheus - 图5NOTE

GreptimeDB is compatible with most of PromQL, but there are some limitations. Please refer to the PromQL Limitations documentation for more information.

Next Steps

Congratulations on quickly experiencing the basic features of GreptimeDB! Now, you can explore more of GreptimeDB’s features by visiting the User Guide documentation.