Prometheus

GreptimeDB can be used as long-term storage for Prometheus. Using GreptimeDB as a Prometheus backend is a seamless experience. Since Prometheus has built-in support for setting up basic authentication information during the configuration of remote write and read, all you need to do is add your configured username and password to the config YAML file and you’re good to go!

First of all, create a database through your favourite SQL client:

sql

  1. CREATE DATABASE prometheus;

Then please follow the settings in Prometheus configuration (prometheus.yml):

yaml

  1. remote_write:
  2. - url: http://localhost:4000/v1/prometheus/write?db=prometheus
  3. # basic_auth:
  4. # username: greptime_user
  5. # password: greptime_pwd
  6. remote_read:
  7. - url: http://localhost:4000/v1/prometheus/read?db=prometheus
  8. # basic_auth:
  9. # username: greptime_user
  10. # password: greptime_pwd

Note: Be sure to uncomment basic_auth section and replace greptime_user(username), greptime_pwd(password) with your own username and password when you enable database authentication. Please refer to client authentication.

The db parameter in url represents the database that we want to write, it’s public if not present.

Show tables in Prometheus when writing successfully:

sql

  1. use prometheus;
  2. show tables;

sql

  1. +---------------------------------------------------------------+
  2. | Tables |
  3. +---------------------------------------------------------------+
  4. | go_memstats_heap_inuse_bytes |
  5. | go_memstats_last_gc_time_seconds |
  6. | net_conntrack_listener_conn_closed_total |
  7. | prometheus_remote_storage_enqueue_retries_total |
  8. | prometheus_remote_storage_exemplars_pending |
  9. | prometheus_remote_storage_read_request_duration_seconds_count |
  10. | prometheus_rule_group_duration_seconds |
  11. | prometheus_rule_group_duration_seconds_count |
  12. | ...... |
  13. +---------------------------------------------------------------+

Prometheus Metrics in GreptimeDB

When the metrics are written into GreptimeDB by remote write endpoint, they will be transformed as follows:

Sample MetricsIn GreptimeDBGreptimeDB Data Types
NameTable (Auto-created) NameString
ValueColumn (greptime_value)Double
TimestampColumn (greptime_timestamp)Timestamp
LabelColumnString

A primary key with all label columns will be created automatically. When a new label is added, it will be added into primary key automatically too.

Example: Prometheus metrics in GreptimeDB Table

txt

  1. prometheus_remote_storage_samples_total{instance="localhost:9090", job="prometheus",
  2. remote_name="648f0c", url="http://localhost:4000/v1/prometheus/write"} 500

This example will be transformed as a row in the table prometheus_remote_storage_samples_total

ColumnValueColumn Data Type
instancelocalhost:9090String
jobprometheusString
remote_name648f0cString
urlhttp://localhost:4000/v1/prometheus/writeString
greptime_value500Double
greptime_timestampThe sample’s unix timestampTimestamp