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
评论列表
文章目录