Browse Source

[Minor] rspamd_stats: Add progress indicator

tags/1.7.0
Alexander Moisseev 6 years ago
parent
commit
c396dd392d
1 changed files with 16 additions and 1 deletions
  1. 16
    1
      utils/rspamd_stats.pl

+ 16
- 1
utils/rspamd_stats.pl View File

@@ -68,6 +68,8 @@ my $ham_junk_change = 0;
my %sym_res;
my $rspamd_log;
my $enabled = 0;
my $log_file_num = 1;
my $spinner_update_time = 0;

my %action;
my %timeStamp;
@@ -108,6 +110,10 @@ elsif ( -d "$log_file" ) {
open( $rspamd_log, "-|", "$dc $log_dir/$_" )
or die "cannot execute $dc $log_dir/$_ : $!";

printf "\033[J Parsing log files: [%d/%d] %s\033[G", $log_file_num++, scalar @logs, $_;
$spinner_update_time = 0; # Force spinner update
&spinner;

&ProcessLog;

close($rspamd_log)
@@ -337,6 +343,7 @@ sub ProcessLog {
next if !$enabled;

if (/^.*rspamd_task_write_log.*$/) {
&spinner;
my $ts =
($is_syslog)
? syslog2iso( join ' ', ( split /\s+/ )[ 0 .. 2 ] )
@@ -528,7 +535,7 @@ sub GetLogfilesList {

# Loop through array printing out filenames
if (!$json) {
print "\nParsing log files:\n";
print "\nLog files to process:\n";
foreach my $file (@logs) {
print " $file\n";
}
@@ -589,6 +596,14 @@ sub numeric {
$a_num <=> $b_num;
}

sub spinner {
my @spinner = qw{/ - \ |};
return
if ( ( time - $spinner_update_time ) < 1 );
printf "%s\033[1D", $spinner[ time % @spinner ];
$spinner_update_time = time;
}

# Convert syslog timestamp to "ISO 8601 like" format
# using current year as syslog does not record the year (nor the timezone)
# or the last year if the guessed time is in the future.

Loading…
Cancel
Save