]> granicus.if.org Git - pgbadger/commitdiff
Add --disable-error command line option to remove error report from the output
authorDarold <gilles@darold.net>
Sun, 24 Jun 2012 09:46:50 +0000 (11:46 +0200)
committerDarold <gilles@darold.net>
Sun, 24 Jun 2012 09:46:50 +0000 (11:46 +0200)
README
doc/pgBadger.pod
pgbadger

diff --git a/README b/README
index f515dac1ce9a6a5dd8fdf4127760c53298295824..4921c34e947d938e958e2432729ad85310aebea0 100644 (file)
--- 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:
 
index c27eff2823fc59f0a9917eaaef3cf6821b6ce361..658a1ec7ba824bb99209bd91d2b4016273477390 100644 (file)
@@ -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:
 
index a5106c2b3a7b44832afdd33e0aafa0492f7192c3..4b259ee26e45effbb44d61603755d49300d56dc9 100755 (executable)
--- 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 <a href=\"https://github.com/dalibo/pgbadger\">PgBadger</a> $VERSION.\n";
@@ -1210,8 +1222,12 @@ EOF
 <a href="#NormalizedQueriesMostTimeReport">Queries that took up the most time (N)</a> |
 <a href="#NormalizedQueriesMostFrequentReport">Most frequent queries (N)</a> |
 <a href="#NormalizedQueriesSlowestAverageReport">Slowest queries (N)</a><br />
+};
+               if (!$disable_error) {
+                       print $fh qq{
 <a href="#NormalizedErrorsMostFrequentReport">Most frequent errors (N)</a> |
 };
+               }
                if (scalar keys %lock_info > 0) {
                        print $fh qq{<a href="#LocksByTypeReport">Locks by type</a> |};
                }
@@ -1279,9 +1295,12 @@ sub html_footer
                        print $fh qq{<li><a href="#ConnectionsHostReport">Connections per host</a></li><li>};
                }
 
-
-               print $fh qq{<a href="#SlowestQueriesReport">Slowest queries</a></li><li><a href="#NormalizedQueriesMostTimeReport">Queries that took up the most time (N)</a></li><li><a href="#NormalizedQueriesMostFrequentReport">Most frequent queries (N)</a></li><li><a href="#NormalizedQueriesSlowestAverageReport">Slowest queries (N)</a></li><li><a href="#NormalizedErrorsMostFrequentReport">Most frequent errors (N)</a></li>
-               </ul>
+               print $fh qq{<a href="#SlowestQueriesReport">Slowest queries</a></li><li><a href="#NormalizedQueriesMostTimeReport">Queries that took up the most time (N)</a></li><li><a href="#NormalizedQueriesMostFrequentReport">Most frequent queries (N)</a></li><li><a href="#NormalizedQueriesSlowestAverageReport">Slowest queries (N)</a></li>
+};
+               if (!$disable_error) {
+                       print $fh "<li><a href=\"#NormalizedErrorsMostFrequentReport\">Most frequent errors (N)</a></li>\n";
+               }
+               print $fh qq{</ul>
        </div>
        <div id="littleTocTitle">Table of contents</div>
 </div>
@@ -1338,15 +1357,17 @@ sub dump_as_html
                print $fh "<li>Query peak: ", &comma_numbers($overall_stat{'query_peak'}{$_}), " queries/s at $_</li>";
                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{
 <li>Number of errors: $fmt_errors</li>
 <li>Number of unique normalized errors: $fmt_unique_error</li>
 </ul>
 </td><td valign="top">
 <ul>
 };
+       }
        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}));
@@ -2184,7 +2205,8 @@ sub dump_as_html
        }
        print $fh "</table>\n";
 
