zabbix
zabbix copied to clipboard
Fix 'Free swap space in %' calculation so that it does not divide by zero
The original calculation
last(//system.swap.free[memAvailSwap.0]) / last(//system.swap.total[memTotalSwap.0]) * 100
will fail with a divide by zero error when system.swap.total[memTotalSwap.0]
equals zero. To avoid that I changed the calculation to
(last(//system.swap.total[memTotalSwap.0]) <> 0) * last(//system.swap.free[memAvailSwap.0]) /
(last(//system.swap.total[memTotalSwap.0]) + (last(//system.swap.total[memTotalSwap.0]) = 0) ) * 100
So when memTotalSwap.0 equals zero then the expression evaluates to zero:
==> (0) * last(//system.swap.free[memAvailSwap.0]) / (last(//system.swap.total[memTotalSwap.0]) + (1) ) * 100
==> 0 * last(//system.swap.free[memAvailSwap.0]) / 1 * 100
==> 0
and when memTotalSwap.0 is different from zero the expression evaluates to the original:
==> (1) * last(//system.swap.free[memAvailSwap.0]) / (last(//system.swap.total[memTotalSwap.0]) + (0) ) * 100
==> last(//system.swap.free[memAvailSwap.0]) / last(//system.swap.total[memTotalSwap.0]) * 100