美文网首页监控
通过zabbix及阿里api 监控阿里云业务

通过zabbix及阿里api 监控阿里云业务

作者: 大鹏一怒乘风起 | 来源:发表于2021-05-27 15:17 被阅读0次

    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脚本内容:

    #!/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 <Project> <Metric>
    

    消息队列 Kafka
    Project为acs_kafka,采样周期为60s,Period赋值为60或60的整数倍数。

    Metric  监控项含义   单位  Dimensions
    instance_disk_capacity  实例磁盘使用率 %   instanceId
    instance_message_input  实例消息生产量 byte/s  instanceId
    instance_message_output 实例消息消费量 byte/s  instanceId
    topic_message_input topic每分钟消息生产量   byte/s  instanceId,topic
    topic_message_output    topic每分钟消息消费量   byte/s  instanceId,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  <Metric>
    

    负载均衡 SLB

    Project为acs_slb_dashboard,采样周期为60s,Period赋值为60或60的整数倍。
    
    Dimensions中的instanceId赋值SLB实例的instanceId。
    
    Dimensions中的port赋值SLB实例的端口。
    
    Dimensions中的vip赋值SLB实例的服务地址。
    

    4层协议监控指标

    Metric  描述  单位  Dimensions  Statistics
    HeathyServerCount   后端健康ECS实例个数 Count   instanceId  Average、Minimum、Maximum
    UnhealthyServerCount    后端异常ECS实例个数 Count   instanceId  Average、Minimum、Maximum
    PacketTX    端口每秒流出数据包数  Count/Second    instanceId, port, vip   Average、Minimum、Maximum
    PacketRX    端口每秒流入数据包数  Count/Second    instanceId, port, vip   Average、Minimum、Maximum
    TrafficRXNew    端口每秒流入数据量   bit/s   instanceId, port, vip   Average、Minimum、Maximum
    TrafficTXNew    端口每秒流出数据量   bit/s   instanceId, port, vip   Average、Minimum、Maximum
    ActiveConnection    端口当前活跃连接数,既客户端正在访问SLB产生的连接  Count   instanceId, port, vip   Average、Minimum、Maximum
    InactiveConnection  端口当前非活跃连接数,既访问SLB后未断开的空闲的连接 Count   instanceId, port, vip   Average、Minimum、Maximum
    NewConnection   端口当前新建连接数   Count   instanceId, port, vip   Average、Minimum、Maximum
    MaxConnection   端口当前并发连接数   Count   instanceId, port, vip   Average、Minimum、Maximum
    DropConnection  监听每秒丢失连接数   Count/Second    instanceId, port, vip   Average、Minimum、Maximum
    DropPacketRX    监听每秒丢失入包数   Count/Second    instanceId, port, vip   Average、Minimum、Maximum
    DropPacketTX    监听每秒丢失出包数   Count/Second    instanceId, port, vip   Average、Minimum、Maximum
    DropTrafficRX   监听每秒丢失入bit数 bit/s   instanceId, port, vip   Average、Minimum、Maximum
    DropTrafficTX   监听每秒丢失出bit数 bit/s   instanceId, port, vip   Average、Minimum、Maximum
    InstanceActiveConnection    实例每秒活跃连接数   Count/Second    instanceId  Average、Minimum、Maximum
    InstanceDropConnection  实例每秒丢失连接数   Count/Second    instanceId  Average、Minimum、Maximum
    InstanceDropPacketRX    实例每秒丢失入包数   Count/Second    instanceId  Average、Minimum、Maximum
    InstanceDropPacketTX    实例每秒丢失出包数   Count/Second    instanceId  Average、Minimum、Maximum
    InstanceDropTrafficRX   实例每秒丢失入bit数 bit/s   instanceId  Average、Minimum、Maximum
    InstanceDropTrafficTX   实例每秒丢失出bit数 bit/s   instanceId  Average、Minimum、Maximum
    InstanceInactiveConnection  实例每秒非活跃连接数  Count/Second    instanceId  Average、Minimum、Maximum
    InstanceMaxConnection   实例每秒最大并发连接数 Count/Second    instanceId  Average、Minimum、Maximum
    InstanceNewConnection   实例每秒新建连接数   Count/Second    instanceId  Average、Minimum、Maximum
    InstancePacketRX    实例每秒入包数 Count/Second    instanceId  Average、Minimum、Maximum
    InstancePacketTX    实例每秒出包数 Count/Second    instanceId  Average、Minimum、Maximum
    InstanceTrafficRX   实例每秒入bit数   bit/s   instanceId  Average、Minimum、Maximum
    InstanceTrafficTX   实例每秒出bit数   bit/s   instanceId  Average、Minimum、Maximum
    InstanceMaxConnectionUtilization    最大连接数使用率    %   instanceId  Average、Maximum、Minimum
    InstanceNewConnectionUtilization    新建连接数使用率    %   instanceId  Average、Maximum、Minimum
    

    7层协议监控指标

    Metric  描述  单位  Dimensions  Statistics
    Qps 端口维度的QPS    Count/Second    instanceId, port, vip   Average
    Rt  端口维度的请求平均延时 ms  instanceId, port, vip   Average
    StatusCode2xx   端口维度的slb返回给client的2xx状态码统计  Count/Second    instanceId, port, vip   Average
    StatusCode3xx   端口维度的slb返回给client的3xx状态码统计  Count/Second    instanceId, port, vip   Average
    StatusCode4xx   端口维度的slb返回给client的4xx状态码统计  Count/Second    instanceId, port, vip   Average
    StatusCode5xx   端口维度的slb返回给client的5xx状态码统计  Count/Second    instanceId, port, vip   Average
    StatusCodeOther 端口维度的slb返回给client的other状态码统计    Count/Second    instanceId, port, vip   Average
    UpstreamCode4xx 端口维度的rs返回给slb的4xx状态码统计  Count/Second    instanceId, port, vip   Average
    UpstreamCode5xx 端口维度的rs返回给client的5xx状态码统计   Count/Second    instanceId, port, vip   Average
    UpstreamRt  端口维度的rs发给proxy的平均请求延迟   ms  instanceId, port, vip   Average
    InstanceQps 实例维度的QPS    Count/Second    instanceId  Average
    InstanceRt  实例维度的请求平均延时 ms  instanceId  Average
    InstanceStatusCode2xx   实例维度的slb返回给client的2xx状态码统计  Count/Second    instanceId  Average
    InstanceStatusCode3xx   实例维度的slb返回给client的3xx状态码统计  Count/Second    instanceId  Average
    InstanceStatusCode4xx   实例维度的slb返回给client4xx状态码统计   Count/Second    instanceId  Average
    InstanceStatusCode5xx   实例维度的slb返回给client的5xx状态码统计  Count/Second    instanceId  Average
    InstanceStatusCodeOther 实例维度的slb返回给client的Other状态码统计    Count/Second    instanceId  Average
    InstanceUpstreamCode4xx 实例维度的rs返回给slb的4xx状态码统计  Count/Second    instanceId  Average
    InstanceUpstreamCode5xx 实例维度的rs返回给slb的5xx状态码统计  Count/Second    instanceId  Average
    InstanceUpstreamRt  实例维度的rs发给proxy的平均请求延迟   ms  instanceId  Average
    InstanceQpsUtilization  QPS使用率  %   instanceId  Average、Maximum、Minimum
    

    相关文章

      网友评论

        本文标题:通过zabbix及阿里api 监控阿里云业务

        本文链接:https://www.haomeiwen.com/subject/tdfdsltx.html