From 4247bb518e3e6d1a2ec601ea4597edf5eb3cc72e Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Sat, 25 Apr 2020 20:49:12 +0200 Subject: [statistics] Track CPU-load and standby failures of clients --- modules-available/statistics/api.inc.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'modules-available/statistics/api.inc.php') diff --git a/modules-available/statistics/api.inc.php b/modules-available/statistics/api.inc.php index b8ef2eb1..3e8ed917 100644 --- a/modules-available/statistics/api.inc.php +++ b/modules-available/statistics/api.inc.php @@ -112,7 +112,7 @@ if ($type{0} === '~') { . ' cpumodel = :cpumodel,' . ' systemmodel = :systemmodel,' . ' id44mb = :id44mb,' - . ' live_tmpsize = 0, live_swapsize = 0, live_memsize = 0,' + . ' live_tmpsize = 0, live_swapsize = 0, live_memsize = 0, cpuload = 255', . ' badsectors = :badsectors,' . ' data = :data,' . ' state = :state ' @@ -215,11 +215,16 @@ if ($type{0} === '~') { } } } - foreach (['memsize', 'tmpsize', 'swapsize', 'memfree', 'tmpfree', 'swapfree'] as $item) { + foreach (['memsize', 'tmpsize', 'swapsize', 'memfree', 'tmpfree', 'swapfree', 'cpuload'] as $item) { $liveVal = Request::post($item, false, 'int'); if ($liveVal !== false) { $strUpdateBoottime .= ' live_' . $item . ' = :_' . $item . ', '; - $params['_' . $item] = ceil($liveVal / 1024); + if ($item === 'cpuload') { + $liveVal = round($liveVal); + } else { + $liveVal = ceil($liveVal / 1024); + } + $params['_' . $item] = $liveVal; } } // Figure out what's happening - state changes @@ -358,7 +363,8 @@ if ($type{0} === '~') { updateIp('suspend', $uuid, $old, $ip); } if ($NOW - $old['lastseen'] < 610 && $old['state'] !== 'OFFLINE') { - Database::exec("UPDATE machine SET lastseen = UNIX_TIMESTAMP(), state = 'STANDBY' + Database::exec("UPDATE machine SET lastseen = UNIX_TIMESTAMP(), state = 'STANDBY', + standbysem = If(standbysem < 6, standbysem + 1, 6) WHERE machineuuid = :uuid AND state = :oldstate AND lastseen = :oldlastseen", array('uuid' => $uuid, 'oldlastseen' => $old['lastseen'], 'oldstate' => $old['state'])); } else { @@ -371,7 +377,8 @@ if ($type{0} === '~') { updateIp('resume', $uuid, $old, $ip); } if ($old['state'] === 'STANDBY') { - $res = Database::exec("UPDATE machine SET state = 'IDLE', clientip = :ip, lastseen = UNIX_TIMESTAMP() + $res = Database::exec("UPDATE machine SET state = 'IDLE', clientip = :ip, lastseen = UNIX_TIMESTAMP(), + standbysem = If(standbysem > 1, standbysem - 2, 0) WHERE machineuuid = :uuid AND state = :oldstate AND lastseen = :oldlastseen", array('uuid' => $uuid, 'ip' => $ip, 'oldlastseen' => $old['lastseen'], 'oldstate' => $old['state'])); // Write standby period length to statistic table -- cgit v1.2.3-55-g7522