From: Darold Gilles Date: Thu, 27 Dec 2012 09:00:36 +0000 (+0100) Subject: Add link menu to the request per database and limit the display of this information... X-Git-Tag: v3.2~76 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c9be1c3082b4de196b4f168d815563be3876dc70;p=pgbadger Add link menu to the request per database and limit the display of this information when there is more than one database. --- diff --git a/pgbadger b/pgbadger index 261ab64..e2d4ac3 100755 --- a/pgbadger +++ b/pgbadger @@ -1304,8 +1304,8 @@ Average duration of sessions: $avg_session_duration if (!$disable_connection && $connection_info{count}) { print $fh "Total number of connections: $connection_info{count}\n"; } - if ($database_info{count}) { - print $fh "Total number of databases: $database_info{count}\n"; + if (exists $database_info{database}) { + print $fh "Total number of databases: ", scalar keys %{$database_info{database}}, "\n"; } if (!$disable_hourly && $overall_stat{'queries_number'}) { print $fh qq{ @@ -1335,6 +1335,21 @@ Report not supported by text format print $fh "OTHERS: ", &comma_numbers($total - $totala) || 0, " ", sprintf("%0.2f", (($total - $totala) * 100) / $total), "%\n" if (($total - $totala) > 0); print $fh "\n"; + + # Show request per database statistics + if (scalar keys %{$database_info{database}} > 1) { + print $fh "\n- Request per database ------------------------------------------------------\n\n"; + print $fh "Database Request type Count\n"; + foreach my $d (sort keys %{$database_info{database}}) { + print $fh "$d - ", &comma_numbers($database_info{database}{$d}{count}), "\n"; + foreach my $r (sort keys %{$database_info{database}{$d}}) { + next if ($r eq 'count'); + print $fh "\t$r ", &comma_numbers($database_info{database}{$d}{$r}), "\n"; + } + } + } + + } if (!$disable_lock && scalar keys %lock_info > 0) { @@ -1355,6 +1370,7 @@ Report not supported by text format } print $fh "Total:\t\t\t", &comma_numbers($total_count), " ", &convert_time($total_duration), " ", &convert_time($total_duration / ($total_count || 1)), "\n"; + } # Show session per database statistics @@ -1388,19 +1404,6 @@ Report not supported by text format } } - # Show request per database statistics - if (exists $database_info{database}) { - print $fh "\n- Request per database ------------------------------------------------------\n\n"; - print $fh "Database Request type Count\n"; - foreach my $d (sort keys %{$database_info{database}}) { - print $fh "$d - ", &comma_numbers($database_info{database}{$d}{count}), "\n"; - foreach my $r (sort keys %{$database_info{database}{$d}}) { - next if ($r eq 'count'); - print $fh "\t$r ", &comma_numbers($database_info{database}{$d}{$r}), "\n"; - } - } - } - # Show connection per database statistics if (!$disable_connection && exists $connection_info{database}) { print $fh "\n- Connections per database ------------------------------------------------------\n\n"; @@ -1890,13 +1893,14 @@ EOF } if (!$disable_type && (!$log_duration || $enable_log_min_duration)) { print $fh qq{Queries by type | }; + print $fh qq{Requests per database | } if (scalar keys %{$database_info{database}} > 1); } if (!$disable_query && (!$log_duration || $enable_log_min_duration)) { print $fh qq{ Slowest queries | Queries that took up the most time (N) | -Most frequent queries (N) | -Slowest queries (N)
+Most frequent queries (N)
+Slowest queries (N) | } } if (!$disable_lock && scalar keys %lock_info > 0) { @@ -1956,6 +1960,7 @@ sub html_footer } if (!$disable_type && (!$log_duration || $enable_log_min_duration)) { print $fh qq{
  • Queries by type
  • }; + print $fh qq{
  • Requests per database
  • } if (scalar keys %{$database_info{database}} > 1); } if (!$disable_lock && scalar keys %lock_info > 0) { print $fh qq{
  • Locks by type
  • }; @@ -1973,7 +1978,6 @@ sub html_footer } if (!$disable_connection) { if (exists $connection_info{database}) { - print $fh qq{
  • Requests per database
  • } if ($database_info{database}); print $fh qq{
  • Connections per database
  • }; } if (exists $connection_info{user}) { @@ -2090,9 +2094,10 @@ sub dump_as_html
  • Total number of connections: $connection_info{count}
  • }; } - if ($database_info{count}) { + if (exists $database_info{database}) { + my $db_count = scalar keys %{$database_info{database}}; print $fh qq{ -
  • Total number of databases: $database_info{count}
  • +
  • Total number of databases: $db_count
  • } } print $fh qq{ @@ -2625,6 +2630,53 @@ qq{Wrote buffersAddedRemovedRecycledWrit &flotr2_piegraph(9, 'queriesbytype_graph', 'Type of queries', %data); } print $fh "\n"; + + # Show request per database statistics + if (scalar keys %{$database_info{database}} > 1) { + print $fh qq{ +

    Requests per database ^

    + +
    + + + + + + +}; + my $total_count = 0; + foreach my $d (sort keys %{$database_info{database}}) { + print $fh "\n"; + $total_count += $database_info{database}{$d}{count}; + foreach my $r (sort keys %{$database_info{database}{$d}}) { + next if ($r eq 'count'); + print $fh "\n"; + } + } + print $fh "
    DatabaseRequest typeCount
    $d", + &comma_numbers($database_info{database}{$d}{count}), "
    $r", + &comma_numbers($database_info{database}{$d}{$r}), "
    \n"; + if ($graph && $total_count) { + my %infos = (); + my @small = (); + foreach my $d (sort keys %{$database_info{database}}) { + if ((($database_info{database}{$d}{count} * 100) / $total_count) > $pie_percentage_limit) { + $infos{$d} = $database_info{database}{$d}{count} || 0; + } else { + $infos{"Sum databases < $pie_percentage_limit%"} += $database_info{database}{$d}{count} || 0; + push(@small, $d); + } + } + if ($#small == 0) { + $infos{$small[0]} = $infos{"Sum databases < $pie_percentage_limit%"}; + delete $infos{"Sum databases < $pie_percentage_limit%"}; + } + &flotr2_piegraph(20, 'requestsdatabases_graph', 'Requests per database', %infos); + } + print $fh "
    \n"; + } + + } # Lock stats per type @@ -2818,51 +2870,6 @@ qq{Wrote buffersAddedRemovedRecycledWrit print $fh "\n"; } - # Show request per database statistics - if (exists $database_info{database}) { - print $fh qq{ -

    Requests per database ^

    - -
    - - - - - - -}; - my $total_count = 0; - foreach my $d (sort keys %{$database_info{database}}) { - print $fh "\n"; - $total_count += $database_info{database}{$d}{count}; - foreach my $r (sort keys %{$database_info{database}{$d}}) { - next if ($r eq 'count'); - print $fh "\n"; - } - } - print $fh "
    DatabaseRequest typeCount
    $d", - &comma_numbers($database_info{database}{$d}{count}), "
    $r", - &comma_numbers($database_info{database}{$d}{$r}), "
    \n"; - if ($graph && $total_count) { - my %infos = (); - my @small = (); - foreach my $d (sort keys %{$database_info{database}}) { - if ((($database_info{database}{$d}{count} * 100) / $total_count) > $pie_percentage_limit) { - $infos{$d} = $database_info{database}{$d}{count} || 0; - } else { - $infos{"Sum databases < $pie_percentage_limit%"} += $database_info{database}{$d}{count} || 0; - push(@small, $d); - } - } - if ($#small == 0) { - $infos{$small[0]} = $infos{"Sum databases < $pie_percentage_limit%"}; - delete $infos{"Sum databases < $pie_percentage_limit%"}; - } - &flotr2_piegraph(20, 'requestsdatabases_graph', 'Requests per database', %infos); - } - print $fh "
    \n"; - } - # Show connection per database statistics if (!$disable_connection && exists $connection_info{database}) { print $fh qq{ @@ -3513,7 +3520,6 @@ sub load_stats $database_info{database}{$db}{$k} += $_database_info{database}{$db}{$k}; } } - $database_info{count} += $_database_info{count}; ### connection_info ### @@ -4452,7 +4458,6 @@ sub store_queries $per_hour_info{"$cur_day_str"}{"$cur_hour_str"}{$action}{duration} += $cur_info{$t_pid}{duration}; $database_info{database}{$cur_info{$t_pid}{dbname}}{count}++; $database_info{database}{$cur_info{$t_pid}{dbname}}{$action}++; - $database_info{count}++; #if ($graph) { # $per_minute_info{"\L$1\E"}{"$cur_day_str"}{"$cur_hour_str"}{$cur_info{$t_pid}{min}}{count}++; # $per_minute_info{"\L$1\E"}{"$cur_day_str"}{"$cur_hour_str"}{$cur_info{$t_pid}{min}}{duration} += $cur_info{$t_pid}{duration};