Zabbix 5.0:监控阿里云RDS

Blog:博客园 个人
由于近期压测,需要频繁登录阿里云查看RDS监控,每次登录查看监控步骤较为繁琐,故将监控接入到zabbix。

概述

由于阿里云已做了RDS的监控,我们只需要通过阿里云SDK把这些监控数据传输到zabbix即可。

前提

子账号

使用阿里云SDK需要一个AK,申请方式如下:

image-20211028172500213

  • 添加AliyunCloudMonitorReadOnlyAccess权限;

环境

  • Python版本:Python3
  • SDK:aliyun-python-sdk-core、aliyun-python-sdk-cms

调用Api示例

Api:DescribeMetricTop

  • Namespaceacs_rds_dashboard
  • Period默认为60秒,也可以为60的整数倍。

当前云产品的MetricNameDimensions的取值如下表所示。

监控项 单位 MetricName Dimensions Statistics
连接数使用率 % ConnectionUsage userId、instanceId Maximum、Minimum、Average
CPU使用率 % CpuUsage userId、instanceId Maximum、Minimum、Average
只读实例延迟 Second DataDelay userId、instanceId Maximum、Minimum、Average
磁盘使用率 % DiskUsage userId、instanceId Maximum、Minimum、Average
IOPS使用率 % IOPSUsage userId、instanceId Maximum、Minimum、Average
内存使用率 % MemoryUsage userId、instanceId Maximum、Minimum、Average
MySQL_ActiveSessions Count MySQL_ActiveSessions userId、instanceId Maximum、Minimum、Average
MySQL每秒Delete量 CountSecond MySQL_ComDelete userId、instanceId Maximum、Minimum、Average
MySQL每秒Insert量 CountSecond MySQL_ComInsert userId、instanceId Maximum、Minimum、Average
MySQL每秒InsertSelect量 CountSecond MySQL_ComInsertSelect userId、instanceId Maximum、Minimum、Average
MySQL每秒Replace量 CountSecond MySQL_ComReplace userId、instanceId Maximum、Minimum、Average
MySQL每秒ReplaceSelect量 CountSecond MySQL_ComReplaceSelect userId、instanceId Maximum、Minimum、Average
MySQL每秒Select量 CountSecond MySQL_ComSelect userId、instanceId Maximum、Minimum、Average
MySQL每秒Update量 CountSecond MySQL_ComUpdate userId、instanceId Maximum、Minimum、Average
MySQL每秒逻辑读次数 CountSecond MySQL_IbufRequestR userId、instanceId Maximum、Minimum、Average
MySQL每秒逻辑写次数 CountSecond MySQL_IbufRequestW userId、instanceId Maximum、Minimum、Average
MySQL每秒查询量 CountSecond MySQL_QPS userId、instanceId Maximum、Minimum、Average
MySQL每秒事务数 CountSecond MySQL_TPS userId、instanceId Maximum、Minimum、Average
SQLServer网络流入带宽 bit/s SQLServer_NetworkInNew userId、instanceId Maximum、Minimum、Average
SQLServer网络流出带宽 bit/s SQLServer_NetworkOutNew userId、instanceId Maximum、Minimum、Average
MySQL网络流入带宽 bit/s MySQL_NetworkInNew userId、instanceId Average、Minimum、Maximum
MySQL网络流出带宽 bit/s MySQL_NetworkOutNew userId、instanceId Average、Minimum、Maximum
MySQL_BP脏页百分率 % MySQL_IbufDirtyRatio userId、instanceId Average、Maximum、Minimum
MySQL_BP利用率 % MySQL_IbufUseRatio userId、instanceId Average、Maximum、Minimum
MySQL_InnoDB每秒读取数据量 KByte MySQL_InnoDBDataRead userId、instanceId Average、Maximum、Minimum
MySQL_InnoDB每秒写入数据量 KByte MySQL_InnoDBDataWritten userId、instanceId Average、Maximum、Minimum
MySQL每秒创建临时表数量 CountSecond MySQL_TempDiskTableCreates userId、instanceId Average、Maximum、Minimum
MySQL_InnoDB每秒更新行数 CountSecond MySQL_InnoDBRowUpdate userId、instanceId Average、Maximum、Minimum
MySQL_InnoDB每秒插入行数 CountSecond MySQL_InnoDBRowInsert userId、instanceId Average、Maximum、Minimum
MySQL_InnoDB每秒删除行数 CountSecond MySQL_InnoDBRowDelete userId、instanceId Average、Maximum、Minimum
MySQL_InnoDB每秒读取行数 CountSecond MySQL_InnoDBRowRead userId、instanceId Average、Maximum、Minimum
MySQL_InnoDB每秒日志fsync量 CountSecond MySQL_InnoDBLogFsync userId、instanceId Average、Maximum、Minimum
MySQL_InnoDB每秒日志物理写次数 CountSecond MySQL_InnoDBLogWrites userId、instanceId Average、Maximum、Minimum
MySQL_InnoDB每秒日志写请求次数 CountSecond MySQL_InnoDBLogWriteRequests userId、instanceId Average、Maximum、Minimum
MySQL每秒慢查询量 CountSecond MySQL_SlowQueries userId、instanceId Average、Maximum、Minimum
MySQL_BP读命中率 % MySQL_IbufReadHit userId、instanceId Average、Maximum、Minimum
MySQL每秒物理读次数 CountSecond MySQL_ibufPoolReads userId、instanceId Average、Maximum、Minimum
MySQL_数据磁盘使用量 MB MySQL_DataDiskSize userId、instanceId Average、Maximum、Minimum
MySQL_实例磁盘使用量 MB MySQL_InstanceDiskSize userId、instanceId Average、Maximum、Minimum
MySQL_日志磁盘使用量 MB MySQL_LogDiskSize userId、instanceId Average、Maximum、Minimum
MySQL_其他磁盘使用量 MB MySQL_OtherDiskSize userId、instanceId Average、Maximum、Minimum
MySQL_临时磁盘使用量 MB MySQL_TmpDiskSize userId、instanceId Average、Maximum、Minimum
MySQL_ProxyCpu使用率 % MySQL_ProxyCpuUsage userId、instanceId Average、Maximum、Minimum
只读实例IO线程状态 Value MySQL_SlaveIORunning userId、instanceId Average、Maximum、Minimum
只读实例SQL线程状态 Value MySQL_SlaveSQLRunning userId、instanceId Average、Maximum、Minimum
MySQL_线程连接数 Count MySQL_ThreadsConnected userId、instanceId Average、Maximum、Minimum
MySQL_活跃线程数 Count MySQL_ThreadsRunning userId、instanceId Average、Maximum、Minimum

