批量查询数据接口
更新时间:2024-04-18
接口描述
可获取批量实例数据的接口,支持多维度多指标查找。可获取云产品监控数据、站点监控数据或您推送的自定义监控数据。
接口限制
• 一个实例的任意一个指标一次返回的数据点数目不能超过1440个。
请求参数
名称 | 类型 | 描述 | 是否必须 | 参数位置 |
---|---|---|---|---|
userId | String | 租户ID | 是 | URL参数 |
scope | String,仅限于使用如下字符集合:"0~9、A~Z、a~z"、 "_" | 名字空间 | 是 | URL参数 |
metricName | String,仅限于使用如下字符集合:"0~9、A~Z、a~z"、 "_" 当需要查找多个指标项时,使用String数组存储,每个数组元素为一个指标项 |
监控指标名 | 是 | Query参数 |
statistics | Statistics,按照statistics1,statistics2,statistics3格式,可选值为average,maximum,minimum,sum,sampleCount | 统计方法类型 | 是 | Query参数 |
dimensions | String,由dimensionName:dimensionValue组成。当监控项具备多个维度时使用分号连接,例如dimensionName:dimensionValue;dimensionName:dimensionValue,相同维度只能指定一个维度值。 需要查找批量实例数据时,使用逗号将各个实例的完整维度连接,例如dimensionName:dimensionValue,dimensionName:dimensionValue |
维度列表 | 是 | Query参数 |
startTime | DateTime,请参考日期与时间,UTC日期表示 | 查询起始时间 | 是 | Query参数 |
endTime | DateTime,请参考日期与时间,UTC日期表示 | 查询截止时间 | 是 | Query参数 |
periodInSecond | int,60的倍数,单位:秒(s) | 统计周期 | 是 | Query参数 |
参数解释
- 名字空间scope、监控项metric、统计方法Statistic、维度Dimension等的概念请参考核心概念。
响应参数
名称 | 类型 | 描述 |
---|---|---|
requestId | String | 请求标识 |
code | String | 返回码 |
message | String | 错误信息 |
errorList | List<ErrorMetricData> | 错误的监控指标 |
successList | List<SuccessMetricData> | 成功的监控指标 |
ErrorMetricData
名称 | 类型 | 描述 |
---|---|---|
metricName | String | 指标名称 |
message | String | 错误信息 |
dimensions | List<Dimension> | 维度信息 |
SuccessMetricData
名称 | 类型 | 描述 |
---|---|---|
metricName | String | 指标名称 |
dimensions | List<Dimension> | 维度信息 |
dataPoints | List<DataPoint> | 监控指标 |
Dimension
名称 | 类型 | 描述 |
---|---|---|
name | String | 维度名 |
value | String | 维度值 |
DataPoint
名称 | 类型 | 描述 |
---|---|---|
average | double | 统计周期内监控项的平均值 |
sum | double | 统计周期内监控项的和值 |
minimum | double | 统计周期内监控项的最小值 |
maximum | double | 统计周期内监控项的最大值 |
sampleCount | int | 统计周期内监控项数据点数 |
timestamp | String | 监控项统计周期对应的时间,UTC日期表示 |
请求示例
Java
1// params definition
2String endpoint = "bcm.bj.baidubce.com";
3String userId = "453bf9********************9090dc";
4String ak = "ALTA********************YG";
5String sk = "b2c5************************3ac1";
6String scope ="BCE_BCC";
7String dimensions = "InstanceId:i-YB****4F,InstanceId:i-R6****xl";
8String[] metrics = {"CPUUsagePercent", "MemUsedPercent"};
9Statistics[] statistics = {Statistics.average, Statistics.maximum};
10long now = System.currentTimeMillis();
11String startTime = DateUtils.formatAlternateIso8601Date(new Date(now - 60 * 60 * 1000));
12String endTime = DateUtils.formatAlternateIso8601Date(new Date(now));
13int periodInSecond = 60;
14
15// create a bcm client
16BcmClientConfiguration config = new BcmClientConfiguration();
17config.setCredentials(new DefaultBceCredentials(ak, sk));
18config.setEndpoint(endpoint);
19BcmClient client = new BcmClient(config);
20
21// query metric data from bcm interface
22ListMetricDataRequest request = new ListMetricDataRequest();
23request.withUserId(userId)
24 .withScope(scope)
25 .withDimensions(dimensions)
26 .withMetricNames(metrics)
27 .withPeriodInSecond(periodInSecond)
28 .withStartTime(startTime)
29 .withEndTime(endTime)
30 .withStatistics(statistics);
31ListMetricDataResponse response = client.getMetricData(request);
32System.out.println(JsonUtils.toJsonString(response));
响应结果
Plain Text
1{
2 "metadata": {
3 "bceRequestId": "024348c6-1ef4-4ee5-a411-c48ddf6b9cdd"
4 },
5 "requestId": "024348c6-1ef4-4ee5-a411-c48ddf6b9cdd",
6 "code": "OK",
7 "message": "",
8 "errorList": null,
9 "successList": [
10 {
11 "metricName": "MemUsedPercent",
12 "dimensions": [
13 {
14 "name": "InstanceId",
15 "value": "i-YB****4F"
16 }
17 ],
18 "dataPoints": [
19 {
20 "average": 5.974418891389501,
21 "sum": null,
22 "maximum": 5.974689065937,
23 "minimum": null,
24 "sampleCount": null,
25 "value": null,
26 "timestamp": "2024-04-11T07:01:00Z"
27 }
28 ]
29 },
30 {
31 "metricName": "CPUUsagePercent",
32 "dimensions": [
33 {
34 "name": "InstanceId",
35 "value": "i-R6****xl"
36 }
37 ],
38 "dataPoints": [
39 {
40 "average": 0.4166418167165,
41 "sum": null,
42 "maximum": 0.483133433283,
43 "minimum": null,
44 "sampleCount": null,
45 "value": null,
46 "timestamp": "2024-04-11T07:01:00Z"
47 }
48 ]
49 },
50 {
51 "metricName": "MemUsedPercent",
52 "dimensions": [
53 {
54 "name": "InstanceId",
55 "value": "i-R6****xl"
56 }
57 ],
58 "dataPoints": [
59 {
60 "average": 4.961740077942499,
61 "sum": null,
62 "maximum": 4.97271004918,
63 "minimum": null,
64 "sampleCount": null,
65 "value": null,
66 "timestamp": "2024-04-11T07:01:00Z"
67 }
68 ]
69 },
70 {
71 "metricName": "CPUUsagePercent",
72 "dimensions": [
73 {
74 "name": "InstanceId",
75 "value": "i-YB****4F"
76 }
77 ],
78 "dataPoints": [
79 {
80 "average": 0.466666770871,
81 "sum": null,
82 "maximum": 0.599941845894,
83 "minimum": null,
84 "sampleCount": null,
85 "value": null,
86 "timestamp": "2024-04-11T07:01:00Z"
87 }
88 ]
89 }
90 ]
91}