Zabbix 5.0:监控阿里云RDS

2022年01月14日 阅读数:6
这篇文章主要向大家介绍Zabbix 5.0:监控阿里云RDS,主要内容包括基础应用、实用技巧、原理机制等方面,希望对大家有所帮助。

Blog:博客园 我的
因为近期压测,须要频繁登陆阿里云查看RDS监控,每次登陆查看监控步骤较为繁琐,故将监控接入到zabbix。python

概述

因为阿里云已作了RDS的监控,咱们只须要经过阿里云SDK把这些监控数据传输到zabbix便可。json

前提

子帐号

使用阿里云SDK须要一个AK,申请方式以下:api

image-20211028172500213

  • 添加AliyunCloudMonitorReadOnlyAccess权限;

环境

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

调用Api示例

Api:DescribeMetricTopspa

  • 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'))

输出结果以下:code

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

配置模板

经过以上示例,很容易经过脚本获得相关监控数据。orm

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

image-20211028173859926

查看监控数据:

image-20211028174021744

监控图以下:

image-20211028174828895