From bf3f22315a281fb44a5cd9b075b7915138145d6e Mon Sep 17 00:00:00 2001 From: "Jose A. Rivera" Date: Thu, 21 Apr 2016 13:09:21 -0500 Subject: [PATCH] ctdb-scripts: Avoid dividing by zero in memory calculation Don't do a percentage calculation for either memtotal or swaptotal if they are zero. Signed-off-by: Jose A. Rivera Reviewed-by: Martin Schwenke --- ctdb/config/events.d/05.system | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ctdb/config/events.d/05.system b/ctdb/config/events.d/05.system index 69fcec2e854..bfa8e7b4c4e 100755 --- a/ctdb/config/events.d/05.system +++ b/ctdb/config/events.d/05.system @@ -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" -- 2.11.4.GIT