From c396dd392d649f37e75b2085cdb6337fa9fbdd01 Mon Sep 17 00:00:00 2001 From: Alexander Moisseev Date: Wed, 27 Dec 2017 20:54:06 +0300 Subject: [Minor] rspamd_stats: Add progress indicator --- utils/rspamd_stats.pl | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'utils') 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. -- cgit v1.2.3