简体中文
Appearance
简体中文
Appearance
Datalayers 完全兼容 Prometheus Remote Write 协议,可无缝承接 Prometheus 数据流。本指南将帮助您快速完成数据接入和查询配置。
通过 Prometheus Remote Write 协议,可以将 Prometheus 中的数据快速导入 Datalayers。为此,您需要在 Prometheus 的配置文件中增加以下内容,将 Datalayers 设置为 Remote Write 端点:
remote_write:
- url: https://<host>:<port>/api/v1/write
basic_auth:
username: <username>
password: <password>
headers:
database: <dbname>参数说明:
<host> 和 <port>:Datalayers 服务地址和 HTTP 端口<username> 和 <password>:认证凭据(默认:admin/public)<dbname>:目标数据库名称(需预先创建)# 实际配置示例
remote_write:
- url: "http://localhost:9090/api/v1/write"
basic_auth:
username: admin
password: public
headers:
database: prometheus_metricsDatalayers 提供完整的 Prometheus HTTP API 兼容接口:
/api/v1/query/api/v1/query_range/api/v1/series/api/v1/labels/api/v1/label/<label_name>/values这些接口的输入和输出与 Prometheus 保持一致。例如,您可以通过如下请求查询指标 up 在 2025-07-22T10:00:00Z 时刻的数据:
curl -v \
-u admin:public \
-H "database:prom" \
-d "query=up&time=2025-07-22T10:00:00Z" \
"http://localhost:9090/api/v1/query"{
"status": "success",
"data": {
"resultType": "vector",
"result": [
{ "metric": { "__name__": "up", "sid": "s1", "flag": "ok" }, "value": [ 1753178400.0, "1" ] },
{ "metric": { "__name__": "up", "sid": "s2", "flag": "fail" }, "value": [ 1753178400.0, "0" ] },
{ "metric": { "__name__": "up", "sid": "s3", "flag": "ok" }, "value": [ 1753178400.0, "2" ] }
]
}
}更多关于 API 的内容可参考 Prometheus 官方文档。
相较于 Prometheus,Datalayers 有额外的数据库的概念,每个 metric 都归属于某个数据库,因此在查询时需要显式指明数据库的名称。可通过以下两种方式指定数据库:
database: <dbname>,之后查询的 metric 都会默认归属该数据库__database__ 指定数据库,如 up{__database__="dbname"}。通过这种方式可以覆盖 HTTP header 中指定的数据库。您可以直接将 Datalayers 作为 Prometheus 数据源添加到 Grafana 中,具体步骤如下:
http://<host>:<port>database: <dbname>