From a91fec53b6104d6943e4587e022d35d82d2a84ee Mon Sep 17 00:00:00 2001 From: Darold Gilles Date: Wed, 22 Jun 2016 12:25:25 +0200 Subject: [PATCH] Fix autodetection of PgBouncer files containing only stats lines. Thanks to Glyn Astill for the patch. --- pgbadger | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/pgbadger b/pgbadger index bce960d..21554c5 100755 --- a/pgbadger +++ b/pgbadger @@ -2283,9 +2283,11 @@ sub process_file } my $is_pgbouncer_format = 0; + my $retcode = 0; + my $msg = ''; if ($logfile ne '-') { # Detect if we are parsing a pgbouncer file - my ($is_pgbouncer_format, $retcode, $msg) = &detect_pgbouncer_log($logfile, $saved_last_line{datetime}, 1); + ($is_pgbouncer_format, $retcode, $msg) = &detect_pgbouncer_log($logfile, $saved_last_line{datetime}, 1); } # Parse pgbouncer logfile @@ -3105,6 +3107,14 @@ sub detect_pgbouncer_log for (my $i = 0 ; $i <= $#pgb_prefix_params ; $i++) { $prefix_vars{$pgb_prefix_params[$i]} = $matches[$i]; } + } else { + @matches = ($line =~ $pgbouncer_log_parse1); + if (($#matches >= 0) && ($matches[-1] =~ /^Stats:/) ) { + $ispgbouncerlog++; + for (my $i = 0 ; $i <= $#pgb_prefix_parse1 ; $i++) { + $prefix_vars{$pgb_prefix_params[$i]} = $matches[$i]; + } + } } next if (!$prefix_vars{'t_timestamp'}); if ($iscompressed) { @@ -13436,7 +13446,12 @@ sub autodetect_format last if (($nfound > 10) || ($nline > 5000)); } $tfile->close(); - if (!$format) { + # When --pgbouncer-only is used force the format to stderr as + # we don't have to care of log format with pgbouncer only report + if (!$format && $pgbouncer_only) { + $pgbouncer_only = 1; + $fmt = 'stderr'; + } elsif (!$format) { if (!$fmt || ($nfound < 10)) { localdie("FATAL: unable to detect log file format from $file, please use -f option.\n"); } -- 2.50.1