diff options
| author | Simon Rettberg | 2025-02-13 15:51:38 +0100 |
|---|---|---|
| committer | Simon Rettberg | 2025-02-13 15:51:38 +0100 |
| commit | 68a8ab1f4e9d9e4e794729739bbe9ae9af7cb48a (patch) | |
| tree | a5561d09852511bc43be4ea85f9e35c7c8496c1c /modules-available/statistics | |
| parent | [statistics] Provide last runmode to events on ~poweron (diff) | |
| download | slx-admin-68a8ab1f4e9d9e4e794729739bbe9ae9af7cb48a.tar.gz slx-admin-68a8ab1f4e9d9e4e794729739bbe9ae9af7cb48a.tar.xz slx-admin-68a8ab1f4e9d9e4e794729739bbe9ae9af7cb48a.zip | |
[statistics] cron: Add status output in case the cronjob hangs/fails
Diffstat (limited to 'modules-available/statistics')
| -rw-r--r-- | modules-available/statistics/hooks/cron.inc.php | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/modules-available/statistics/hooks/cron.inc.php b/modules-available/statistics/hooks/cron.inc.php index 4ba5e2f6..9e7d6537 100644 --- a/modules-available/statistics/hooks/cron.inc.php +++ b/modules-available/statistics/hooks/cron.inc.php @@ -9,6 +9,7 @@ function logstats() $join = 'LEFT JOIN runmode r USING (machineuuid)'; $where = 'AND (r.isclient IS NULL OR r.isclient <> 0)'; } + error_log("Generating per-location usage stats"); // Get total/online/in-use $known = Database::queryKeyValueList("SELECT locationid, Count(*) AS val FROM machine m $join WHERE m.lastseen > $cutoff $where @@ -22,7 +23,16 @@ function logstats() // Get calendar data if available if (Module::isAvailable('locationinfo')) { // Refresh all calendars around 07:00 - $calendars = LocationInfo::getAllCalendars(date('G') != 7 || date('i') >= 10); + if (date('G') == 7 && date('i') <= 15) { + error_log("Updating stale calendar data"); + $start = time(); + } else { + $start = 0; + } + $calendars = LocationInfo::getAllCalendars($start + 55); + if ($start !== 0) { + error_log('Updating calendars took ' . (time() - $start) . 's'); + } } // Mash together $data = ['usage' => []]; @@ -42,6 +52,7 @@ function logstats() } $data['usage'][$lid] = $entry; } + error_log("Writing to DB"); Database::exec("INSERT INTO statistic (dateline, typeid, clientip, username, data) VALUES (:now, '~stats', '', '', :vals)", array( 'now' => $NOW, 'vals' => json_encode($data), @@ -50,12 +61,17 @@ function logstats() function state_cleanup() { + error_log("Looking for machines that stopped reporting state without logging a shutdown/hibernate..."); // Fix online state of machines that crashed $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, logintime, lastseen, live_memfree, live_swapfree, live_tmpfree FROM machine 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'"); + // Check results foreach ($res as $row) { ClientLog::write($row, 'machine-mismatch-cron', 'Client timed out, last known state is ' . $row['state'] @@ -74,8 +90,6 @@ function state_cleanup() } } } - // 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(); @@ -83,14 +97,20 @@ state_cleanup(); logstats(); if (mt_rand(1, 10) === 1) { + error_log("Deleting old statistic entries"); Database::exec("DELETE FROM statistic WHERE (UNIX_TIMESTAMP() - 86400 * 365 * 2) > dateline"); if (mt_rand(1, 100) === 1) { + error_log("Optimizing statistic table"); Database::exec("OPTIMIZE TABLE statistic"); } } if (mt_rand(1, 10) === 1) { + error_log("Deleting old machine entries"); Database::exec("DELETE FROM machine WHERE (UNIX_TIMESTAMP() - 86400 * 365 * 2) > lastseen"); if (mt_rand(1, 100) === 1) { + error_log("Optimizing machine table"); Database::exec("OPTIMIZE TABLE machine"); } } + +error_log("Statistics cronjob done");
\ No newline at end of file |