脚本示例:

#!/usr/bin/env python3
#coding=utf-8

from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.acs_exception.exceptions import ClientException
from aliyunsdkcore.acs_exception.exceptions import ServerException
from aliyunsdkcore.auth.credentials import AccessKeyCredential
from aliyunsdkcore.auth.credentials import StsTokenCredential
from aliyunsdkcms.request.v20190101.DescribeMetricTopRequest import DescribeMetricTopRequest

credentials = AccessKeyCredential('<your-access-key-id>', '<your-access-key-secret>')
# use STS Token
# credentials = StsTokenCredential('<your-access-key-id>', '<your-access-key-secret>', '<your-sts-token>')
client = AcsClient(region_id='cn-hangzhou', credential=credentials)

request = DescribeMetricTopRequest()
request.set_accept_format('json')

request.set_Namespace("acs_rds_dashboard")
request.set_MetricName("CpuUsage")
request.set_Orderby("Maximum")
request.set_Dimensions("[{\"instanceId\":\"rm-b*****qc\"}]")

response = client.do_action_with_exception(request)
# python2:  print(response) 
print(str(response, encoding='utf-8'))

输出结果如下:

{
  "RequestId": "D0237455-0978-532A-AG95-C1DG8CD83346",
  "Period": "60",
  "Datapoints": "[{\"order\":1,\"timestamp\":1635413400000,\"userId\":\"186XXXXXXX\",\"instanceId\":\"rm-b*****c\",\"Maximum\":14.95,\"Minimum\":14.95,\"Average\":14.95,\"_count\":1.0}]",
  "Code": "200"
}

配置模板

通过以上示例,很容易通过脚本得到相关监控数据。

脚本完成后,再导入模板,监控项如下:

image-20211028173859926

查看监控数据:

image-20211028174021744

监控图如下:

image-20211028174828895

posted @ 2021-10-28 17:51  不羁的罗恩  阅读(1476)  评论(3编辑  收藏  举报