]> granicus.if.org Git - pgbadger/commitdiff
Fix minimal statistics output when nothing was load from log file. Thanks to Herve...
authorDarold Gilles <gilles@darold.net>
Wed, 3 Jul 2013 13:07:47 +0000 (15:07 +0200)
committerDarold Gilles <gilles@darold.net>
Wed, 3 Jul 2013 13:07:47 +0000 (15:07 +0200)
pgbadger

index 809ca8de930c4089b26b7da45701a53b4de0e172..dd67af37c775dd826ff32294e0f21249918190e8 100755 (executable)
--- a/pgbadger
+++ b/pgbadger
@@ -1136,12 +1136,12 @@ sub process_file
                                last;
                        }
 
-                       # Jump to the last line parsed if required
-                       next if (!&check_incremental_position($prefix_vars{'t_timestamp'}, join(',', @$row)));
-
                        # Store the current timestamp of the log line
                        &store_current_timestamp($prefix_vars{'t_timestamp'});
 
+                       # Jump to the last line parsed if required
+                       next if (!&check_incremental_position($prefix_vars{'t_timestamp'}, join(',', @$row)));
+
                        # Set query parameters as global variables
                        $prefix_vars{'t_dbuser'}  = $row->[1] || '';
                        $prefix_vars{'t_dbname'}  = $row->[2] || '';
@@ -1265,14 +1265,14 @@ sub process_file
                                                last;
                                        }
 
+                                       # Store the current timestamp of the log line
+                                       &store_current_timestamp($prefix_vars{'t_timestamp'});
+
                                        # Jump to the last line parsed if required
                                        next if (!&check_incremental_position($prefix_vars{'t_timestamp'}, $line));
                                        $cur_pid = $prefix_vars{'t_pid'};
                                        $goon = 1;
 
-                                       # Store the current timestamp of the log line
-                                       &store_current_timestamp($prefix_vars{'t_timestamp'});
-
                                        # Extract information from log line prefix
                                        if (!$log_line_prefix) {
                                                &parse_log_prefix($prefix_vars{'t_logprefix'});
@@ -1369,13 +1369,13 @@ sub process_file
                                                last;
                                        }
 
+                                       # Store the current timestamp of the log line
+                                       &store_current_timestamp($prefix_vars{'t_timestamp'});
+
                                        # Jump to the last line parsed if required
                                        next if (!&check_incremental_position($prefix_vars{'t_timestamp'}, $line));
                                        $cur_pid = $prefix_vars{'t_pid'};
 
-                                       # Store the current timestamp of the log line
-                                       &store_current_timestamp($prefix_vars{'t_timestamp'});
-
                                        # Extract information from log line prefix
                                        if (!$log_line_prefix) {
                                                &parse_log_prefix($prefix_vars{'t_logprefix'});
@@ -1736,9 +1736,11 @@ Log start from $overall_stat{'first_log_ts'} to $overall_stat{'last_log_ts'}
 };
 
        # Overall statistics
-       my $fmt_unique  = &comma_numbers(scalar keys %normalyzed_info);
-       my $fmt_queries = &comma_numbers($overall_stat{'queries_number'});
+       my $fmt_unique  = &comma_numbers(scalar keys %normalyzed_info) || 0;
+       my $fmt_queries = &comma_numbers($overall_stat{'queries_number'}) || 0;
        my $fmt_duration = &convert_time($overall_stat{'queries_duration'}) || 0;
