zmstats.pl: add use warnings. Fix log deletion only ever deleting 100 when it should delete more in a loop. Add deleting more than 100 sessions. Fix loop not terminating on Ctrl-C

This commit is contained in:
Isaac Connor 2021-06-08 12:50:50 -04:00
parent 48b1e8a055
commit 3d70e621b2
1 changed files with 10 additions and 5 deletions

View File

@ -1,5 +1,6 @@
#!@PERL_EXECUTABLE@ -wT #!@PERL_EXECUTABLE@ -wT
use strict; use strict;
use warnings;
use bytes; use bytes;
# ========================================================================== # ==========================================================================
@ -79,14 +80,18 @@ while (!$zm_terminate) {
} }
my $rows; my $rows;
do { do {
my $rows = zmDbDo('DELETE FROM `Logs` WHERE `TimeKey` < unix_timestamp(now() - interval '.$Config{ZM_LOG_DATABASE_LIMIT}.') LIMIT 100'); $rows = zmDbDo('DELETE FROM `Logs` WHERE `TimeKey` < unix_timestamp(now() - interval '.$Config{ZM_LOG_DATABASE_LIMIT}.') LIMIT 100');
Debug("Deleted $rows log table entries by time") if defined $rows; Debug("Deleted $rows log table entries by time") if $rows;
} while ($rows); } while ($rows and ($rows == 100) and !$zm_terminate);
} }
} # end if ZM_LOG_DATABASE_LIMIT } # end if ZM_LOG_DATABASE_LIMIT
# Delete any sessions that are more ethan a week old. Limiting to 100 because mysql sucks my $rows;
zmDbDo('DELETE FROM Sessions WHERE access < ? LIMIT 100', time - (60*60*24*7)); do {
# Delete any sessions that are more than a week old. Limiting to 100 because mysql sucks
$rows = zmDbDo('DELETE FROM Sessions WHERE access < ? LIMIT 100', time - (60*60*24*7));
Debug("Deleted $rows sessions") if $rows;
} while ($rows and ($rows == 100) and !$zm_terminate);
sleep($Config{ZM_STATS_UPDATE_INTERVAL}); sleep($Config{ZM_STATS_UPDATE_INTERVAL});
} # end while (!$zm_terminate) } # end while (!$zm_terminate)