*
查看多个指标在一段时间内的监控数据
请求信息
请求行
POST /v2/metrics/{cluster}/query_range
查询指定集群下多个指标在一段时间内的监控数据,例如:多个节点在一段时间内的 CPU 利用率。可通过请求体设置查询指标及查询时间,指标名称、监控指标变量等参数可通过 GET /v2/metrics/{cluster}/indicators 接口获取。
请求行参数
名称 | 类型 | 是否必填项 | 描述 |
---|---|---|---|
cluster | string | 是 | 集群的名称。 |
请求体
Content-Type
application/json
请求体示例
指标查询范围的请求体。
{
"end": 1640674800,
"queries": [
{
"id": "total",
"indicator": "platform.alerts.fired.count",
"name": "total",
"variables": {
"range": "600s"
}
}
],
"start": 1640671200,
"step": 600
}
请求体说明
名称 | 类型 | 是否必填项 | 描述 |
---|---|---|---|
end | integer | 是 |
结束时间的 Unix 时间戳,以秒为单位。
字段路径:end |
queries | array | 是 |
执行的查询的入参信息。
字段路径:queries |
queries[] | object | 是 |
查询项。
字段路径:queries[] |
queries[].id | string | 是 |
用于区分查询的 id,用户可自定义。例如:有多个查询时,可通过该 ID 来识别每个查询。
字段路径:queries[].id |
queries[].indicator | string | 是 |
指标名称。可通过 GET /v2/metrics/{cluster}/indicators 接口获取。
字段路径:queries[].indicator |
queries[].variables | object | 是 |
监控指标的变量(键/值对)。可通过 GET /v2/metrics/{cluster}/indicators 接口获取。
字段路径:queries[].variables |
start | integer | 是 |
开始时间的 Unix 时间戳,以秒为单位。
字段路径:start |
step | integer | 是 |
查询结果数据的聚合时间,单位:秒。即使用查询时间前 xx 秒内数据进行聚合。
字段路径:step |
返回信息
Content-Type
application/json
状态码: 200
OK
返回体示例
Prometheus 返回的查询结果数据。字段说明请参考:https://prometheus.io/docs/concepts/jobs_instances/#jobs-and-instances
[
{
"id": "total",
"result": [
{
"metric": {
"alert_kind": "cluster"
},
"values": [
[
1640671200,
"0"
],
[
1640671800,
"2"
],
[
1640672400,
"0"
],
[
1640673000,
"0"
],
[
1640673600,
"0"
],
[
1640674200,
"0"
],
[
1640674800,
"0"
]
]
},
{
"metric": {
"alert_kind": "workload"
},
"values": [
[
1640671200,
"0"
],
[
1640671800,
"0"
],
[
1640672400,
"0"
],
[
1640673000,
"0"
],
[
1640673600,
"0"
],
[
1640674200,
"0"
],
[
1640674800,
"0"
]
]
}
],
"resultType": "matrix"
}
]
返回体说明
名称 | 类型 | 描述 |
---|---|---|
[] | object |
Prometheus 返回的查询结果数据。
字段路径:[] |
[].id | string |
查询 id,唯一标识一次查询。
字段路径:[].id |
[].result | array |
从 Prometheus 中查询到的结果中的值。
字段路径:[].result |
[].resultType | string |
Prometheus 表达式数据类型。详细信息请参考:https://prometheus.io/docs/prometheus/latest/querying/basics/#expression-language-data-types
字段路径:[].resultType |
[].result[] | object |
查询结果的值。
字段路径:[].result[] |
result[].metric | object |
从 Prometheus 中查询到的结果中的指标。
字段路径:[].result[].metric |
其他状态码
更多请求体示例
查询多个节点的 CPU 使用量和 CPU 使用率
{
"start":1640935140,
"end":1640938740,
"name":"nearly_1_hour",
"step":60,
"queries":[
{
"id":"cpu_usage_rate",
"indicator":"node.cpu.utilization",
"metricSourceKey":"instance",
"variables":{
"name":".*",
"ip":".*"
}
},
{
"id":"cpu_usage",
"indicator":"node.cpu.usage",
"metricSourceKey":"instance",
"variables":{
"name":".*",
"ip":".*"
}
}
]
}