Skip to content

监控

监控是数据库管理的重要组成部分。通过监控指标,你可以评估数据库的状态,维护部署并诊断问题。

请参考指标详情章节了解 GreptimeDB 的具体指标。

启动 GreptimeDB

请参考此处了解如何启动 GreptimeDB。

导出数据到 Prometheus

GreptimeDB 支持导出数据到 Prometheus。 在配置导出数据之前,你需要按照 Prometheus 的官方文档安装 Prometheus.

要从 GreptimeDB 中抓取指标,请编写 Prometheus 配置文件并将其保存为 prometheus.yml

yml
global:
  scrape_interval: 15s 

scrape_configs:
  - job_name: 'greptimedb'
    static_configs:
      # Assuming that GreptimeDB is running locally.
      # The default HTTP port of 4000.
      - targets: ['localhost:4000']
global:
  scrape_interval: 15s 

scrape_configs:
  - job_name: 'greptimedb'
    static_configs:
      # Assuming that GreptimeDB is running locally.
      # The default HTTP port of 4000.
      - targets: ['localhost:4000']

使用该配置文件启动 Prometheus。 例如,使用 Docker 启动 Prometheus 时,可以将配置文件挂载到 Docker 容器中:

bash
docker run \
  -p 9090:9090 \
  -v $(pwd)/prometheus.yml:/etc/prometheus/prometheus.yml \
  prom/prometheus
docker run \
  -p 9090:9090 \
  -v $(pwd)/prometheus.yml:/etc/prometheus/prometheus.yml \
  prom/prometheus

将指标保存到 GreptimeDB 自身

你还可以将指标保存到 GreptimeDB 本身,以便于使用 SQL 语句进行查询和分析。 本节提供了相关配置示例,有关配置的更多详细信息,请参阅监控指标选项

单机模式

在单机模式下,你可以简单地使用 self_import 来导出指标。 相关配置如下:

toml
[export_metrics]
enable=true
# The interval of writing metrics.
write_interval = "30s"
[export_metrics.self_import]
db = "information_schema"
[export_metrics]
enable=true
# The interval of writing metrics.
write_interval = "30s"
[export_metrics.self_import]
db = "information_schema"

db 选项指定了保存指标的数据库,你可以将其修改为其他数据库。

分布式集群

集群中的每个组件都需要编写配置文件。

Frontend

你可以简单地使用 self_import 来导出指标。

toml
[export_metrics]
enable=true
# The interval of writing metrics.
write_interval = "30s"
[export_metrics.self_import]
db = "information_schema"
[export_metrics]
enable=true
# The interval of writing metrics.
write_interval = "30s"
[export_metrics.self_import]
db = "information_schema"

db 选项指定了保存指标的数据库,你可以将其修改为其他数据库。

Datanode 和 Metasrv

在 Datanode 和 Metasrv 中,你需要使用 remote_write 配置来导出指标。

toml
[export_metrics]
enable=true
write_interval = "30s"
[export_metrics.remote_write]
url = "http://127.0.0.1:4000/v1/prometheus/write?db=system"
[export_metrics]
enable=true
write_interval = "30s"
[export_metrics.remote_write]
url = "http://127.0.0.1:4000/v1/prometheus/write?db=system"

GreptimeDB 兼容 Prometheus Remote-Write 协议。 请参考 Prometheus Remote-Write 获取更多信息。

指标详情

可以通过执行curl http://<host>:<port>/metrics的输出来获取 GreptimeDB 的最新指标。

Frontend

KeyType
greptime_table_operator_ingest_rowscounter
greptime_servers_errorcounter
greptime_servers_http_requests_totalcounter
greptime_servers_postgres_connection_countgauge
greptime_servers_mysql_connection_countgauge
greptime_query_merge_scan_regionssummary
greptime_servers_http_sql_elapsedsummary
greptime_query_optimize_physicalplan_elapsedsummary
greptime_frontend_handle_sql_elapsedsummary
greptime_http_track_metricssummary
greptime_query_create_physicalplan_elapsedsummary
greptime_servers_mysql_query_elapsedsummary
greptime_servers_http_requests_elapsedsummary
greptime_query_execute_plan_elapsedsummary
greptime_catalog_kv_get_remotesummary
greptime_grpc_region_requestsummary
greptime_query_merge_scan_poll_elapsedsummary
greptime_catalog_kv_getsummary
greptime_table_operator_create_tablesummary

Datanode

KeyType
greptime_opendal_bytes_totalcounter
greptime_servers_http_requests_totalcounter
greptime_opendal_requests_totalcounter
greptime_catalog_catalog_countgauge
greptime_catalog_schema_countgauge
greptime_opendal_requests_duration_secondssummary
greptime_http_track_metricssummary
greptime_servers_http_requests_elapsedsummary

Meta

KeyType
greptime_meta_create_schemacounter
greptime_servers_http_requests_totalcounter
greptime_meta_create_catalogcounter
greptime_meta_heartbeat_connection_numgauge
greptime_meta_txn_requestsummary
greptime_meta_kv_requestsummary
greptime_meta_create_schemasummary
greptime_meta_create_catalogsummary
greptime_meta_handler_executesummary
greptime_servers_http_requests_elapsedsummary
greptime_http_track_metricssummary
greptime_meta_procedure_create_tablesummary
greptime_grpc_region_requestsummary