]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ctdb-scripts: Avoid dividing by zero in memory calculation
authorJose A. Rivera <jarrpa@samba.org>
Thu, 21 Apr 2016 18:09:21 +0000 (13:09 -0500)
committerMartin Schwenke <martins@samba.org>
Sat, 23 Apr 2016 21:55:14 +0000 (23:55 +0200)
Don't do a percentage calculation for either memtotal or swaptotal if they
are zero.

Signed-off-by: Jose A. Rivera <jarrpa@samba.org>
Reviewed-by: Martin Schwenke <martin@meltin.net>
ctdb/config/events.d/05.system

index 69fcec2e854332ba9ed763cfc2e31734b87c4d77..bfa8e7b4c4e7f97ddf272fbc61e3a0adcfb181f4 100755 (executable)
@@ -144,8 +144,8 @@ $1 == "SwapFree:"     { swapfree  = $2 }
 $1 == "SwapTotal:"    { swaptotal = $2 }
 END {
     if (memavail != 0) { memfree = memavail ; }
-    print int((memtotal -  memfree)  / memtotal * 100),
-          int((swaptotal - swapfree) / swaptotal * 100)
+    if (memtotal != 0) { print int((memtotal - memfree) / memtotal * 100) ; } else { print 0 ; }
+    if (swaptotal != 0) { print int((swaptotal - swapfree) / swaptotal * 100) ; } else { print 0 ; }
 }')
     _mem_usage="$1"
     _swap_usage="$2"