最近更新时间:2025-06-12 13:41:59
有数据查询需求时,可以通过查询 API 请求监控数据。
通过云监控 Prometheus HTTP API 使用时,需要通过 Bearer Token 的方式进行鉴权访问。
Token 从对应 Promthues 实例详情页面中获取,如图所示:
GET /api/v1/query
POST /api/v1/queryquery=<string>: Prometheus:查询表达式。
time=<rfc3339 | unix_timestamp>:时间戳, 可选。
timeout=<duration>:检测超时时间,可选。 默认由 -query.timeout 参数指定。
根据时间范围查询我们需要的数据是我们面临的最多的场景,这时我们需要用到 /api/v1/query_range 接口,示例如下:
$ curl --location 'https://{endpoint}/api/v1/query_range?query=up&start=2025-06-01T20:10:30.781Z&end=2025-06-01T20:30:00.781Z&step=60' \
--header 'Authorization: ••••••'
返回:
{
"status": "success",
"isPartial": false,
"data": {
"resultType": "matrix",
"result": [
{
"metric": {
"__name__": "up",
"instance": "localhost:9090",
"job": "prometheus"
},
"values": [
[
1748808630.781,
"1"
],
[
1748808690.781,
"1"
],
[
1748808750.781,
"1"
],
[
1748808810.781,
"1"
],
[
1748808870.781,
"1"
],
[
1748808930.781,
"1"
],
[
1748808990.781,
"1"
],
[
1748809050.781,
"1"
],
[
1748809110.781,
"1"
],
[
1748809170.781,
"1"
],
[
1748809230.781,
"1"
],
[
1748809290.781,
"1"
],
[
1748809350.781,
"1"
],
[
1748809410.781,
"1"
],
[
1748809470.781,
"1"
],
[
1748809530.781,
"1"
],
[
1748809590.781,
"1"
],
[
1748809650.781,
"1"
],
[
1748809710.781,
"1"
],
[
1748809770.781,
"1"
]
]
}
]
}
}
纯净模式
