summaryrefslogtreecommitdiffstats
path: root/modules-available/eventlog
diff options
context:
space:
mode:
authorSimon Rettberg2022-09-12 10:00:27 +0200
committerSimon Rettberg2022-09-12 10:00:27 +0200
commit617e1f3671d9eef578382dba170dc61ff1335581 (patch)
treea9956b993ef7da318622701dcc8aa538a4dc4e85 /modules-available/eventlog
parent[eventlog] Add machine data to collected notification samples (diff)
downloadslx-admin-617e1f3671d9eef578382dba170dc61ff1335581.tar.gz
slx-admin-617e1f3671d9eef578382dba170dc61ff1335581.tar.xz
slx-admin-617e1f3671d9eef578382dba170dc61ff1335581.zip
[eventlog] Keep sample log data a little longer
Diffstat (limited to 'modules-available/eventlog')
-rw-r--r--modules-available/eventlog/hooks/cron.inc.php12
1 files changed, 7 insertions, 5 deletions
diff --git a/modules-available/eventlog/hooks/cron.inc.php b/modules-available/eventlog/hooks/cron.inc.php
index 72aa4f76..05a6921e 100644
--- a/modules-available/eventlog/hooks/cron.inc.php
+++ b/modules-available/eventlog/hooks/cron.inc.php
@@ -1,13 +1,15 @@
<?php
if (mt_rand(1, 10) === 1) {
- Database::exec("DELETE FROM eventlog WHERE (UNIX_TIMESTAMP() - 86400 * 190) > dateline");
- // Keep at least 30 events or 7 days wirth of samples (whichever is more)
+ // One year of event log
+ Database::exec("DELETE FROM eventlog WHERE (UNIX_TIMESTAMP() - 86400 * 365) > dateline");
+ // Keep at least 20 events or 7 days worth of samples (whichever is more)
$types = Database::simpleQuery("SELECT type, Count(*) AS num, Min(dateline) as oldest
FROM `notification_sample` GROUP BY type");
$cutoff = time() - 86400 * 7;
+ $maxCutoff = time() - 86400 * 365; // But don't keep anything for more than a year
foreach ($types as $type) {
- if ($type['num'] > 30 && $type['oldest'] < $cutoff) {
+ if ($type['num'] > 20 && $type['oldest'] < $cutoff) {
// This type has more than 30 and the oldest one is older than 7 days
// find out which one takes priority
$thisCutoff = $cutoff;
@@ -17,13 +19,13 @@ if (mt_rand(1, 10) === 1) {
LIMIT 29, 1",
['type' => $type['type']]);
// The 30th entry is older than 7 days? Bump the cutoff dateline back to this date,
- // so we keep at least 30 entries
+ // so we keep at least 20 entries
if ($find !== false && $find['dateline'] < $thisCutoff) {
$thisCutoff = $find['dateline'];
}
Database::exec("DELETE FROM notification_sample
WHERE type = :type AND dateline < :dateline",
- ['type' => $type['type'], 'dateline' => $thisCutoff]);
+ ['type' => $type['type'], 'dateline' => max($thisCutoff, $maxCutoff)]);
}
}
}