查询云数据库MySQL监控
# 1.接口描述
Action:DescribeDBInstancePerformance
描述: 获取云数据库MySQL监控指标
请求地址: http://cdsapi.capitalonline.net/paas/monitor
请求方法: POST
# 2.请求参数
参数名 | 必选 | 类型 | 说明 |
---|---|---|---|
InstanceUuid | 是 | string | 实例编号 |
MetricKey | 是 | string | 可选指标参数(见下表) |
StartTime | 是 | string | 开始时间 |
EndTime | 是 | string | 结束时间 |
# 性能参数表:
API参数名 | 类别 | 类型 | 单位 | 含义 |
---|---|---|---|---|
mysql_cpu_usage | resources | gauge | 百分比 | cpu使用率 |
mysql_mem_usage | resources | gauge | 百分比 | 内存使用率 |
mysql_space_usage | resources | gauge | 百分比 | 挂载的数据磁盘容量使用百分比 |
mysql_network_trffice | resources | gauge | MB/s | 业务网卡流量大小每秒,包括进入流量和出去流量 |
mysql_sessions | engine | gauge | 个 | 当前打开的连接的数量 |
mysql_slow_queries | engine | gauge | 个 | 查询时间超过 long_query_time 秒的查询的个数 |
# 时间粒度:
监控粒度自适应方法如下:
时间跨度 | 监控粒度 | 自适应说明 | 保留时长 |
---|---|---|---|
(0h, 4h] | 30s | 时间跨度在4小时内,监控粒度为5秒 | 1天 |
(4h, 2d] | 1min | 时间跨度超过4小时,但在2天内,监控粒度调整为1分钟 | 15天 |
(2d, 10d] | 5min | 时间跨度超过2天,但在10天内,监控粒度调整为5分钟 | 31天 |
(10d, 30d] | 1h | 时间跨度超过10天,但在30天内,监控粒度调整为1小时 | 62天 |
# 3.请求示例
def get_instance_Performance(instance_uuid, metric_key, start_time, end_time):
"""
获取MySQL监控
:param instance_uuid: 实例uuid
:param metric_key: 性能指标参数
:param start_time: 开始时间
:param end_time: 结束时间
"""
action = "DescribeDBInstancePerformance"
method = "POST"
param = {}
url = get_signature(action, AccessKey, SecretAccessKey, method, monitor_url, param=param)
body = {
"InstanceUuid": instance_uuid,
"MetricKey": metric_key,
"StartTime": start_time,
"EndTime": end_time
}
res = requests.post(url, json=body).json()
print(res)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 4.返回参数
参数名 | 类型 | 说明 |
---|---|---|
Message | str | 信息描述 |
Code | str | 状态码 |
Data | dict | 数据 |
InstanceUuid | str | 实例编号 |
ProductType | str | 产品类型 |
MetricKey | string | 性能指标参数 |
Period | int | 监控粒度(根据时间跨度自适应监控粒度,单位为秒) |
StartTime | string | 开始时间 |
EndTime | string | 结束时间 |
DataPoints | list | 监控数据集合 |
MetricName | string | 性能指标名称 |
MetricType | string | 指标类型(gauge,counter) |
MonitorType | list | 监控类型(resources,engine, engine_extension, deploy) |
Values | list | 监控数据列表 |
Value | float | 监控数值 |
DataTime | string | 监控时间点 |
# 5.返回示例
{
"Code": "Success",
"Data": {
"DataPoints": [{
"MetricName": "slow_queries",
"MetricType": "counter",
"MonitorType": "engine",
"Unit": "次",
"Values": [{
"DateTime": "2020-11-03 14:33:24",
"Value": 4
}, {
"DateTime": "2020-11-03 14:33:54",
"Value": 15
}, {
"DateTime": "2020-11-03 14:34:24",
"Value": 35
}, {
"DateTime": "2020-11-03 14:34:54",
"Value": 67
}]
}],
"EndTime": "2020-11-03 14:35:00",
"InstanceUuid": "b6120f04-63ab-491c-9049-54fca54102bf",
"MetricKey": "mysql_slow_queries",
"Period": 30,
"ProductType": "mysql-replication",
"StartTime": "2020-11-03 14:28:00"
},
"Message": "success",
"TaskId": ""
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32