CL19 Added logging exceptions
This commit is contained in:
parent
1627b012e6
commit
213a90462c
|
@ -1,4 +1,5 @@
|
||||||
#!/usr/bin/env python2
|
#!/usr/bin/env python2
|
||||||
|
# ver 1.1 CL2019
|
||||||
|
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
from flask import Response
|
from flask import Response
|
||||||
|
@ -17,6 +18,7 @@ the hx_creds.py looks like this:
|
||||||
|
|
||||||
hosts=[{'host':'10.1.1.1', 'username':'local/root', 'password':'*******'},{'host':'10.1.1.2', 'username':'local/root', 'password':'****'}]
|
hosts=[{'host':'10.1.1.1', 'username':'local/root', 'password':'*******'},{'host':'10.1.1.2', 'username':'local/root', 'password':'****'}]
|
||||||
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
#
|
#
|
||||||
server_IP ='10.100.253.13'
|
server_IP ='10.100.253.13'
|
||||||
|
@ -40,6 +42,7 @@ app = Flask('HX Stats')
|
||||||
def get_stats():
|
def get_stats():
|
||||||
results =''
|
results =''
|
||||||
for host in hx_creds.hosts:
|
for host in hx_creds.hosts:
|
||||||
|
logger.info("----------- Processing Host: %s -----------"%host['host'])
|
||||||
# get auth token (either cached or new one)
|
# get auth token (either cached or new one)
|
||||||
authdata = get_auth(host['host'], host['username'], host['password'])
|
authdata = get_auth(host['host'], host['username'], host['password'])
|
||||||
if not authdata:
|
if not authdata:
|
||||||
|
@ -55,11 +58,14 @@ def get_stats():
|
||||||
try:
|
try:
|
||||||
MBps_Read=round(MBps_data[0]['datapoints'][-2][0],3)
|
MBps_Read=round(MBps_data[0]['datapoints'][-2][0],3)
|
||||||
MBps_Write=round(MBps_data[1]['datapoints'][-2][0],3)
|
MBps_Write=round(MBps_data[1]['datapoints'][-2][0],3)
|
||||||
|
logger.info("Got MBps info")
|
||||||
|
|
||||||
# build the results
|
# build the results
|
||||||
results += 'MBps_Read{host="%s"} %s\n'%(host['host'],str(MBps_Read))
|
results += 'MBps_Read{host="%s"} %s\n'%(host['host'],str(MBps_Read))
|
||||||
results += 'MBps_Write{host="%s"} %s\n'%(host['host'],str(MBps_Write))
|
results += 'MBps_Write{host="%s"} %s\n'%(host['host'],str(MBps_Write))
|
||||||
except:
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(e)
|
||||||
logger.error("Couldn't parse returned throughput data")
|
logger.error("Couldn't parse returned throughput data")
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -71,11 +77,14 @@ def get_stats():
|
||||||
try:
|
try:
|
||||||
IOPS_Read=round(IOPS_data[0]['datapoints'][-2][0],3)
|
IOPS_Read=round(IOPS_data[0]['datapoints'][-2][0],3)
|
||||||
IOPS_Write=round(IOPS_data[1]['datapoints'][-2][0],3)
|
IOPS_Write=round(IOPS_data[1]['datapoints'][-2][0],3)
|
||||||
|
logger.info("Got IOPS info")
|
||||||
|
|
||||||
# build the results
|
# build the results
|
||||||
results += 'IOPS_Read{host="%s"} %s\n'%(host['host'],str(IOPS_Read))
|
results += 'IOPS_Read{host="%s"} %s\n'%(host['host'],str(IOPS_Read))
|
||||||
results += 'IOPS_Write{host="%s"} %s\n'%(host['host'],str(IOPS_Write))
|
results += 'IOPS_Write{host="%s"} %s\n'%(host['host'],str(IOPS_Write))
|
||||||
except:
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(e)
|
||||||
logger.error("Couldn't parse returned IOPS data")
|
logger.error("Couldn't parse returned IOPS data")
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -88,17 +97,21 @@ def get_stats():
|
||||||
try:
|
try:
|
||||||
Lat_Read=round(Lat_data[0]['datapoints'][-2][0],3)
|
Lat_Read=round(Lat_data[0]['datapoints'][-2][0],3)
|
||||||
Lat_Write=round(Lat_data[1]['datapoints'][-2][0],3)
|
Lat_Write=round(Lat_data[1]['datapoints'][-2][0],3)
|
||||||
|
logger.info("Got Latency info")
|
||||||
|
|
||||||
# build the results
|
# build the results
|
||||||
results += 'Lat_Read{host="%s"} %s\n'%(host['host'],str(Lat_Read))
|
results += 'Lat_Read{host="%s"} %s\n'%(host['host'],str(Lat_Read))
|
||||||
results += 'Lat_Write{host="%s"} %s\n'%(host['host'],str(Lat_Write))
|
results += 'Lat_Write{host="%s"} %s\n'%(host['host'],str(Lat_Write))
|
||||||
except:
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(e)
|
||||||
logger.error("Couldn't parse returned latency data")
|
logger.error("Couldn't parse returned latency data")
|
||||||
pass
|
pass
|
||||||
#
|
#
|
||||||
# When processing data I'm taking one before last record ([-2]), as sometimes the last record is None
|
# When processing data I'm taking one before last record ([-2]), as sometimes the last record is None
|
||||||
#
|
#
|
||||||
# return the results to the caller
|
# return the results to the caller
|
||||||
|
logger.info("----------- Finished -----------")
|
||||||
return Response(results, mimetype='text/plain')
|
return Response(results, mimetype='text/plain')
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
Loading…
Reference in New Issue