+       $overall_stat{'first_query_ts'} ||= '-';
+       $overall_stat{'last_query_ts'} ||= '-';
        print $fh qq{
 
 - Overall statistics ---------------------------------------------------
@@ -1754,8 +1756,8 @@ Last query: $overall_stat{'last_query_ts'}
                last;
        }
        if (!$disable_error) {
-               my $fmt_errors = &comma_numbers($overall_stat{'errors_number'});
-               my $fmt_unique_error = &comma_numbers(scalar keys %{$overall_stat{'unique_normalized_errors'}});
+               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 events: $fmt_errors
 Number of unique normalized events: $fmt_unique_error
@@ -2713,9 +2715,11 @@ sub print_global_information
 sub print_overall_statistics
 {
 
-       my $fmt_unique  = &comma_numbers(scalar keys %normalyzed_info);
-       my $fmt_queries = &comma_numbers($overall_stat{'queries_number'});
+       my $fmt_unique  = &comma_numbers(scalar keys %normalyzed_info) || 0;
+       my $fmt_queries = &comma_numbers($overall_stat{'queries_number'}) || 0;
        my $fmt_duration = &convert_time($overall_stat{'queries_duration'}) || 0;
+       $overall_stat{'first_query_ts'} ||= '-';
+       $overall_stat{'last_query_ts'} ||= '-';
        print $fh qq{
 <div class="reports">
 <h2 id="OverallStatsReport">Overall statistics <a href="#top" title="Back to top">^</a></h2>
@@ -2733,8 +2737,8 @@ sub print_overall_statistics
                last;
        }
        if (!$disable_error) {
-               my $fmt_errors = &comma_numbers($overall_stat{'errors_number'});
-               my $fmt_unique_error = &comma_numbers(scalar keys %{$overall_stat{'unique_normalized_errors'}});
+               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 events: $fmt_errors</li>
 <li>Number of unique normalized events: $fmt_unique_error</li>
@@ -3400,11 +3404,11 @@ sub print_query_type_report
 {
        my $totala = 0;
        foreach my $a (@SQL_ACTION) {
-               $overall_stat{$a} ||= 0;
                $totala += $overall_stat{$a};
        }
-       if (!$totala) {
-               print $fh qq{
+       return if (!$totala);
+
+       print $fh qq{
 <h2 id="QueriesByTypeReport">Queries by type <a href="#top" title="Back to top">^</a></h2>
 <table>
 <tr><td width="500" align="left" valign="top">
@@ -3416,37 +3420,36 @@ sub print_query_type_report
                <th>Percentage</th>
        </tr>
 };
-               my $total = $overall_stat{'queries_number'} || 1;
+       my $total = $overall_stat{'queries_number'} || 1;
 
-               my $r = 0;
-               foreach my $a (@SQL_ACTION) {
-               print $fh "<tr class=\"row$r\"><td>$a</td><td class=\"right\">", &comma_numbers($overall_stat{'$a'}),
-                       "</td><td class=\"right\">", sprintf("%0.2f", ($overall_stat{$a} * 100) / $total), "%</td></tr>\n";
-                       ($r > 0) ? $r = 0 : $r = 1;
-               }
-               print $fh "<tr class=\"row0\"><td>OTHERS</td><td class=\"right\">", &comma_numbers($total - $totala),
-                       "</td><td class=\"right\">", sprintf("%0.2f", (($total - $totala) * 100) / $total), "%</td></tr>\n"
-                       if (($total - $totala) > 0);
-               print $fh "</table></td><td width=\"500\" align=\"center\" valign=\"top\">\n";
+       my $r = 0;
+       foreach my $a (@SQL_ACTION) {
+       print $fh "<tr class=\"row$r\"><td>$a</td><td class=\"right\">", &comma_numbers($overall_stat{'$a'}),
+               "</td><td class=\"right\">", sprintf("%0.2f", ($overall_stat{$a} * 100) / $total), "%</td></tr>\n";
+               ($r > 0) ? $r = 0 : $r = 1;
+       }
+       print $fh "<tr class=\"row0\"><td>OTHERS</td><td class=\"right\">", &comma_numbers($total - $totala),
+               "</td><td class=\"right\">", sprintf("%0.2f", (($total - $totala) * 100) / $total), "%</td></tr>\n"
+               if (($total - $totala) > 0);
+       print $fh "</table></td><td width=\"500\" align=\"center\" valign=\"top\">\n";
 
-               if ($graph) {
-                       my %data = ();
-                       foreach my $t (@SQL_ACTION) {
-                               if ((($overall_stat{$t} * 100) / $total) > $pie_percentage_limit) {
-                                       $data{$t} = $overall_stat{$t} || 0;
-                               } else {
-                                       $data{"Sum types < $pie_percentage_limit%"} += $overall_stat{$t} || 0;
-                               }
-                       }
-                       if (((($total - $totala) * 100) / $total) > $pie_percentage_limit) {
-                               $data{'Others'} = $total - $totala;
+       if ($graph) {
+               my %data = ();
+               foreach my $t (@SQL_ACTION) {
+                       if ((($overall_stat{$t} * 100) / $total) > $pie_percentage_limit) {
+                               $data{$t} = $overall_stat{$t} || 0;
                        } else {
-                               $data{"Sum types < $pie_percentage_limit%"} += $total - $totala;
+                               $data{"Sum types < $pie_percentage_limit%"} += $overall_stat{$t} || 0;
                        }
-                       &flotr2_piegraph(22, 'queriesbytype_graph', 'Type of queries', %data);
                }
-               print $fh "</td></tr></table>\n";
+               if (((($total - $totala) * 100) / $total) > $pie_percentage_limit) {
+                       $data{'Others'} = $total - $totala;
+               } else {
+                       $data{"Sum types < $pie_percentage_limit%"} += $total - $totala;
+               }
+               &flotr2_piegraph(22, 'queriesbytype_graph', 'Type of queries', %data);
        }
+       print $fh "</td></tr></table>\n";
 }
 
 sub print_request_report