summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorphildd <ict.advisor@nepal.inf.org>2013-12-22 03:49:56 -0800
committerChris Buechler <cmb@pfsense.org>2013-12-22 07:37:37 -0600
commite20a0af7089abc356936b8954f83c583c214a1bd (patch)
treef3967b3afc29ce8c1e6aa5eb29ba46a72b9768bb
parent27a015571a497dae6729d6ee4560566bc7e8daaa (diff)
downloadpfsense-e20a0af7089abc356936b8954f83c583c214a1bd.zip
pfsense-e20a0af7089abc356936b8954f83c583c214a1bd.tar.gz
Avoid dashboard divide by zero errors
-rw-r--r--usr/local/www/includes/functions.inc.php15
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;
}
OpenPOWER on IntegriCloud