summaryrefslogtreecommitdiffstats
path: root/usr/local
diff options
context:
space:
mode:
authorScott Ullrich <sullrich@pfsense.org>2005-03-02 02:02:08 +0000
committerScott Ullrich <sullrich@pfsense.org>2005-03-02 02:02:08 +0000
commit275c49324dac9463f24b7274877a31043ab2e8e1 (patch)
tree0b8be67385dbe684b87a4e081b2553d583174b8f /usr/local
parenta30afc6a4077a3099b1af5e4c0e3e0ad3b17a880 (diff)
downloadpfsense-275c49324dac9463f24b7274877a31043ab2e8e1.zip
pfsense-275c49324dac9463f24b7274877a31043ab2e8e1.tar.gz
Add 1 to each value to make sure we dont divide by 0. grape's math teacher thanks us.
Diffstat (limited to 'usr/local')
-rwxr-xr-xusr/local/www/index.php23
1 files changed, 13 insertions, 10 deletions
diff --git a/usr/local/www/index.php b/usr/local/www/index.php
index c08e9c5..ddb8f75 100755
--- a/usr/local/www/index.php
+++ b/usr/local/www/index.php
@@ -144,11 +144,14 @@ $cpuTicks = explode(" ", `/sbin/sysctl -n kern.cp_time`);
$cpuTicks2 = explode(" ", `/sbin/sysctl -n kern.cp_time`);
$diff = array();
-$diff['user'] = $cpuTicks2[0] - $cpuTicks[0];
-$diff['nice'] = $cpuTicks2[1] - $cpuTicks[1];
-$diff['sys'] = $cpuTicks2[2] - $cpuTicks[2];
-$diff['intr'] = $cpuTicks2[3] - $cpuTicks[3];
-$diff['idle'] = $cpuTicks2[4] - $cpuTicks[4];
+$diff['user'] = ($cpuTicks2[0] - $cpuTicks[0])+1;
+$diff['nice'] = ($cpuTicks2[1] - $cpuTicks[1])+1;
+$diff['sys'] = ($cpuTicks2[2] - $cpuTicks[2])+1;
+$diff['intr'] = ($cpuTicks2[3] - $cpuTicks[3])+1;
+$diff['idle'] = ($cpuTicks2[4] - $cpuTicks[4])+1;
+
+echo "<-- user: {$diff['user']} nice {$diff['nice']} sys {$diff['sys']} intr {$diff['intr']} idle {$diff['idle']} -->";
+
$totalDiff = $diff['user'] + $diff['nice'] + $diff['sys'] + $diff['intr'] + $diff['idle'];
$cpuUsage = round(100 * (1 - $diff['idle'] / $totalDiff), 0);
@@ -218,11 +221,11 @@ sleep(2);
$cpuTicks2 = explode(" ", `/sbin/sysctl -n kern.cp_time`);
$diff = array();
-$diff['user'] = $cpuTicks2[0] - $cpuTicks[0];
-$diff['nice'] = $cpuTicks2[1] - $cpuTicks[1];
-$diff['sys'] = $cpuTicks2[2] - $cpuTicks[2];
-$diff['intr'] = $cpuTicks2[3] - $cpuTicks[3];
-$diff['idle'] = $cpuTicks2[4] - $cpuTicks[4];
+$diff['user'] = ($cpuTicks2[0] - $cpuTicks[0])+1;
+$diff['nice'] = ($cpuTicks2[1] - $cpuTicks[1])+1;
+$diff['sys'] = ($cpuTicks2[2] - $cpuTicks[2])+1;
+$diff['intr'] = ($cpuTicks2[3] - $cpuTicks[3])+1;
+$diff['idle'] = ($cpuTicks2[4] - $cpuTicks[4])+1;
$totalDiff = $diff['user'] + $diff['nice'] + $diff['sys'] + $diff['intr'] + $diff['idle'];
$cpuUsage = round(100 * (1 - $diff['idle'] / $totalDiff), 0);
OpenPOWER on IntegriCloud