ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
[TOC] > [更多详情](https://prometheus.io/docs/prometheus/latest/querying/api/) ## HTTP API 通过第三方(如:Grafana)调用 prometheus api 获取prometheus信息 ### 格式概述 API响应格式为JSON ``` 2xx 请求成功 400 Bad Request 参数丢失或不正确时。 422 Unprocessable Entity无法执行表达式时(RFC4918)。 503 Service Unavailable 查询超时或中止时。 ``` json 格式 ``` { "status": "success" | "error", "data": <data>, // Only set if status is "error". The data field may still hold // additional data. "errorType": "<string>", "error": "<string>", // Only if there were warnings while executing the request. // There will still be data in the data field. "warnings": ["<string>"] } ``` ### 表达式查询 #### 时间点 ``` GET /api/v1/query POST /api/v1/query ``` * `query=<string>`:Prometheus表达式查询字符串。 * `time=<rfc3339 | unix_timestamp>`:评估时间戳记。可选的,省略表示当前时间。 * `timeout=<duration>`:评估超时。可选的。默认为,并以该`-query.timeout`标志的值为上限 如: ``` curl http://192.168.0.229:9090/api/v1/query?query=node_disk_io_now ``` #### 时间段 ``` GET /api/v1/query_range POST /api/v1/query_range ``` * `query=<string>`:Prometheus表达式查询字符串。 * `start=<rfc3339 | unix_timestamp>`:开始时间戳。 * `end=<rfc3339 | unix_timestamp>`:结束时间戳记。 * `step=<duration | float>`:以`duration`格式或浮点秒数查询分辨率步长。 * `timeout=<duration>`:评估超时。可选的。默认为,并以该`-query.timeout`标志的值为上限 如: ``` curl 'http://localhost:9090/api/v1/query_range?query=up&start=2015-07-01T20:10:30.781Z&end=2015-07-01T20:11:00.781Z&step=15s' ```