riak.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:plugins 作者: site24x7 项目源码 文件源码
def metricCollector():
    data = {}

    #defaults
    data['plugin_version'] = PLUGIN_VERSION

    data['heartbeat_required']=HEARTBEAT

    data['units']=METRICS_UNITS

    URL = "http://"+RIAK_HOST+":"+RIAK_PORT+"/"+RIAK_STATS_URI

    try:

        if RIAK_USERNAME and RIAK_PASSWORD:
            password_mgr = connector.HTTPPasswordMgrWithDefaultRealm()
            password_mgr.add_password(REALM, URL, RIAK_USERNAME, RIAK_PASSWORD)
            auth_handler = connector.HTTPBasicAuthHandler(password_mgr)
            opener = connector.build_opener(auth_handler)
            connector.install_opener(opener)

        response = connector.urlopen(URL, timeout=10)

        byte_responseData = response.read()
        str_responseData = byte_responseData.decode('UTF-8')

        riak_dict = json.loads(str_responseData)

        for metric in riak_dict:
            if metric in METRICS_TO_BE_PUSHED_TO_SERVER:
                value=riak_dict[metric]
                if metric in BYTES_TO_MB_LIST:
                     value=convertBytesToMB(value)
                data[metric]=value 
    except Exception as e:
            data['status']=0
            data['msg']=str(e)

    return data
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号