diff options
author | phildd <ict.advisor@nepal.inf.org> | 2013-12-22 03:49:56 -0800 |
---|---|---|
committer | Chris Buechler <cmb@pfsense.org> | 2013-12-22 07:37:37 -0600 |
commit | e20a0af7089abc356936b8954f83c583c214a1bd (patch) | |
tree | f3967b3afc29ce8c1e6aa5eb29ba46a72b9768bb | |
parent | 27a015571a497dae6729d6ee4560566bc7e8daaa (diff) | |
download | pfsense-e20a0af7089abc356936b8954f83c583c214a1bd.zip pfsense-e20a0af7089abc356936b8954f83c583c214a1bd.tar.gz |
Avoid dashboard divide by zero errors
-rw-r--r-- | usr/local/www/includes/functions.inc.php | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/usr/local/www/includes/functions.inc.php b/usr/local/www/includes/functions.inc.php index 33cb585..1c57ba7 100644 --- a/usr/local/www/includes/functions.inc.php +++ b/usr/local/www/includes/functions.inc.php @@ -152,7 +152,10 @@ function get_pfstate($percent=false) { $curentries = $matches[1]; } if ($percent) - return round(($curentries / $maxstates) * 100, 0); + if ($maxstates > 0) + return round(($curentries / $maxstates) * 100, 0); + else + return "NA"; else return $curentries . "/" . $maxstates; } @@ -172,7 +175,10 @@ function get_mbuf($percent=false) { $mbufs_output=trim(`/usr/bin/netstat -mb | /usr/bin/grep "mbuf clusters in use" | /usr/bin/awk '{ print $1 }'`); list( $mbufs_current, $mbufs_cache, $mbufs_total, $mbufs_max ) = explode( "/", $mbufs_output); if ($percent) - return round(($mbufs_total / $mbufs_max) * 100, 0); + if ($mbufs_max > 0) + return round(($mbufs_total / $mbufs_max) * 100, 0); + else + return "NA"; else return "{$mbufs_total}/{$mbufs_max}"; } @@ -217,7 +223,10 @@ function mem_usage() { $totalMem = $memory[0]; $availMem = $memory[1] + $memory[2] + $memory[3]; $usedMem = $totalMem - $availMem; - $memUsage = round(($usedMem * 100) / $totalMem, 0); + if ($totalMem > 0) + $memUsage = round(($usedMem * 100) / $totalMem, 0); + else + $memUsage = "NA"; return $memUsage; } |