ffnord / ffmap-backend

THIS PROJECT DOESN'T HAVE A MAINTAINER!
Other
20 stars 56 forks source link

ZeroDivisionError Exception #52

Closed xeaon closed 9 years ago

xeaon commented 9 years ago

lib/nodes.py throws ZeroDivisionError. Somehow d['total'] seems not to be a decimal sometimes - maybe when nodes do not provide the information

Here is the trace:

Traceback (most recent call last):
 File "./backend.py", line 170, in <module>
 main(options)
 File "./backend.py", line 90, in main
 nodes.import_statistics(nodedb['nodes'], alfred.statistics())
 File "/srv/ffmap-backend-new-troisdorf/lib/nodes.py", line 74, in import_statistics
 lambda d: 1 - d['free'] / d['total'])
 File "/srv/ffmap-backend-new-troisdorf/lib/nodes.py", line 61, in add
 statistics))
 File "/srv/ffmap-backend-new-troisdorf/lib/nodes.py", line 74, in <lambda>
 lambda d: 1 - d['free'] / d['total'])
ZeroDivisionError: division by zero

Simple solution (replace line 74 with):

try:
            add(node, stats, 'memory_usage', ['memory'], lambda d: 1 - d['free'] / d['total'])
except ZeroDivisionError:
            add(node, stats, 'memory_usage', ['memory'], lambda d: 0)
tcatm commented 9 years ago

Fixed.