diff options
author | Bill Marquette <bill.marquette@gmail.com> | 2009-03-11 23:24:29 -0500 |
---|---|---|
committer | Bill Marquette <bill.marquette@gmail.com> | 2009-03-11 23:26:18 -0500 |
commit | 4a1cd18fe7f4039534a1f9f3c22916ace411226b (patch) | |
tree | ce83a54ffcb949c69ff087f7b9123ff30f4a0498 /usr/local/www/includes | |
parent | 5a3b0d3b8cf86f0fccfec34061df98bb3f35e7bd (diff) | |
download | pfsense-4a1cd18fe7f4039534a1f9f3c22916ace411226b.zip pfsense-4a1cd18fe7f4039534a1f9f3c22916ace411226b.tar.gz |
cleaner and more proper cpu graph
Diffstat (limited to 'usr/local/www/includes')
-rw-r--r-- | usr/local/www/includes/functions.inc.php | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/usr/local/www/includes/functions.inc.php b/usr/local/www/includes/functions.inc.php index b4c37a0..c62e9d9 100644 --- a/usr/local/www/includes/functions.inc.php +++ b/usr/local/www/includes/functions.inc.php @@ -86,26 +86,27 @@ function get_uptime() { return $uptimestr; } +/* Calculates non-idle CPU time and returns as a percentage function cpu_usage() { - exec("sysctl -n kern.cp_time && sleep 1 && sysctl -n kern.cp_time",$cpuTicksEx); + $duration = 1; + $diff = array('user', 'nice', 'sys', 'intr', 'idle'); + $cpuTicks = array_combine($diff, explode(" ", `/sbin/sysctl -n kern.cp_time`)); + sleep($duration); + $cpuTicks2 = array_combine($diff, explode(" ", `/sbin/sysctl -n kern.cp_time`)); + + $totalStart = array_sum($cpuTicks); + $totalEnd = array_sum($cpuTicks2); + + // Something wrapped ?!?! + if ($totalEnd <= $totalStart) + return 0; + + // Calculate total cycles used + $totalUsed = ($totalEnd - $totalStart) - ($cpuTicks2['idle'] - $cpuTicks['idle']); - $cpuTicks = explode(" ", $cpuTicksEx[0]); - $cpuTicks2 = explode(" ", $cpuTicksEx[1]); + // Calculate the percentage used + $cpuUsage = floor(100 * ($totalUsed / ($totalEnd - $totalStart))); - $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]); - - //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']; - $totalused = $diff['user'] + $diff['nice'] + $diff['sys'] + $diff['intr']; - if (isset($totalused)&&$totalused <= 0) { - $totalused = 0.001; - } - $cpuUsage = floor(100 * ($totalused / $totalDiff)); return $cpuUsage; } @@ -177,6 +178,7 @@ function mem_usage() return $memUsage; } +<<<<<<< HEAD:usr/local/www/includes/functions.inc.php function update_date_time() { $datetime = date("D M j G:i:s T Y"); @@ -261,4 +263,7 @@ function get_interfacestatus(){ return $data; } -?>
\ No newline at end of file +?> +======= +?> +>>>>>>> 9d75714... cleaner and more proper cpu graph:usr/local/www/includes/functions.inc.php |