-       print $fh qq{
+       if (!$disable_error) {
+               print $fh qq{
 <h2 id="NormalizedErrorsMostFrequentReport">Most frequent errors (N) <a href="#top" title="Back to top">^</a></h2>
 <table class="queryList">
 <tr>
@@ -2194,44 +2216,45 @@ sub dump_as_html
 
 </tr>
 };
-       $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);
-               my $col = $idx % 2;
-               print $fh "<tr class=\"row$col\"><td class=\"center top\">$idx</td><td class=\"relevantInformation top center\"><div class=\"tooltipLink\"><span class=\"information\">", &comma_numbers($error_info{$k}{count}), "</span>";
-               print $fh "<div class=\"tooltip\"><table><tr><th>Day</th><th>Time</th><th>Count</th></tr>";
-               foreach my $d (sort keys %{$error_info{$k}{chronos}}) {
-                       my $c = 1;
-                       $d =~ /^\d{4}(\d{2})(\d{2})$/;
-                       my $zday = "$abbr_month{$1} $2";
-                       foreach my $h (sort keys %{$error_info{$k}{chronos}{$d}}) {
-                               my $colb = $c % 2;
-                               $zday = "&nbsp;" if ($c > 1);
-                               print $fh "<tr class=\"row$colb\"><td>$zday</td><td>$h</td><td>", &comma_numbers($error_info{$k}{chronos}{$d}{$h}{count}), "</td></tr>";
-                               $c++;
+               $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);
+                       my $col = $idx % 2;
+                       print $fh "<tr class=\"row$col\"><td class=\"center top\">$idx</td><td class=\"relevantInformation top center\"><div class=\"tooltipLink\"><span class=\"information\">", &comma_numbers($error_info{$k}{count}), "</span>";
+                       print $fh "<div class=\"tooltip\"><table><tr><th>Day</th><th>Time</th><th>Count</th></tr>";
+                       foreach my $d (sort keys %{$error_info{$k}{chronos}}) {
+                               my $c = 1;
+                               $d =~ /^\d{4}(\d{2})(\d{2})$/;
+                               my $zday = "$abbr_month{$1} $2";
+                               foreach my $h (sort keys %{$error_info{$k}{chronos}{$d}}) {
+                                       my $colb = $c % 2;
+                                       $zday = "&nbsp;" if ($c > 1);
+                                       print $fh "<tr class=\"row$colb\"><td>$zday</td><td>$h</td><td>", &comma_numbers($error_info{$k}{chronos}{$d}{$h}{count}), "</td></tr>";
+                                       $c++;
+                               }
                        }
-               }
-               print $fh "</table></div></div></td>\n";
-               if ($error_info{$k}{count} > 1) {
-                       print $fh "<td><div class=\"error\">$k</div>";
-                       print $fh "<input type=\"button\" class=\"examplesButton\" id=\"button_NormalizedErrorsMostFrequentReport_$idx\" name=\"button_NormalizedErrorsMostFrequentReport_$idx\" value=\"Show examples\" onclick=\"javascript:toggle('button_NormalizedErrorsMostFrequentReport_$idx', 'examples_NormalizedErrorsMostFrequentReport_$idx', 'examples');\" /><div id=\"examples_NormalizedErrorsMostFrequentReport_$idx\" class=\"examples\" style=\"display:none;\">";
-                       for (my $i = 0; $i <= $#{$error_info{$k}{date}}; $i++) {
-                               my $c = $i % 2;
-                               print $fh "<div class=\"example$c\" title=\"$error_info{$k}{date}[$i]\">$error_info{$k}{error}[$i]</div>\n";
-                               print $fh "<div class=\"errorInformation$c\">Detail: $error_info{$k}{detail}[$i]</div>\n" if ($error_info{$k}{detail}[$i]);
+                       print $fh "</table></div></div></td>\n";
+                       if ($error_info{$k}{count} > 1) {
+                               print $fh "<td><div class=\"error\">$k</div>";
+                               print $fh "<input type=\"button\" class=\"examplesButton\" id=\"button_NormalizedErrorsMostFrequentReport_$idx\" name=\"button_NormalizedErrorsMostFrequentReport_$idx\" value=\"Show examples\" onclick=\"javascript:toggle('button_NormalizedErrorsMostFrequentReport_$idx', 'examples_NormalizedErrorsMostFrequentReport_$idx', 'examples');\" /><div id=\"examples_NormalizedErrorsMostFrequentReport_$idx\" class=\"examples\" style=\"display:none;\">";
+                               for (my $i = 0; $i <= $#{$error_info{$k}{date}}; $i++) {
+                                       my $c = $i % 2;
+                                       print $fh "<div class=\"example$c\" title=\"$error_info{$k}{date}[$i]\">$error_info{$k}{error}[$i]</div>\n";
+                                       print $fh "<div class=\"errorInformation$c\">Detail: $error_info{$k}{detail}[$i]</div>\n" if ($error_info{$k}{detail}[$i]);
+                               }
+                               print $fh "</div>";
+                       } elsif ($error_info{$k}{detail}[0]) {
+                               print $fh "<td><div class=\"error\" title=\"$error_info{$k}{date}[0]\">$k</div>";
+                               print $fh "<div class=\"errorInformation\">Detail: $error_info{$k}{detail}[0]</div>\n";
+                       } else {
+                               print $fh "<td><div class=\"error\" title=\"$error_info{$k}{date}[0]\">$k</div>";
                        }
-                       print $fh "</div>";
-               } elsif ($error_info{$k}{detail}[0]) {
-                       print $fh "<td><div class=\"error\" title=\"$error_info{$k}{date}[0]\">$k</div>";
-                       print $fh "<div class=\"errorInformation\">Detail: $error_info{$k}{detail}[0]</div>\n";
-               } else {
-                       print $fh "<td><div class=\"error\" title=\"$error_info{$k}{date}[0]\">$k</div>";
+                       print $fh "</td></tr>\n";
+                       $idx++;
                }
-               print $fh "</td></tr>\n";
-               $idx++;
+               print $fh "</table>\n";
        }
-       print $fh "</table>\n";
 
        # Dump the html footer
        &html_footer();
@@ -2504,25 +2527,27 @@ sub parse_query
        # Store errors statistics
        if ($cur_info{query}) {
                delete $conn_received{$cur_info{pid}};
-               if ($cur_info{loglevel} =~ /WARNING|ERROR|FATAL|PANIC|HINT/) {
-                       $cur_info{query} = substr($cur_info{query}, 0, $maxlength) . '[...]' if (($maxlength > 0) && (length($cur_info{query}) > $maxlength));
-                       $cur_info{query} = $cur_info{loglevel} . ": " . $cur_info{query};
-                       $overall_stat{'errors_number'}++;
-                       my $normalized_error = &normalize_error($cur_info{query});
-                       $overall_stat{'unique_normalized_errors'}{"$normalized_error"}++;
-                       # Store normalyzed error count
-                       $error_info{$normalized_error}{count}++; 
-                       # Store normalyzed error count per time
-                       $error_info{$normalized_error}{chronos}{"$cur_info{year}$cur_info{month}$cur_info{day}"}{"$cur_info{hour}"}{count}++; 
-                       # Store normalyzed query samples
-                       my $cur_last_log_date = "$cur_info{year}-$cur_info{month}-$cur_info{day} $cur_info{hour}:$cur_info{min}:$cur_info{sec}";
-                       if ($t_loglevel =~ /DETAIL|STATEMENT/) {
-                               &set_top_error_sample($normalized_error, $cur_last_log_date, $cur_info{query}, $t_query);
-                       } else {
-                               &set_top_error_sample($normalized_error, $cur_last_log_date, $cur_info{query});
+               if (!$disable_error) {
+                       if ($cur_info{loglevel} =~ /WARNING|ERROR|FATAL|PANIC|HINT/) {
+                               $cur_info{query} = substr($cur_info{query}, 0, $maxlength) . '[...]' if (($maxlength > 0) && (length($cur_info{query}) > $maxlength));
+                               $cur_info{query} = $cur_info{loglevel} . ": " . $cur_info{query};
+                               $overall_stat{'errors_number'}++;
+                               my $normalized_error = &normalize_error($cur_info{query});
+                               $overall_stat{'unique_normalized_errors'}{"$normalized_error"}++;
+                               # Store normalyzed error count
+                               $error_info{$normalized_error}{count}++; 
+                               # Store normalyzed error count per time
+                               $error_info{$normalized_error}{chronos}{"$cur_info{year}$cur_info{month}$cur_info{day}"}{"$cur_info{hour}"}{count}++; 
+                               # Store normalyzed query samples
+                               my $cur_last_log_date = "$cur_info{year}-$cur_info{month}-$cur_info{day} $cur_info{hour}:$cur_info{min}:$cur_info{sec}";
+                               if ($t_loglevel =~ /DETAIL|STATEMENT/) {
+                                       &set_top_error_sample($normalized_error, $cur_last_log_date, $cur_info{query}, $t_query);
+                               } else {
+                                       &set_top_error_sample($normalized_error, $cur_last_log_date, $cur_info{query});
+                               }
+                               %cur_info = ();
+                               return;
                        }
-                       %cur_info = ();
-                       return;
                }
 
                # Process complete query but not debug/info logs