couchdb.py 文件源码

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

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

    #defaults
    data['plugin_version'] = PLUGIN_VERSION

    data['heartbeat_required']=HEARTBEAT

    data['units']=METRICS_UNITS

    URL = "http://"+COUCHDB_HOST+":"+COUCHDB_PORT+COUCHDB_STATS_URI

    try:
        if COUCHDB_USERNAME and COUCHDB_PASSWORD:
            password_mgr = connector.HTTPPasswordMgrWithDefaultRealm()
            password_mgr.add_password(REALM, URL, COUCHDB_USERNAME, COUCHDB_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')
        couch_dict = json.loads(str_responseData)
        for attribute, attribute_value in couch_dict.items():
            for metric, val in attribute_value.items():
                if 'current' in val and val['current'] is not None:
                    if metric in METRICS_KEY_VS_NAME:
                        metric = METRICS_KEY_VS_NAME[metric]
                    data[metric]=val['current']
    except Exception as e:
            data['status']=0
            data['msg']=str(e)  

    return data
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号