api调试地址
https://api.aliyun.com/?spm=a2c4g.11186623.2.16.2f352ef74mLr9A#product=Cms&api=DescribeSiteMonitorData
api监控指标项:
https://help.aliyun.com/document_detail/28619.html?spm=a2c4g.11186623.2.15.67e05679fpgajb#h2-url-31
对接api脚本
安装基础依赖
pip install aliyun-python-sdk-core
安装监控SDK
pip install aliyun-python-sdk-cms
本文主要展示 kafka应用和阿里云SLB 应用,其他应用雷同
kafka脚本内容:
#!/usr/bin/env python
#coding=utf-8
import json
import sys
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.acs_exception.exceptions import ClientException
from aliyunsdkcore.acs_exception.exceptions import ServerException
from aliyunsdkcms.request.v20190101.DescribeMetricListRequest import DescribeMetricListRequest
def query_request(Namespace,MetricName):
client = AcsClient('xxxx', 'xxxx', 'cn-hangzhou')
request = DescribeMetricListRequest()
request.set_accept_format('json')
request.set_MetricName(MetricName)
request.set_Namespace(Namespace)
request.set_Length("1")
response = client.do_action_with_exception(request)
Arr = json.loads(response)
i = eval(Arr['Datapoints'])
for i in eval(Arr['Datapoints']):
if i.has_key('Maximum'):
print i['Maximum']
elif i.has_key('Value'):
print i['Value']
else:
print "None"
query_request(sys.argv[1],sys.argv[2])
脚本使用方法:
python aliapi.py
消息队列 Kafka
Project为acs_kafka,采样周期为60s,Period赋值为60或60的整数倍数。
Metric监控项含义单位Dimensions
instance_disk_capacity实例磁盘使用率%instanceId
instance_message_input实例消息生产量byte/sinstanceId
instance_message_output实例消息消费量byte/sinstanceId
topic_message_inputtopic每分钟消息生产量byte/sinstanceId,topic
topic_message_outputtopic每分钟消息消费量byte/sinstanceId,topic
SLB脚本内容:
#!/usr/bin/env python
#coding=utf-8
import sys
import json
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.acs_exception.exceptions import ClientException
from aliyunsdkcore.acs_exception.exceptions import ServerException
from aliyunsdkcms.request.v20190101.DescribeMetricListRequest import DescribeMetricListRequest
def query_req(MetricName):
client = AcsClient('xxxx', 'xxxxx', 'cn-hangzhou')
request = DescribeMetricListRequest()
request.set_accept_format('json')
#request.set_StartTime("2019-05-30 12:00:00")
request.set_Dimensions("{\"instanceId\":\"lb-bp12611tm9yubz6r8duwy\"}")
request.set_Period("60")
request.set_Namespace("acs_slb_dashboard")
request.set_MetricName(MetricName)
request.set_Length("1")
response = client.do_action_with_exception(request)
#python2: print(response)
Arr = json.loads(response)
# print Arr #print dict
i = eval(Arr['Datapoints'])
for i in eval(Arr['Datapoints']):
if i.has_key('Average'):
# print i #print list
print i['Average']
elif i.has_key('Value'):
print i['Value']
else:
print "None"
query_req(sys.argv[1])
脚本使用方法:
python aliapislb.py
负载均衡 SLB
Project为acs_slb_dashboard,采样周期为60s,Period赋值为60或60的整数倍。
Dimensions中的instanceId赋值SLB实例的instanceId。
Dimensions中的port赋值SLB实例的端口。
Dimensions中的vip赋值SLB实例的服务地址。
4层协议监控指标
Metric描述单位DimensionsStatistics
HeathyServerCount后端健康ECS实例个数CountinstanceIdAverage、Minimum、Maximum
UnhealthyServerCount后端异常ECS实例个数CountinstanceIdAverage、Minimum、Maximum
PacketTX端口每秒流出数据包数Count/SecondinstanceId, port, vipAverage、Minimum、Maximum
PacketRX端口每秒流入数据包数Count/SecondinstanceId, port, vipAverage、Minimum、Maximum
TrafficRXNew端口每秒流入数据量bit/sinstanceId, port, vipAverage、Minimum、Maximum
TrafficTXNew端口每秒流出数据量bit/sinstanceId, port, vipAverage、Minimum、Maximum
ActiveConnection端口当前活跃连接数,既客户端正在访问SLB产生的连接CountinstanceId, port, vipAverage、Minimum、Maximum
InactiveConnection端口当前非活跃连接数,既访问SLB后未断开的空闲的连接CountinstanceId, port, vipAverage、Minimum、Maximum
NewConnection端口当前新建连接数CountinstanceId, port, vipAverage、Minimum、Maximum
MaxConnection端口当前并发连接数CountinstanceId, port, vipAverage、Minimum、Maximum
DropConnection监听每秒丢失连接数Count/SecondinstanceId, port, vipAverage、Minimum、Maximum
DropPacketRX监听每秒丢失入包数Count/SecondinstanceId, port, vipAverage、Minimum、Maximum
DropPacketTX监听每秒丢失出包数Count/SecondinstanceId, port, vipAverage、Minimum、Maximum
DropTrafficRX监听每秒丢失入bit数bit/sinstanceId, port, vipAverage、Minimum、Maximum
DropTrafficTX监听每秒丢失出bit数bit/sinstanceId, port, vipAverage、Minimum、Maximum
InstanceActiveConnection实例每秒活跃连接数Count/SecondinstanceIdAverage、Minimum、Maximum
InstanceDropConnection实例每秒丢失连接数Count/SecondinstanceIdAverage、Minimum、Maximum
InstanceDropPacketRX实例每秒丢失入包数Count/SecondinstanceIdAverage、Minimum、Maximum
InstanceDropPacketTX实例每秒丢失出包数Count/SecondinstanceIdAverage、Minimum、Maximum
InstanceDropTrafficRX实例每秒丢失入bit数bit/sinstanceIdAverage、Minimum、Maximum
InstanceDropTrafficTX实例每秒丢失出bit数bit/sinstanceIdAverage、Minimum、Maximum
InstanceInactiveConnection实例每秒非活跃连接数Count/SecondinstanceIdAverage、Minimum、Maximum
InstanceMaxConnection实例每秒最大并发连接数Count/SecondinstanceIdAverage、Minimum、Maximum
InstanceNewConnection实例每秒新建连接数Count/SecondinstanceIdAverage、Minimum、Maximum
InstancePacketRX实例每秒入包数Count/SecondinstanceIdAverage、Minimum、Maximum
InstancePacketTX实例每秒出包数Count/SecondinstanceIdAverage、Minimum、Maximum
InstanceTrafficRX实例每秒入bit数bit/sinstanceIdAverage、Minimum、Maximum
InstanceTrafficTX实例每秒出bit数bit/sinstanceIdAverage、Minimum、Maximum
InstanceMaxConnectionUtilization最大连接数使用率%instanceIdAverage、Maximum、Minimum
InstanceNewConnectionUtilization新建连接数使用率%instanceIdAverage、Maximum、Minimum
7层协议监控指标
Metric描述单位DimensionsStatistics
Qps端口维度的QPSCount/SecondinstanceId, port, vipAverage
Rt端口维度的请求平均延时msinstanceId, port, vipAverage
StatusCode2xx端口维度的slb返回给client的2xx状态码统计Count/SecondinstanceId, port, vipAverage
StatusCode3xx端口维度的slb返回给client的3xx状态码统计Count/SecondinstanceId, port, vipAverage
StatusCode4xx端口维度的slb返回给client的4xx状态码统计Count/SecondinstanceId, port, vipAverage
StatusCode5xx端口维度的slb返回给client的5xx状态码统计Count/SecondinstanceId, port, vipAverage
StatusCodeOther端口维度的slb返回给client的other状态码统计Count/SecondinstanceId, port, vipAverage
UpstreamCode4xx端口维度的rs返回给slb的4xx状态码统计Count/SecondinstanceId, port, vipAverage
UpstreamCode5xx端口维度的rs返回给client的5xx状态码统计Count/SecondinstanceId, port, vipAverage
UpstreamRt端口维度的rs发给proxy的平均请求延迟msinstanceId, port, vipAverage
InstanceQps实例维度的QPSCount/SecondinstanceIdAverage
InstanceRt实例维度的请求平均延时msinstanceIdAverage
InstanceStatusCode2xx实例维度的slb返回给client的2xx状态码统计Count/SecondinstanceIdAverage
InstanceStatusCode3xx实例维度的slb返回给client的3xx状态码统计Count/SecondinstanceIdAverage
InstanceStatusCode4xx实例维度的slb返回给client4xx状态码统计Count/SecondinstanceIdAverage
InstanceStatusCode5xx实例维度的slb返回给client的5xx状态码统计Count/SecondinstanceIdAverage
InstanceStatusCodeOther实例维度的slb返回给client的Other状态码统计Count/SecondinstanceIdAverage
InstanceUpstreamCode4xx实例维度的rs返回给slb的4xx状态码统计Count/SecondinstanceIdAverage
InstanceUpstreamCode5xx实例维度的rs返回给slb的5xx状态码统计Count/SecondinstanceIdAverage
InstanceUpstreamRt实例维度的rs发给proxy的平均请求延迟msinstanceIdAverage
InstanceQpsUtilizationQPS使用率%instanceIdAverage、Maximum、Minimum