Python: if the value in array is very big, float value is automatically converted to X.XXXXXe+12
Case example:
If the value from cloudwatch metric is big and has a lot of digits (for example - 3Tb in bytes), it automatically converts into 3.1961603113e+12.
This value is illegal for zabbix, so fix is needed.
# Check if the metric has collected statistics. If it does not, say so
metricsList = cloudwatch.list_metrics(dimensions=dimension, namespace=args.namespace)
metricTest='Metric:'+args.metric
strMetricsList=[]
for item in metricsList:
strMetricsList.append(str(item))
if metricTest in strMetricsList:
cloudwatch_result = cloudwatch.get_metric_statistics(args.interval, start_time, end_time, args.metric, args.namespace, statistics=args.statistic, dimensions=dimension)
cloudwatch_result = cloudwatch_result[0]
if len(cloudwatch_result)>0:
# Check if the result value is too big to be float. If yes - convert to long
if len(repr(cloudwatch_result[args.statistic]))>6:
cloudwatch_result = long(cloudwatch_result[args.statistic])
else:
cloudwatch_result = float(cloudwatch_result[args.statistic])
else:
# Assuming value is 0 if AWS returned empty list
cloudwatch_result = 0
print cloudwatch_result
else:
print 'Unsupported Metric'
return
Case example:
If the value from cloudwatch metric is big and has a lot of digits (for example - 3Tb in bytes), it automatically converts into 3.1961603113e+12.
This value is illegal for zabbix, so fix is needed.
# Check if the metric has collected statistics. If it does not, say so
metricsList = cloudwatch.list_metrics(dimensions=dimension, namespace=args.namespace)
metricTest='Metric:'+args.metric
strMetricsList=[]
for item in metricsList:
strMetricsList.append(str(item))
if metricTest in strMetricsList:
cloudwatch_result = cloudwatch.get_metric_statistics(args.interval, start_time, end_time, args.metric, args.namespace, statistics=args.statistic, dimensions=dimension)
cloudwatch_result = cloudwatch_result[0]
if len(cloudwatch_result)>0:
# Check if the result value is too big to be float. If yes - convert to long
if len(repr(cloudwatch_result[args.statistic]))>6:
cloudwatch_result = long(cloudwatch_result[args.statistic])
else:
cloudwatch_result = float(cloudwatch_result[args.statistic])
else:
# Assuming value is 0 if AWS returned empty list
cloudwatch_result = 0
print cloudwatch_result
else:
print 'Unsupported Metric'
return
Комментариев нет:
Отправить комментарий