From 345f152181d8d6991199c8ee2da716380ab8971d Mon Sep 17 00:00:00 2001 From: Kyle Johnson Date: Fri, 21 Nov 2014 19:49:03 +0000 Subject: [PATCH] Add function for returning system load via api --- web/api/app/Controller/HostController.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/web/api/app/Controller/HostController.php b/web/api/app/Controller/HostController.php index f09f27943..d7c3c45d7 100644 --- a/web/api/app/Controller/HostController.php +++ b/web/api/app/Controller/HostController.php @@ -22,4 +22,15 @@ class HostController extends AppController { )); } + function getLoad() { + $uptime = shell_exec( 'uptime' ); + $load = ''; + if ( preg_match( '/load average: ([\d.]+)/', $uptime, $matches ) ) + $load = $matches[1]; + + $this->set(array( + 'load' => $load, + '_serialize' => array('load') + )); + } }