批量查询监控数据接口V2
更新时间:2024-04-16
接口描述
可获取多实例、多指标、多统计数据的接口,可获取云产品监控数据、站点监控数据或您推送的自定义监控数据。
接口限制
- 一个实例的任意一个指标一次返回的数据点数目不能超过1440个。
 - 一次请求最多支持查询100个实例。
 
请求参数
| 名称 | 类型 | 描述 | 是否必须 | 参数位置 | 
|---|---|---|---|---|
| userId | String | 用户ID | 是 | Body参数 | 
| scope | String | 云产品标识,请参考云产品标识列表 | 是 | Body参数 | 
| region | String | 区域标识,取值请参考区域列表 | 是 | Body参数 | 
| type | String | 监控对象类型,请参考监控对象类型列表 | 是 | Body参数 | 
| metricNames | List<String> | 监控指标列表,仅限于使用如下字符集合:"0~9、A~Z、a~z"、 "_" 当需要查找多个指标项时,使用String数组存储,每个数组元素为一个指标项  | 
是 | Body参数 | 
| statistics | List<String> | 统计方法类型列表,可选值为average、maximum、minimum、sum、sampleCount,需要查询多个统计值时,使用String数组存储 | 是 | Body参数 | 
| dimensions | List<List<Dimension>> | 维度列表,当需要查询多个实例的数据时,使用二维数组查询。一层数组设置多个实例,二层数组设置多个维度 | 是 | Body参数 | 
| startTime | String | 查询起始时间,请参考日期与时间,UTC日期表示 | 是 | Body参数 | 
| endTime | String | 查询截止时间,请参考日期与时间,UTC日期表示 | 是 | Body参数 | 
| cycle | int | 统计周期,60的倍数,单位:秒 | 是 | Body参数 | 
Dimension
| 名称 | 类型 | 描述 | 
|---|---|---|
| name | String | 维度key | 
| value | String | 维度value | 
参数解释
- 名字空间scope、监控项metric、统计方法Statistic、维度Dimension等的概念请参考核心概念。
 
响应结果
| 名称 | 类型 | 描述 | 
|---|---|---|
| requestId | String | 请求标识 | 
| code | String | 返回码 | 
| message | String | 错误信息 | 
| metrics | List<AllDataMetric> | 监控指标 | 
AllDataMetric
| 名称 | 类型 | 描述 | 
|---|---|---|
| region | String | 区域 | 
| scope | String | 云产品标识 | 
| userId | String | 用户Id | 
| resourceId | String | 资源Id | 
| metricName | String | 指标名称 | 
| dimensions | List<Dimension> | 维度列表 | 
| dataPoints | List<DataPoints> | 指标数据 | 
DataPoints
| 名称 | 类型 | 描述 | 
|---|---|---|
| average | double | 统计周期内监控项的平均值 | 
| sum | double | 统计周期内监控项的和值 | 
| minimum | double | 统计周期内监控项的最小值 | 
| maximum | double | 统计周期内监控项的最大值 | 
| sampleCount | int | 统计周期内监控项数据点数 | 
| timestamp | String | 监控项统计周期对应的时间,请参考日期与时间,UTC日期表示 | 
请求示例
                Plain Text
                
            
            1MultiDimensionalMetricsRequest request = new MultiDimensionalMetricsRequest();
2request.setUserId("453bf9********************9090dc");
3request.setScope("BCE_BCC");
4List<String> metricNames = new ArrayList<String>();
5metricNames.add("CPUUsagePercent");
6metricNames.add("MemUsedPercent");
7request.setMetricNames(metricNames);
8request.setStartTime("2024-03-26T07:01:00Z");
9request.setEndTime("2024-03-26T07:05:00Z");
10List<List<Dimension>> dimensions = new ArrayList<List<Dimension>>();
11List<Dimension> d1 = new ArrayList<Dimension>();
12d1.add(new Dimension("InstanceId", "i-M9****s1"));
13List<Dimension> d2 = new ArrayList<Dimension>();
14d2.add(new Dimension("InstanceId", "i-8y****gG"));
15dimensions.add(d1);
16dimensions.add(d2);
17request.setDimensions(dimensions);
18List<String> statistics = new ArrayList<String>();
19statistics.add("sum");
20statistics.add("average");
21request.setStatistics(statistics);
22request.setRegion("bj");
23TsdbMetricAllDataResult result = bcmClient.getAllDataMetricV2(request);
            返回结果
                Plain Text
                
            
            1{
2      "metadata": {
3            "bceRequestId": "9cc92f21-d697-4133-bf2d-bf5f944ce752",
4            "transferEncoding": "chunked",
5            "contentLength": -1,
6            "contentType": "application/json;charset=UTF-8",
7            "date": 1711508479000
8      },
9      "requestId": "9cc92f21-d697-4133-bf2d-bf5f944ce752",
10      "code": "success",
11      "message": "",
12      "metrics": [
13            {
14                  "region": "bj",
15                  "scope": "BCE_BCC",
16                  "userId": "453bf9********************9090dc",
17                  "resourceId": "i-8y****gG",
18                  "metricName": "CPUUsagePercent",
19                  "dimensions": [
20                        {
21                              "name": "InstanceId",
22                              "value": "i-8y****gG"
23                        }
24                  ],
25                  "dataPoints": [
26                        {
27                              "timestamp": "2024-03-26T07:01:00Z",
28                              "average": 7.9346566231995,
29                              "sum": 15.869313246399
30                        }
31                  ]
32            },
33            {
34                  "region": "bj",
35                  "scope": "BCE_BCC",
36                  "userId": "453bf9********************9090dc",
37                  "resourceId": "i-M9****s1",
38                  "metricName": "MemUsedPercent",
39                  "dimensions": [
40                        {
41                              "name": "InstanceId",
42                              "value": "i-M9****s1"
43                        }
44                  ],
45                  "dataPoints": [
46                        {
47                              "timestamp": "2024-03-26T07:01:00Z",
48                              "average": 27.4557088036185,
49                              "sum": 54.911417607237
50                        }
51                  ]
52            },
53            {
54                  "region": "bj",
55                  "scope": "BCE_BCC",
56                  "userId": "453bf9********************9090dc",
57                  "resourceId": "i-M9****s1",
58                  "metricName": "CPUUsagePercent",
59                  "dimensions": [
60                        {
61                              "name": "InstanceId",
62                              "value": "i-M9****s1"
63                        }
64                  ],
65                  "dataPoints": [
66                        {
67                              "timestamp": "2024-03-26T07:01:00Z",
68                              "average": 3.400926389583,
69                              "sum": 6.801852779166
70                        }
71                  ]
72            },
73            {
74                  "region": "bj",
75                  "scope": "BCE_BCC",
76                  "userId": "453bf9********************9090dc",
77                  "resourceId": "i-8y****gG",
78                  "metricName": "MemUsedPercent",
79                  "dimensions": [
80                        {
81                              "name": "InstanceId",
82                              "value": "i-8y****gG"
83                        }
84                  ],
85                  "dataPoints": [
86                        {
87                              "timestamp": "2024-03-26T07:01:00Z",
88                              "average": 20.5017433695395,
89                              "sum": 41.003486739079
90                        }
91                  ]
92            }
93      ]
94}
            