summaryrefslogtreecommitdiffstats
path: root/src/usr/local/www/includes/functions.inc.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/usr/local/www/includes/functions.inc.php')
-rw-r--r--src/usr/local/www/includes/functions.inc.php22
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 23012bd..b53d2b4 100644
--- a/src/usr/local/www/includes/functions.inc.php
+++ b/src/usr/local/www/includes/functions.inc.php
@@ -114,29 +114,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) {
OpenPOWER on IntegriCloud