prometheus-api
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePrometheus API Skill
Prometheus API 技能
Query Prometheus monitoring systems via HTTP API at .
/api/v1通过路径为的HTTP API查询Prometheus监控系统。
/api/v1Quick Reference
快速参考
Instant Query
即时查询
bash
curl 'http://<prometheus>:9090/api/v1/query?query=<promql>&time=<timestamp>'bash
curl 'http://<prometheus>:9090/api/v1/query?query=<promql>&time=<timestamp>'Range Query
范围查询
bash
curl 'http://<prometheus>:9090/api/v1/query_range?query=<promql>&start=<ts>&end=<ts>&step=<duration>'bash
curl 'http://<prometheus>:9090/api/v1/query_range?query=<promql>&start=<ts>&end=<ts>&step=<duration>'Response Format
响应格式
All responses return JSON:
json
{
"status": "success" | "error",
"data": <result>,
"errorType": "<string>",
"error": "<string>",
"warnings": ["<string>"]
}HTTP codes: (bad params), (expression error), (timeout).
400422503所有响应均返回JSON格式:
json
{
"status": "success" | "error",
"data": <result>,
"errorType": "<string>",
"error": "<string>",
"warnings": ["<string>"]
}HTTP状态码:(参数错误)、(表达式错误)、(请求超时)。
400422503Query Endpoints
查询端点
| Endpoint | Purpose | Key Parameters |
|---|---|---|
| Instant query | |
| Range query | |
| Format PromQL | |
| Find series by labels | |
| List label names | |
| Label values | |
| Query exemplars | |
| 端点 | 用途 | 关键参数 |
|---|---|---|
| 即时查询 | |
| 范围查询 | |
| 格式化PromQL | |
| 通过标签查找时序 | |
| 列出标签名称 | |
| 查询标签值 | |
| 查询示例数据 | |
Metadata & Status Endpoints
元数据与状态端点
| Endpoint | Purpose |
|---|---|
| Target discovery status ( |
| Metric metadata from targets |
| All metric metadata |
| Alerting/recording rules |
| Active alerts |
| Alertmanager discovery |
| Current config YAML |
| CLI flags |
| Runtime info |
| Build info |
| TSDB cardinality stats |
| WAL replay progress |
| 端点 | 用途 |
|---|---|
| 目标发现状态( |
| 来自监控目标的指标元数据 |
| 所有指标元数据 |
| 告警/记录规则 |
| 活跃告警 |
| Alertmanager发现状态 |
| 当前配置YAML |
| CLI启动参数 |
| 运行时信息 |
| 构建信息 |
| TSDB基数统计 |
| WAL重放进度 |
Admin Endpoints (require --web.enable-admin-api
)
--web.enable-admin-api管理端点(需要开启--web.enable-admin-api
参数)
--web.enable-admin-api| Endpoint | Method | Purpose |
|---|---|---|
| POST | Create TSDB snapshot |
| POST | Delete series ( |
| POST | Clean deleted data |
| 端点 | 请求方法 | 用途 |
|---|---|---|
| POST | 创建TSDB快照 |
| POST | 删除时序(参数 |
| POST | 清理已删除数据 |
Common PromQL Patterns
常用PromQL模式
promql
undefinedpromql
undefinedRate of counter over 5m
5分钟内计数器的增长率
rate(http_requests_total[5m])
rate(http_requests_total[5m])
Sum by label
按标签求和
sum by (job) (rate(http_requests_total[5m]))
sum by (job) (rate(http_requests_total[5m]))
Percentile from histogram
直方图百分位计算
histogram_quantile(0.95, rate(http_request_duration_seconds_bucket[5m]))
histogram_quantile(0.95, rate(http_request_duration_seconds_bucket[5m]))
Filter by label
按标签过滤
up{job="prometheus", instance=~".*:9090"}
up{job="prometheus", instance=~".*:9090"}
Increase over time
时间段内的增长量
increase(http_requests_total[1h])
increase(http_requests_total[1h])
Average over time range
时间范围内的平均值
avg_over_time(process_cpu_seconds_total[5m])
undefinedavg_over_time(process_cpu_seconds_total[5m])
undefinedResult Types
结果类型
- vector:
[{"metric": {...}, "value": [timestamp, "value"]}] - matrix:
[{"metric": {...}, "values": [[ts, "val"], ...]}] - scalar:
[timestamp, "value"] - string:
[timestamp, "string"]
- vector:
[{"metric": {...}, "value": [timestamp, "value"]}] - matrix:
[{"metric": {...}, "values": [[ts, "val"], ...]}] - scalar:
[timestamp, "value"] - string:
[timestamp, "string"]
Scripts
脚本
Query script:
scripts/prom_query.pybash
undefined查询脚本:
scripts/prom_query.pybash
undefinedInstant query
即时查询
python scripts/prom_query.py http://localhost:9090 'up'
python scripts/prom_query.py http://localhost:9090 'up'
Range query
范围查询
python scripts/prom_query.py http://localhost:9090 'rate(http_requests_total[5m])'
--start '2024-01-01T00:00:00Z' --end '2024-01-01T01:00:00Z' --step '1m'
--start '2024-01-01T00:00:00Z' --end '2024-01-01T01:00:00Z' --step '1m'
python scripts/prom_query.py http://localhost:9090 'rate(http_requests_total[5m])'
--start '2024-01-01T00:00:00Z' --end '2024-01-01T01:00:00Z' --step '1m'
--start '2024-01-01T00:00:00Z' --end '2024-01-01T01:00:00Z' --step '1m'
Output: table, json, csv
输出格式:table、json、csv
python scripts/prom_query.py http://localhost:9090 'up' --format table
Health check: `scripts/prom_health.py`
```bash
python scripts/prom_health.py http://localhost:9090python scripts/prom_query.py http://localhost:9090 'up' --format table
健康检查:`scripts/prom_health.py`
```bash
python scripts/prom_health.py http://localhost:9090Detailed Reference
详细参考
For complete API documentation: references/api_reference.md
For PromQL functions: references/promql_functions.md
完整API文档:references/api_reference.md
PromQL函数说明:references/promql_functions.md