From: Alexander Moisseev Date: Wed, 27 Dec 2017 17:54:06 +0000 (+0300) Subject: [Minor] rspamd_stats: Add progress indicator X-Git-Tag: 1.7.0~316^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c396dd392d649f37e75b2085cdb6337fa9fbdd01;p=rspamd.git [Minor] rspamd_stats: Add progress indicator --- diff --git a/utils/rspamd_stats.pl b/utils/rspamd_stats.pl index 2c40e347c..1f075b9bb 100755 --- a/utils/rspamd_stats.pl +++ b/utils/rspamd_stats.pl @@ -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.