import json
from tencentcloud.common import credential
from tencentcloud.common.profile.client_profile import ClientProfile
from tencentcloud.common.profile.http_profile import HttpProfile
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
from tencentcloud.monitor.v20180724 import monitor_client, models
import sys
viplist=["IP1","IP2","IP3"]

def huoquwlptcode(xxx,xxx):   #根据自己的实例更新
    try:
        cred = credential.Credential("", "")
        ##根据自己的实例更新认证
        httpProfile = HttpProfile()
        httpProfile.endpoint = "monitor.tencentcloudapi.com"

        clientProfile = ClientProfile()
        clientProfile.httpProfile = httpProfile
        client = monitor_client.MonitorClient(cred, "ap-shanghai-fsi", clientProfile)
##根据自己的实例云位置
        req = models.GetMonitorDataRequest()
        params = {
        "Namespace": "QCE/LB_PRIVATE",
        "MetricName": wlptcode,    
        "Period": 300,
        "Instances": [
            {
                "Dimensions": [
                    {
                        "Name": "vip",
                        "Value": xxxx   #根据自己的实例更新
                    },
                    {
                        "Name": "vpcId",
                        "Value": "vpc-xxx" #根据自己的实例更新
                    }
                ]
            }
        ]
    }
        req.from_json_string(json.dumps(params))

        resp = client.GetMonitorData(req)

        loadBalancersJson=json.loads(resp.to_json_string())
        global sumvalue
        for i in loadBalancersJson["DataPoints"] :
            if i["Values"] != [] :           
               #print(i["Values"])
               sumvalue=sumvalue+i["Values"][-1]


    except TencentCloudSDKException as err:
        print(err)

#特殊的指标格式化处理
if __name__ == '__main__':
    wlptcode = str(sys.argv[1] )
    sumvalue=0
    for wlptvip in viplist :     #传过来的第一个参数 ip
        huoquwlptcode(wlptcode,wlptvip)
    if wlptcode == "RspAvg"   :
       sumvalue=sumvalue/2
       sumvalue=int(sumvalue)
    elif wlptcode == "RspMax" :
       sumvalue=sumvalue/2
       sumvalue=int(sumvalue)
         
    print(sumvalue)

获取指标,自定义keyzabbix

[root@vm-centos ~]# python3 wlptclb.py RspAvg

0.25

注:可封装c可执行文件,避免不同机器python版本问题

pip3 install nuitka

python3 -m nuitka xxx.py --standalone

cd  xxx.dist && ./xxx.bin 指标

#tencet cloude参考资料:

https://cloud.tencent.com/document/product/248/51898