From: Darold Date: Sun, 24 Jun 2012 09:46:50 +0000 (+0200) Subject: Add --disable-error command line option to remove error report from the output X-Git-Tag: v3.2~222 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3a114152dbd3fda167f89968320f060e13321452;p=pgbadger Add --disable-error command line option to remove error report from the output --- diff --git a/README b/README index f515dac..4921c34 100644 --- a/README +++ b/README @@ -44,6 +44,7 @@ SYNOPSIS --exclude-query regex : any query matching the given regex will be excluded from the report. For example: "^(COPY|VACUUM|COMMIT)" you can use this option multiple time. + --disable-error : do not generate error report. Examples: diff --git a/doc/pgBadger.pod b/doc/pgBadger.pod index c27eff2..658a1ec 100644 --- a/doc/pgBadger.pod +++ b/doc/pgBadger.pod @@ -46,6 +46,8 @@ Options: --exclude-query regex : any query matching the given regex will be excluded from the report. For example: "^(COPY|VACUUM|COMMIT)" you can use this option multiple time. + --disable-error : do not generate error report. + Examples: diff --git a/pgbadger b/pgbadger index a5106c2..4b259ee 100755 --- a/pgbadger +++ b/pgbadger @@ -65,6 +65,7 @@ my $quiet = 0; my $progress = 0; my $error_only = 0; my @exclude_query = (); +my $disable_error = 0; my $NUMPROGRESS = 10000; my @DIMENSIONS = (800,300); @@ -109,6 +110,7 @@ my $result = GetOptions ( "image-format=s"=> \$img_format, "w|watch-mode!" => \$error_only, "exclude-query=s" => \@exclude_query, + "disable-error!"=> \$disable_error, ); if ($ver) { @@ -189,6 +191,11 @@ if (not defined $tmpfh) { $tmpfh->close(); unlink($outfile) if (-e $outfile); +# -w and --disable-error can't go together +if ($error_only && $disable_error) { + die "FATAL: please choose between no error report and reporting errors only.\n"; +} + # Testing regex syntaxe if ($#exclude_query >= 0) { foreach my $r (@exclude_query) { @@ -514,6 +521,7 @@ Options: --exclude-query regex : any query matching the given regex will be excluded from the report. For example: "^(COPY|VACUUM|COMMIT)" you can use this option multiple time. + --disable-error : do not generate error report. Examples: @@ -691,12 +699,14 @@ Last query: $overall_stat{'last_query'} print $fh "Query peak: ", &comma_numbers($overall_stat{'query_peak'}{$_}), " queries/s at $_"; last; } - my $fmt_errors = &comma_numbers($overall_stat{'errors_number'}) || 0; - my $fmt_unique_error = &comma_numbers(scalar keys %{$overall_stat{'unique_normalized_errors'}}) || 0; - print $fh qq{ + if (!$disable_error) { + my $fmt_errors = &comma_numbers($overall_stat{'errors_number'}) || 0; + my $fmt_unique_error = &comma_numbers(scalar keys %{$overall_stat{'unique_normalized_errors'}}) || 0; + print $fh qq{ Number of errors: $fmt_errors Number of unique normalized errors: $fmt_unique_error }; + } if ($tempfile_info{count}) { my $fmt_temp_maxsise = &comma_numbers($tempfile_info{maxsize}) || 0; my $fmt_temp_avsize = &comma_numbers(sprintf("%.2f", ($tempfile_info{maxsize}/$tempfile_info{count}))); @@ -891,28 +901,30 @@ Report not supported by text format $idx++; } - print $fh "\n- Most frequent errors (N) ---------------------------------------------\n\n"; - print $fh "Rank Times reported Error\n"; - $idx = 1; - foreach my $k (sort {$error_info{$b}{count} <=> $error_info{$a}{count}} keys %error_info) { - next if (!$error_info{$k}{count}); - last if ($idx > $top); - print $fh "$idx) " . &comma_numbers($error_info{$k}{count}) . " - $k\n"; - print $fh "--\n"; - if ($error_info{$k}{count} > 1) { - my $j = 1; - for (my $i = 0; $i <= $#{$error_info{$k}{date}}; $i++) { - print $fh "\t- Example $j: $error_info{$k}{date}[$i] - $error_info{$k}{error}[$i]\n"; - print $fh "\t\tDetail: $error_info{$k}{detail}[$i]\n" if ($error_info{$k}{detail}[$i]); - $j++; + if (!$disable_error) { + print $fh "\n- Most frequent errors (N) ---------------------------------------------\n\n"; + print $fh "Rank Times reported Error\n"; + $idx = 1; + foreach my $k (sort {$error_info{$b}{count} <=> $error_info{$a}{count}} keys %error_info) { + next if (!$error_info{$k}{count}); + last if ($idx > $top); + print $fh "$idx) " . &comma_numbers($error_info{$k}{count}) . " - $k\n"; + print $fh "--\n"; + if ($error_info{$k}{count} > 1) { + my $j = 1; + for (my $i = 0; $i <= $#{$error_info{$k}{date}}; $i++) { + print $fh "\t- Example $j: $error_info{$k}{date}[$i] - $error_info{$k}{error}[$i]\n"; + print $fh "\t\tDetail: $error_info{$k}{detail}[$i]\n" if ($error_info{$k}{detail}[$i]); + $j++; + } + } elsif ($error_info{$k}{detail}[0]) { + print $fh "\t- Example: $error_info{$k}{date}[0] - $k"; + print $fh "\t\tDetail: $error_info{$k}{detail}[0]\n"; + } else { + print $fh "\t- Example: $error_info{$k}{date}[0] - $k\n"; } - } elsif ($error_info{$k}{detail}[0]) { - print $fh "\t- Example: $error_info{$k}{date}[0] - $k"; - print $fh "\t\tDetail: $error_info{$k}{detail}[0]\n"; - } else { - print $fh "\t- Example: $error_info{$k}{date}[0] - $k\n"; + $idx++; } - $idx++; } print $fh "\n\n"; print $fh "Report generated by PgBadger $VERSION.\n"; @@ -1210,8 +1222,12 @@ EOF Queries that took up the most time (N) | Most frequent queries (N) | Slowest queries (N)
+}; + if (!$disable_error) { + print $fh qq{ Most frequent errors (N) | }; + } if (scalar keys %lock_info > 0) { print $fh qq{Locks by type |}; } @@ -1279,9 +1295,12 @@ sub html_footer print $fh qq{
  • Connections per host
  • }; } - - print $fh qq{Slowest queries
  • Queries that took up the most time (N)
  • Most frequent queries (N)
  • Slowest queries (N)
  • Most frequent errors (N)
  • - + print $fh qq{Slowest queries
  • Queries that took up the most time (N)
  • Most frequent queries (N)
  • Slowest queries (N)
  • +}; + if (!$disable_error) { + print $fh "
  • Most frequent errors (N)
  • \n"; + } + print $fh qq{
    Table of contents
    @@ -1338,15 +1357,17 @@ sub dump_as_html print $fh "
  • Query peak: ", &comma_numbers($overall_stat{'query_peak'}{$_}), " queries/s at $_
  • "; last; } - my $fmt_errors = &comma_numbers($overall_stat{'errors_number'}) || 0; - my $fmt_unique_error = &comma_numbers(scalar keys %{$overall_stat{'unique_normalized_errors'}}) || 0; - print $fh qq{ + if (!$disable_error) { + my $fmt_errors = &comma_numbers($overall_stat{'errors_number'}) || 0; + my $fmt_unique_error = &comma_numbers(scalar keys %{$overall_stat{'unique_normalized_errors'}}) || 0; + print $fh qq{
  • Number of errors: $fmt_errors
  • Number of unique normalized errors: $fmt_unique_error