Search the whole station

zabbix监控阿里云SLB操作指引

1. SLB介绍

阿里云负载均衡(Server Load Balancer,简称SLB)是云原生时代应用高可用的基本要素。通过将流量分发到不同的后端服务来扩展应用系统的服务吞吐能力,消除单点故障并提升应用系统的可用性。 阿里云SLB包含面向4层的网络型负载均衡NLB、面向7层的应用型负载均衡ALB和传统型负载均衡CLB,是阿里云官方云原生网关。

2. 监控前准备

本次监控方式通过zabbix采集器方式(目前网上能查到的文章,监控数据获取是基于agent的。由于调用阿里云的接口,超过一定次数会有费用产生,故采用采集器方式会比agent更优)

3. 获取SLB实例

#!/usr/bin/env python
#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 aliyunsdkslb.request.v20140515.DescribeLoadBalancersRequest import DescribeLoadBalancersRequest
import json
# 这里填 ACCESS_KEY 和SECRET_KEY
credentials = AccessKeyCredential('********', '****')
# 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 = DescribeLoadBalancersRequest()
request.set_accept_format('json')
response = client.do_action_with_exception(request)
r = []
res = json.loads(response)

# 拼接成用于zabbix自动发现资源的格式 ,这里使用  LoadBalancerId 作为主机名称   LoadBalancerName 作为可见名称
for i in res['LoadBalancers']['LoadBalancer']:
        buf = {'{#PROJECT}':'acs_slb_dashboard', '{#INSTANCE}':i['LoadBalancerId'], '{#INSTANCE_NANME}':i['LoadBalancerName']}
        r.append(buf)
print(json.dumps({"data":r}))

4. 获取监控数据

#!/usr/bin/env python
#coding=utf-8
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.acs_exception.exceptions import ClientException
from aliyunsdkcore.acs_exception.exceptions import ServerException
from aliyunsdkcore.request import CommonRequest
from aliyunsdkcore.auth.credentials import AccessKeyCredential
from aliyunsdkcore.auth.credentials import StsTokenCredential
from aliyunsdkcms.request.v20190101.DescribeMetricLastRequest import DescribeMetricLastRequest
import json,sys
from os import popen,system
# 键值
k=sys.argv[1]
# 资源所在区域
Produce=sys.argv[2]
# 命名空间
Namespace=sys.argv[3]
# ACCESS_KEY
Akey=sys.argv[4]
# SECRET_KEY
Skey=sys.argv[5]
# 获取监控数据的数据类型,有最大值(Maximum),平均值(avg)等
Kdata=sys.argv[6]
ZABBIX_SEND_ADDR = '/itops/zabbix/bin/zabbix_sender'     #zabbix_sender 绝对路径
zabbix_server_ip = "192.168.1.1"       #zabbix_server或zabbix_proxy地址,用于接收数据
ZABBIX_PORT = '10051'      #zabbix_server或zabbix_proxy服务端口
credentials = AccessKeyCredential(Akey, Skey)
    # use STS Token
    # credentials = StsTokenCredential('<your-access-key-id>', '<your-access-key-secret>', '<your-sts-token>')
client = AcsClient(region_id=Produce, credential=credentials)
request = DescribeMetricLastRequest()
request.set_accept_format('json')
request.set_Namespace(Namespace)
request.set_MetricName(k)
result = client.do_action_with_exception(request)
#res = response.decode()
result = json.loads(result)
result = json.loads(result['Datapoints'])
#print(result)
# 通过zabbix_sender 发送监控数据到监控对象
for i in result:
        hosthost=i["instanceId"]
        key=k
        value=i[Kdata]
        popen('%s -z %s -p %s -s %s -k %s -o %s >/dev/null' % (ZABBIX_SEND_ADDR,zabbix_server_ip,ZABBIX_PORT,"'" + hosthost + "'","'" + key + "'","'" + str(value) + "'")

5. 监控模板制作

5.1 新增自动发现规则用于自动发现SLB实例

5.2 新增监控项,用于获取监控数据

5.3 新增监控数据接收的监控模板

以上就是这一期的分享内容。

大家好,我是乐乐,专注IT运维技术研究与分享,关注我,了解更多实用zabbix技术知识。同时欢迎小伙伴们到乐维社区留言提问,共同探讨zabbix使用问题。

附:指标清单参考

https://cms.console.aliyun.com/metric-meta/acs_slb_dashboard/slb?spm=a2c4g.11186623.0.0.68a46c8aTDUUGP

乐维社区
The prev: The next:

Related recommendations

Expand more!