Prometheus

GreptimeDB can serve as a long-term storage solution for Prometheus, providing a seamless integration experience.

Remote write configuration

To configure Prometheus with GreptimeDB, update your Prometheus configuration file (prometheus.yml) as follows:

  1. remote_write:
  2. - url: http://localhost:4000/v1/prometheus/write?db=public
  3. # Uncomment and set credentials if authentication is enabled
  4. # basic_auth:
  5. # username: greptime_user
  6. # password: greptime_pwd
  7. remote_read:
  8. - url: http://localhost:4000/v1/prometheus/read?db=public
  9. # Uncomment and set credentials if authentication is enabled
  10. # basic_auth:
  11. # username: greptime_user
  12. # password: greptime_pwd
  • The host and port in the URL represent the GreptimeDB server. In this example, the server is running on localhost:4000. You can replace it with your own server address. For the HTTP protocol configuration in GreptimeDB, please refer to the protocol options.
  • The db parameter in the URL represents the database to which we want to write data. It is optional. By default, the database is set to public.
  • basic_auth is the authentication configuration. Fill in the username and password if GreptimeDB authentication is enabled. Please refer to the authentication document.

Data Model

In the data model of GreptimeDB, data is organized into tables with columns for tags, time index, and fields. GreptimeDB can be thought of as a multi-value data model, automatically grouping multiple Prometheus metrics into corresponding tables. This allows for efficient data management and querying.

Data Model

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 (Field)Double
TimestampColumn (Time Index)Timestamp
LabelColumn (Tag)String

For example, the following Prometheus metric:

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

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

Improve efficiency by using metric engine

The Prometheus remote writing always creates a large number of small tables. These tables are classified as logical tables in GreptimeDB. However, having a large number of small tables can be inefficient for both data storage and query performance. To address this, GreptimeDB introduces the metric engine feature, which stores the data represented by the logical tables in a single physical table. This approach reduces storage overhead and improves columnar compression efficiency.

The metric engine is enabled by default in GreptimeDB, and you don’t need to specify any additional configuration. By default, the physical table used is greptime_physical_table. If you want to use a specific physical table, you can specify the physical_table parameter in the remote write URL. If the specified physical table doesn’t exist, it will be automatically created.

  1. remote_write:
  2. - url: http://localhost:4000/v1/prometheus/write?db=public&physical_table=greptime_physical_table

Data is stored in the physical table, while queries are performed on logical tables to provide an intuitive view from a metric perspective. For instance, when successfully writing data, you can use the following command to display the logical tables:

  1. show tables;
  1. +---------------------------------------------------------------+
  2. | Tables |
  3. +---------------------------------------------------------------+
  4. | prometheus_remote_storage_enqueue_retries_total |
  5. | prometheus_remote_storage_exemplars_pending |
  6. | prometheus_remote_storage_read_request_duration_seconds_count |
  7. | prometheus_rule_group_duration_seconds |
  8. | ...... |
  9. +---------------------------------------------------------------+

The physical table itself can also be queried. It contains columns from all the logical tables, making it convenient for multi-join analysis and computation.

To view the schema of the physical table, use the DESC TABLE command:

  1. DESC TABLE greptime_physical_table;

The physical table includes all the columns from the logical tables:

  1. +--------------------+----------------------+------+------+---------+---------------+
  2. | Column | Type | Key | Null | Default | Semantic Type |
  3. +--------------------+----------------------+------+------+---------+---------------+
  4. | greptime_timestamp | TimestampMillisecond | PRI | NO | | TIMESTAMP |
  5. | greptime_value | Float64 | | YES | | FIELD |
  6. | __table_id | UInt32 | PRI | NO | | TAG |
  7. | __tsid | UInt64 | PRI | NO | | TAG |
  8. | device | String | PRI | YES | | TAG |
  9. | instance | String | PRI | YES | | TAG |
  10. | job | String | PRI | YES | | TAG |
  11. | error | String | PRI | YES | | TAG |
  12. ...

You can use the SELECT statement to filter data from the physical table as needed. For example, you can filter data based on the device condition from logical table A and the job condition from logical table B:

  1. SELECT *
  2. FROM greptime_physical_table
  3. WHERE greptime_timestamp > "2024-08-07 03:27:26.964000"
  4. AND device = "device1"
  5. AND job = "job1";

VictoriaMetrics remote write

VictoriaMetrics slightly modified Prometheus remote write protocol for better compression. The protocol is automatically enabled when you are using vmagent to send data to a compatible backend.

GreptimeDB has this variant supported, too. Just configure GreptimeDB’s remote write url for vmagent. For example, if you have GreptimeDB installed locally:

  1. vmagent -remoteWrite.url=http://localhost:4000/v1/prometheus/write