Prometheus Query Language
GreptimeDB 可以作为 Grafana 中 Prometheus 的替代品,因为 GreptimeDB 支持 PromQL(Prometheus Query Language)。GreptimeDB 在 Rust 中重新实现了 PromQL,并通过接口将能力开放,包括 Prometheus 的 HTTP API、GreptimeDB 的 HTTP API 和 SQL 接口。
Prometheus 的 HTTP API
GreptimeDB 实现了兼容 Prometheus 的一系列 API,通过 /v1/prometheus 路径对外提
供服务:
- Instant queries
/api/v1/query - Range queries
/api/v1/query_range - Series
/api/v1/series - Label names
/api/v1/labels - Label values
/api/v1/label/<label_name>/values
这些接口的输入和输出与原生的 Prometheus HTTP API 相同,用户可以把 GreptimeDB 当
作 Prometheus 的直接替换。例如,在 Grafana 中我们可以设置
http://localhost:4000/v1/prometheus/ 作为其 Prometheus 数据源的地址。
访问 Prometheus 文档 获得更详细的说明。
你可以通过设置 HTTP 请求的 db 参数来指定 GreptimeDB 中的数据库名。
例如,以下查询将返回 public 数据库中 process_cpu_seconds_total 指标的 CPU 使用率:
curl -X POST \
-H 'Authorization: Basic {{authorization if exists}}' \
--data-urlencode 'query=irate(process_cpu_seconds_total[1h])' \
--data-urlencode 'start=2024-11-24T00:00:00Z' \
--data-urlencode 'end=2024-11-25T00:00:00Z' \
--data-urlencode 'step=1h' \
'http://localhost:4000/v1/prometheus/api/v1/query_range?db=public'