From 12f9b53e75860e5f33241149bef7799128125855 Mon Sep 17 00:00:00 2001 From: Dave Pedu Date: Thu, 28 Jan 2016 22:19:18 -0800 Subject: [PATCH] prevent div by 0 exceptions in certain environments --- pymonitor/monitors/diskio.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pymonitor/monitors/diskio.py b/pymonitor/monitors/diskio.py index c36dc70..732f5cf 100644 --- a/pymonitor/monitors/diskio.py +++ b/pymonitor/monitors/diskio.py @@ -9,6 +9,7 @@ def diskio(disks=[]): continue if stats.read_count == 0 and disk not in disks: continue + print("wb ", stats.write_bytes, " wc ", stats.write_count) stats = { "disk": disk, "disk.raw": disk, @@ -20,8 +21,8 @@ def diskio(disks=[]): "writes": stats.write_count, "read": stats.read_bytes, "written": stats.write_bytes, - "read_size":round(stats.read_bytes/stats.read_count, 2), - "write_size":round(stats.write_bytes/stats.write_count, 2) + "read_size":round(stats.read_bytes/stats.read_count, 2) if stats.read_count > 0 else 0, + "write_size":round(stats.write_bytes/stats.write_count, 2) if stats.write_count > 0 else 0 } yield(stats)