Skip to content

Commit f2f7b1d

Browse files
committed
docs: prometheus
1 parent dc51fe0 commit f2f7b1d

File tree

4 files changed

+124
-0
lines changed

4 files changed

+124
-0
lines changed

dir.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,20 @@
345345
title_cn: Redis 兼容性
346346
path: key-value-data-model/redis-compatibility
347347

348+
- title_en: Prometheus
349+
title_cn: Prometheus 兼容
350+
collapsed: true
351+
children:
352+
- title_en: Overview
353+
title_cn: 概述
354+
path: prometheus/overview
355+
- title_en: Quick Start
356+
title_cn: 快速开始
357+
path: prometheus/quick-start
358+
- title_en: PromQL Compatibility
359+
title_cn: PromQL 兼容性
360+
path: prometheus/promql-compatibility
361+
348362
- title_en: Operation Guide
349363
title_cn: 运维指南
350364
collapsed: true

zh_CN/prometheus/overview.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# 概述
2+
Datalayers 支持 Prometheus 的 HTTP API 和 Remote Write 协议。通过这一特性,用户可以将现有的 Prometheus 生态工具无缝接入 Datalayers,无需修改代码即可实现数据写入和查询。
3+
4+
# 主要特性
5+
- 兼容 Prometheus HTTP API,可直接对接 Grafana 等生态组件。
6+
- 兼容 Prometheus Remote Write 协议,可接收 Prometheus 的实时数据推送。
7+
- 支持 PromQL (Prometheus Query Language),兼容主流查询语法与函数。
8+
9+
# 核心价值
10+
- 平滑迁移: 无需修改现有的数据采集和可视化工具链。
11+
- 高性能/长期存储: 利用 Datalayers 的存储优势,解决原生 Prometheus 在大规模或长期存储场景下的性能和容量瓶颈。
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# PromQL 兼容性
2+
3+
## 选择器
4+
5+
Datalayers 支持 Instant 选择器和 Range 选择器。并且对于普通标签,Datalayers 完整支持四种匹配运算符 (`=, !=, =~, !=`)。
6+
7+
对于特殊标签 `__name__`, `__database__`,Datalayers 目前只支持等值匹配 (`=`),其它运算符将返回错误。
8+
9+
Datalayers 支持 `offset` 修饰符,但不支持 `@` 修饰符。
10+
11+
## 运算符和函数
12+
13+
| 类型 | 支持 | 不支持 |
14+
| :--- | :--- | :--- |
15+
| **运算符** | `neg`, `add`, `sub`, `mul`, `div`, `mod`, `eq`, `ne`, `gt`, `lt`, `ssgt`, `sslt`, `sseq`, `ssne`, `slt`, `sle`, `sge`, `power`, `atan2`, `and`, `or`, `unless` ||
16+
| **聚合** | `sum`, `avg`, `min`, `max`, `stddev`, `stdvar`, `topk`, `bottomk`, `count_values`, `count`, `quantile`, `grouping`| `limitk`, `limit_ratio` |
17+
| **Instant 函数** | `abs`, `ceil`, `exp`, `ln`, `log2`, `log10`, `sqrt`, `acos`, `asin`, `atan`, `sin`, `cos`, `tan`, `acosh`, `asinh`, `atanh`, `sinh`, `cosh`, `scalar`, `tanh`, `timestamp`, `sort`, `sort_desc`, `histogram_quantile`, `predict_linear`, `absent`, `sgn`, `pi`, `deg`, `rad`, `floor`, `clamp`, `clamp_max`, `clamp_min` | 其它 `histogram_<aggr>` 函数|
18+
| **Range 函数** | `idelta`, `<aggr>_over_time` (如 `count_over_time`, `stddev_over_time`, `stdvar_over_time`), `changes`, `delta`, `rate`, `deriv`, `increase`, `irate`, `reset` ||
19+
| **其他函数** | `label_join`, `label_replace`, `sort_by_label`, `sort_by_label_desc` ||

zh_CN/prometheus/quick-start.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Remote Write
2+
3+
通过 Prometheus Remote Write 协议,可以将 Prometheus 中的数据快速导入 Datalayers。为此,您需要在 Prometheus 的配置文件中增加以下内容,将 Datalayers 设置为 Remote Write 端点:
4+
5+
```
6+
remote_write:
7+
- url: https://<host>:<port>/api/v1/write
8+
basic_auth:
9+
username: <username>
10+
password: <password>
11+
headers:
12+
database: <dbname>
13+
```
14+
15+
其中:
16+
17+
- `<host>``<port>` 分别表示 Datalayers 的 IP 地址和 HTTP 端口号
18+
- `<dbname>` 表示数据将要导入的数据库名称,该数据库需要预先创建
19+
- `<username>``<password>` 表示用于认证的用户名和密码
20+
21+
# HTTP API
22+
23+
导入 Datalayers 的数据可以通过以下 Prometheus HTTP API 进行查询:
24+
25+
- Instant queries: `/api/v1/query`
26+
- Range queries: `/api/v1/query_range`
27+
- Series: `/api/v1/series`
28+
- Label names: `/api/v1/labels`
29+
- Label values: `/api/v1/label/<label_name>/values`
30+
31+
这些接口的输入和输出与 Prometheus 保持一致,可以作为其直接替换。例如,您可以通过如下请求查询指标 `up``2025-07-22T10:00:00Z` 时刻的数据:
32+
33+
```
34+
curl -v \
35+
-u admin:public \
36+
-H "database:prom" \
37+
-d "query=up&time=2025-07-22T10:00:00Z" \
38+
"http://localhost:9090/api/v1/query"
39+
```
40+
41+
收到的响应形式如下:
42+
43+
```
44+
{
45+
"status": "success",
46+
"data": {
47+
"resultType": "vector",
48+
"result": [
49+
{ "metric": { "__name__": "up", "sid": "s1", "flag": "ok" }, "value": [ 1753178400.0, "1" ] },
50+
{ "metric": { "__name__": "up", "sid": "s2", "flag": "fail" }, "value": [ 1753178400.0, "0" ] },
51+
{ "metric": { "__name__": "up", "sid": "s3", "flag": "ok" }, "value": [ 1753178400.0, "2" ] }
52+
]
53+
}
54+
}
55+
```
56+
57+
更多关于 HTTP API 的内容可参考![官方文档](https://prometheus.io/docs/prometheus/latest/querying/api/)
58+
59+
## 注意事项
60+
61+
相较于 Prometheus,Datalayers 有额外的数据库的概念,每个 metric 都归属于某个数据库,因此在查询时需要显式指明数据库的名称。
62+
63+
您可以通过两种方式指定数据库:
64+
65+
1. 在 HTTP 请求的 header 中增加 `database: <dbname>`,之后查询的 metric 都会默认归属该数据库
66+
2. 或者通过标签 `__database__` 指定数据库,如 `up{__database__="dbname"}`。通过这种方式可以覆盖 HTTP header 中指定的数据库。
67+
68+
# Grafana
69+
70+
您可以直接将 Datalayers 作为 Prometheus 数据源添加到 Grafana 中,具体步骤如下:
71+
72+
1. 在 Grafana 中 点击 Add new data source,选择 Prometheus 作为数据源
73+
74+
2. 在 Remote server URL 中填入 Datalayers 的地址 `http://<host>:<port>`
75+
76+
3. 在 Authentication method 中选择 Basic authentication,填入用户名和密码
77+
78+
4. 在 Http headers 中增加 header `database: <dbname>`
79+
80+
5. 点击 Save & Test 进行连通性测试,通过后进入面板编写 PromQL 进行查询

0 commit comments

Comments
 (0)