diff options
Diffstat (limited to 'src/usr/local/www/includes')
-rw-r--r-- | src/usr/local/www/includes/functions.inc.php | 22 |
1 files changed, 3 insertions, 19 deletions
diff --git a/src/usr/local/www/includes/functions.inc.php b/src/usr/local/www/includes/functions.inc.php index 43723a3..664ea24 100644 --- a/src/usr/local/www/includes/functions.inc.php +++ b/src/usr/local/www/includes/functions.inc.php @@ -79,29 +79,13 @@ function get_uptime() { return $uptimestr; } -/* Calculates non-idle CPU time and returns as a percentage */ +// Returns the current total ticks and user ticks. The dashboard widget calculates the load from that function cpu_usage() { - $duration = 1; + $diff = array('user', 'nice', 'sys', 'intr', 'idle'); $cpuTicks = array_combine($diff, explode(" ", get_single_sysctl('kern.cp_time'))); - sleep($duration); - $cpuTicks2 = array_combine($diff, explode(" ", get_single_sysctl('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']); - - // Calculate the percentage used - $cpuUsage = floor(100 * ($totalUsed / ($totalEnd - $totalStart))); - return $cpuUsage; + return array_sum($cpuTicks) . "|" . $cpuTicks['idle']; } function get_pfstate($percent=false) { |