Prometheus
GreptimeDB 可以作为 Prometheus 的长期存储。使用 GreptimeDB 作为 Prometheus 的后端存储可以获得无缝体验。由于 Prometheus 支持在配置远程写和读的过程中设置基本的认证信息,用户只需要把配置的用户名和密码添加到配置 YAML 文件中,就可以了。
首先要为存储 Prometheus 的数据创建一个单独的数据库:
sql
1. CREATE DATABASE prometheus;
请按照 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
7. remote_read:
8. - url: http://localhost:4000/v1/prometheus/read?db=prometheus
9. # basic_auth:
10. # username: greptime_user
11. # password: greptime_pwd
注意:请将 greptime_user(username), greptime_pwd(password) 替换为用户自己的用户名和密码,详情请参考客户端鉴权认证。
url 中的 db 参数表示我们要写入的数据库,如果没有指定,则默认为 public。
写入数据成功后,使用下面的命令展示 Prometheus 数据库中的表:
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. +---------------------------------------------------------------+
GreptimeDB 中的 Prometheus 指标
当指标被远程写入 GreptimeDB 时,它们将被转换为下面这样:
| Sample Metrics | In GreptimeDB | GreptimeDB Data Types |
|---|---|---|
| Name | Table (Auto-created) Name | String |
| Value | Column (greptime_value) | Double |
| Timestamp | Column (greptime_timestamp) | Timestamp |
| Label | Column | String |
所有标签列将会被自动创建为主键。当添加新的标签时,它也会自动添加到主键中。
举例: GreptimeDB 表中的 Prometheus 指标
txt
1. prometheus_remote_storage_samples_total{instance="localhost:9090", job="prometheus",
2. remote_name="648f0c", url="http://localhost:4000/v1/prometheus/write"} 500
上面这个例子将被转化为表 prometheus_remote_storage_samples_total 中的一行:
| Column | Value | Column Data Type |
|---|---|---|
| instance | localhost:9090 | String |
| job | prometheus | String |
| remote_name | 648f0c | String |
| url | http://localhost:4000/v1/prometheus/write |
String |
| greptime_value | 500 | Double |
| greptime_timestamp | The sample’s unix timestamp | Timestamp |
