diff options
author | Simon Rettberg | 2019-01-24 12:17:07 +0100 |
---|---|---|
committer | Simon Rettberg | 2019-01-24 12:17:07 +0100 |
commit | c124192e63bd8a48ed1e7caf9542dc52505dfd22 (patch) | |
tree | e43d3ceb7ba0b81e01d0924f384bc61578deeca7 /modules-available/statistics/hooks | |
parent | [locationinfo] use set config language for panels (diff) | |
download | slx-admin-c124192e63bd8a48ed1e7caf9542dc52505dfd22.tar.gz slx-admin-c124192e63bd8a48ed1e7caf9542dc52505dfd22.tar.xz slx-admin-c124192e63bd8a48ed1e7caf9542dc52505dfd22.zip |
[statistics] Handling of standby state in statistics, log crashes
Or rather, not really crashes, but log whenever a client reports a
poweron event without reporting a proper shutdown first. This isn't
neccessarily a crash but could also be due to power loss, hard poweroff,
or network failures.
Diffstat (limited to 'modules-available/statistics/hooks')
-rw-r--r-- | modules-available/statistics/hooks/cron.inc.php | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/modules-available/statistics/hooks/cron.inc.php b/modules-available/statistics/hooks/cron.inc.php index f05762bc..0b8e740e 100644 --- a/modules-available/statistics/hooks/cron.inc.php +++ b/modules-available/statistics/hooks/cron.inc.php @@ -21,10 +21,11 @@ function logstats() function state_cleanup() { // Fix online state of machines that crashed - $standby = time() - 86400 * 2; // Reset standby machines after two days + $standby = time() - 86400 * 4; // Reset standby machines after four days $on = time() - 610; // Reset others after ~10 minutes // Query for logging - $res = Database::simpleQuery("SELECT machineuuid, clientip, state FROM machine WHERE lastseen < If(state = 'STANDBY', $standby, $on) AND state <> 'OFFLINE'"); + $res = Database::simpleQuery("SELECT machineuuid, clientip, state, logintime, lastseen FROM machine + WHERE lastseen < If(state = 'STANDBY', $standby, $on) AND state <> 'OFFLINE'"); while ($row = $res->fetch(PDO::FETCH_ASSOC)) { Database::exec('INSERT INTO clientlog (dateline, logtypeid, clientip, machineuuid, description, extra) VALUES (UNIX_TIMESTAMP(), :type, :client, :uuid, :description, :longdesc)', array( @@ -34,9 +35,20 @@ function state_cleanup() 'longdesc' => '', 'uuid' => $row['machineuuid'], )); + if ($row['state'] === 'OCCUPIED') { + $length = $row['lastseen'] - $row['logintime']; + if ($length > 0 && $length < 86400 * 7) { + Statistics::logMachineState($row['machineuuid'], $row['clientip'], Statistics::SESSION_LENGTH, $row['logintime'], $length); + } + } elseif ($row['state'] === 'STANDBY') { + $length = time() - $row['lastseen']; + if ($length > 0 && $length < 86400 * 7) { + Statistics::logMachineState($row['machineuuid'], $row['clientip'], Statistics::SUSPEND_LENGTH, $row['lastseen'], $length); + } + } } - // Update -- yes this is not atomic. Should be sufficient for simple warnings though. - Database::exec("UPDATE machine SET state = 'OFFLINE' WHERE lastseen < If(state = 'STANDBY', $standby, $on) AND state <> 'OFFLINE'"); + // Update -- yes this is not atomic. Should be sufficient for simple warnings and bookkeeping though. + Database::exec("UPDATE machine SET logintime = 0, state = 'OFFLINE' WHERE lastseen < If(state = 'STANDBY', $standby, $on) AND state <> 'OFFLINE'"); } state_cleanup(); |