From: Darold Gilles Date: Thu, 12 Jul 2012 13:45:58 +0000 (+0200) Subject: This new report sums the messages by log types. The report shows the number of messag... X-Git-Tag: v3.2~186 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9d85688ee9510ecff02e1a4a9b71eaa6b4e0d3af;p=pgbadger This new report sums the messages by log types. The report shows the number of messages of each log type, and a percentage. It also displays a graph. Patch by Guillaume Lelarge --- diff --git a/pgbadger b/pgbadger index 0a97985..f5c2907 100755 --- a/pgbadger +++ b/pgbadger @@ -343,6 +343,7 @@ my %overall_stat = (); my @top_slowest = (); my %normalyzed_info = (); my %error_info = (); +my %logs_type = (); my %per_hour_info = (); my %per_minute_info = (); my %lock_info = (); @@ -1081,6 +1082,18 @@ sub show_error_as_text $idx++; } + if (scalar keys %logs_type > 0) { + print $fh "\n- Logs per type ---------------------------------------------\n\n"; + + my $total_logs = 0; + foreach my $d (keys %logs_type) { + $total_logs += $logs_type{$d}; + } + print $fh "Logs type Count Percentage\n"; + foreach my $d (sort keys %logs_type) { + print $fh "$d\t\t", &comma_numbers($logs_type{$d}), "\t", sprintf("%0.2f", ($logs_type{$d}*100)/$total_logs), "%\n"; + } + } } @@ -1267,7 +1280,7 @@ div#littleToc a:hover { text-decoration:none; background-color:#DDDDDD; } -moz-box-shadow:3px 3px 6px 2px #A9A9A9; -webkit-box-shadow:3px 3px 6px #A9A9A9; } -#queriesbytype_graph, #lockbytype_graph, #databasesessions_graph, #usersessions_graph, #hostsessions_graph, #databaseconnections_graph, #userconnections_graph, #hostconnections_graph { +#queriesbytype_graph, #lockbytype_graph, #databasesessions_graph, #usersessions_graph, #hostsessions_graph, #databaseconnections_graph, #userconnections_graph, #hostconnections_graph, #logstype_graph { width : 500px; height: 250px; background:#F3F2ED; @@ -1315,11 +1328,11 @@ EOF

PgBadger

}; - if (!$error_only) { - print $fh qq{ + print $fh qq{ \n"; } + if (!$disable_error) { + print $fh qq{Most frequent errors (N) | }; + print $fh qq{Logs per type}; + } + print $fh "\n"; print $fh "

Normalized reports are marked with a \"(N)\".

\n"; } @@ -1378,14 +1392,14 @@ sub html_footer }; - if (!$error_only) { - print $fh qq{ + print $fh qq{
+ } + if (!$disable_error) { + print $fh "
  • Most frequent errors (N)
  • \n"; + print $fh qq{
  • Logs per type
  • \n}; + } + print $fh qq{
    Table of contents
    }; - } print $fh qq{ @@ -2511,6 +2526,56 @@ sub show_error_as_html } print $fh "\n"; + + if (scalar keys %logs_type > 0) { + # Show log' types + print $fh qq{ +

    Logs per type ^

    + +
    + + + + + + + }; + + my $total_logs = 0; + foreach my $d (sort keys %logs_type) { + $total_logs += $logs_type{$d}; + } + + my $c = 0; + + foreach my $d (sort keys %logs_type) { + my $colb = $c % 2; + print $fh "\n"; + $c++; + } + + print $fh "
    TypeCountPercentage
    $d", &comma_numbers($logs_type{$d}), "", sprintf("%0.2f", ($logs_type{$d}*100)/$total_logs), "%
    \n"; + if ($graph && $total_logs) { + my %infos = (); + my @small = (); + foreach my $d (sort keys %logs_type) { + if ((($logs_type{$d}*100)/$total_logs) > $pie_percentage_limit) { + $infos{$d} = $logs_type{$d} || 0; + } else { + $infos{"Sum log types < $pie_percentage_limit%"} += $logs_type{$d} || 0; + push(@small, $d); + } + } + + if ($#small == 0) { + $infos{$small[0]} = $infos{"Sum log types < $pie_percentage_limit%"}; + delete $infos{"Sum log types < $pie_percentage_limit%"}; + } + &flotr2_piegraph(17, 'logstype_graph','Logs per type', %infos); + } + print $fh "
    \n"; + } + } @@ -2617,6 +2682,9 @@ sub parse_query $first_log_date = "$t_year-$t_month-$t_day $t_hour:$t_min:$t_sec" if (!$first_log_date); $last_log_date = "$t_year-$t_month-$t_day $t_hour:$t_min:$t_sec"; + # Store a counter of logs type + $logs_type{$t_loglevel}++; + # Replace syslog tablulation rewrite $t_query =~ s/#011/\t/g if ($format eq 'syslog'); # Remove line from session number