批量数据查询接口
更新时间:2024-04-18
接口描述
可获取批量实例的接口,支持多维度多指标查找。可获取云产品监控数据、站点监控数据或您推送的自定义监控数据。
接口限制
• 一个实例的任意一个指标一次返回的数据点数目不能超过1440个。
请求参数
名称 | 类型 | 描述 | 是否必须 | 参数位置 |
---|---|---|---|---|
user_id | String | 租户ID | 是 | URL参数 |
scope | String,仅限于使用如下字符集合:"0~9、A~Z、a~z"、 "_" | 名字空间 | 是 | URL参数 |
metric_name | String,仅限于使用如下字符集合:"0~9、A~Z、a~z"、 "_" 当需要查找多个指标项时,使用逗号分开,按照metric1,metric2,metric3格式。 |
监控指标名 | 是 | URL参数 |
statistics | Statistics,按照statistics1,statistics2,statistics3格式,可选值为average,maximum,minimum,sum,sampleCount | 统计方法类型 | 是 | Query参数 |
dimensions | String,由dimensionName:dimensionValue组成。当监控项具备多个维度时使用逗号连接,例如dimensionName:dimensionValue;dimensionName:dimensionValue,相同维度只能指定一个维度值 需要查找批量实例数据时,使用逗号将各个实例的完整维度连接,例如dimensionName:dimensionValue,dimensionName:dimensionValue |
维度列表 | 是 | Query参数 |
start_time | DateTime,请参考日期与时间,UTC日期表示 | 查询起始时间 | 是 | Query参数 |
end_time | DateTime,请参考日期与时间,UTC日期表示 | 查询截止时间 | 是 | Query参数 |
period_in_second | 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日期表示 |
请求示例
Python
1# params definition
2user_id = "453bf9********************9090dc"
3scope = "BCE_BCC"
4metric_name = "CPUUsagePercent,MemUsagePercent"
5dimensions = "InstanceId:i-YB****4F,InstanceId:i-R6****xl"
6statistics = "average,maximum"
7start_time = "2022-05-16T08:25:55Z"
8end_time = "2022-05-16T09:25:55Z"
9period_in_second = 60
10
11# create a bcm client
12bcm_client = BcmClient(bcm_sample_conf.config)
13
14# get batch metric data
15try:
16 response = bcm_client.get_batch_metric_data(user_id=user_id,
17 scope=scope,
18 metric_name=metric_name,
19 dimensions=dimensions,
20 statistics=statistics,
21 start_time=start_time,
22 end_time=end_time,
23 period_in_second=period_in_second)
24 print response
25except BceHttpClientError as e:
26 if isinstance(e.last_error, BceServerError):
27 __logger.error('send request failed. Response %s, code: %s, msg: %s'
28 % (e.last_error.status_code, e.last_error.code, e.last_error.message))
29 else:
30 __logger.error('send request failed. Unknown exception: %s' % e)
响应结果
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}