From: Darold Gilles Date: Tue, 19 May 2015 21:34:16 +0000 (+0200) Subject: Add new report Sessions per application. Thanks to Keith Fiske for the feature request. X-Git-Tag: v7.1~4^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8969d1c916e130f40695fe3ab7b95f577db60c1b;p=pgbadger Add new report Sessions per application. Thanks to Keith Fiske for the feature request. --- diff --git a/pgbadger b/pgbadger index 8781f86..ef3a998 100755 --- a/pgbadger +++ b/pgbadger @@ -3377,6 +3377,17 @@ Report not supported by text format } } + # Show session per application statistics + if (!$disable_session && exists $session_info{app}) { + print $fh "\n- Sessions per application ------------------------------------------------------\n\n"; + print $fh "Application Count Total Duration Avg duration (s)\n"; + foreach my $d (sort keys %{$session_info{app}}) { + print $fh "$d - ", &comma_numbers($session_info{app}{$d}{count}), " ", &convert_time($session_info{app}{$d}{duration}), + " ", &convert_time($session_info{app}{$d}{duration} / $session_info{app}{$d}{count}), "\n"; + } + } + + # Show connection per database statistics if (!$disable_connection && exists $connection_info{database}) { print $fh "\n- Connections per database ------------------------------------------------------\n\n"; @@ -3908,6 +3919,7 @@ sub html_header
  • Sessions per database
  • Sessions per user
  • Sessions per host
  • +
  • Sessions per application
  • }; @@ -5392,6 +5404,89 @@ sub print_host_session delete $drawn_graphs{hostsessions_graph}; } +sub print_app_session +{ + my %infos = (); + my $total_count = 0; + my $c = 0; + my $sess_app_info = ''; + my @main_app = ('unknown',0); + foreach my $h (sort keys %{$session_info{app}}) { + $sess_app_info .= "$h" . &comma_numbers($session_info{app}{$h}{count}) . + "" . &convert_time($session_info{app}{$h}{duration}) . "" . + &convert_time($session_info{app}{$h}{duration} / $session_info{app}{$h}{count}) . + ""; + $total_count += $session_info{app}{$h}{count}; + if ($main_app[1] < $session_info{app}{$h}{count}) { + $main_app[0] = $h; + $main_app[1] = $session_info{app}{$h}{count}; + } + } + if ($graph) { + my @small = (); + foreach my $d (sort keys %{$session_info{app}}) { + if ((($session_info{app}{$d}{count} * 100) / ($total_count||1)) > $pie_percentage_limit) { + $infos{$d} = $session_info{app}{$d}{count} || 0; + } else { + $infos{"Sum sessions < $pie_percentage_limit%"} += $session_info{app}{$d}{count} || 0; + push(@small, $d); + } + } + if ($#small == 0) { + $infos{$small[0]} = $infos{"Sum sessions < $pie_percentage_limit%"}; + delete $infos{"Sum sessions < $pie_percentage_limit%"}; + } + } + $drawn_graphs{appsessions_graph} = &flotr2_piegraph($graphid++, 'graph_appsessions', 'Connections per application', %infos); + $sess_app_info = qq{$NODATA} if (!$total_count); + $total_count = &comma_numbers($total_count); + print $fh qq{ +
    +

    Sessions per application

    +
    +

    Key values

    +
    +
      +
    • $main_app[0] Main Host
    • +
    • $total_count sessions Total
    • +
    +
    +
    +
    +
    + +
    +
    + $drawn_graphs{appsessions_graph} +
    +
    + + + + + + + + + + + $sess_app_info + +
    ApplicationCountTotal DurationAverage Duration
    +
    +
    +
    +
    +
    +}; + + delete $drawn_graphs{appsessions_graph}; +} + + sub print_database_session { my %infos = (); @@ -8544,6 +8639,8 @@ sub dump_as_html &print_user_session(); # Show per host sessions &print_host_session(); + # Show per application sessions + &print_app_session(); } @@ -9503,6 +9600,11 @@ sub load_stats $session_info{host}{$host}{duration} += $_session_info{host}{$host}{duration}; } + foreach my $app (keys %{ $_session_info{app}}) { + $session_info{app}{$app}{count} += $_session_info{app}{$app}{count}; + $session_info{app}{$app}{duration} += $_session_info{app}{$app}{duration}; + } + ### tempfile_info ### $tempfile_info{count} += $_tempfile_info{count} @@ -10178,6 +10280,10 @@ sub parse_query $session_info{user}{$usr}{duration} += $time; $session_info{host}{$host}{count}++; $session_info{host}{$host}{duration} += $time; + my $app = 'unknown'; + $app = $prefix_vars{'t_appname'} if (exists $prefix_vars{'t_appname'}); + $session_info{app}{$app}{count}++; + $session_info{app}{$app}{duration} += $time; my $k = &get_hist_inbound($time, @histogram_session_time); $overall_stat{histogram}{session_time}{$k}++; $overall_stat{histogram}{session_total}++; @@ -13909,7 +14015,7 @@ footer { height: 400px; } -#queriesbytype_graph, #lockbytype_graph, #databasesessions_graph, #usersessions_graph, #hostsessions_graph, #databaseconnections_graph, #userconnections_graph, #hostconnections_graph, #logstype_graph, #tableanalyzes_graph, #tablevacuums_graph, #tuplevacuums_graph, #pagevacuums_graph, #queriesbydatabase_graph, #queriesbyapplication_graph, #queriesbyuser_graph, #queriesbyhost_graph, #histogram_query_times_graph, #histogram_session_times_graph, #durationbyuser_graph { +#queriesbytype_graph, #lockbytype_graph, #databasesessions_graph, #usersessions_graph, #hostsessions_graph, #appsessions_graph, #databaseconnections_graph, #userconnections_graph, #hostconnections_graph, #logstype_graph, #tableanalyzes_graph, #tablevacuums_graph, #tuplevacuums_graph, #pagevacuums_graph, #queriesbydatabase_graph, #queriesbyapplication_graph, #queriesbyuser_graph, #queriesbyhost_graph, #histogram_query_times_graph, #histogram_session_times_graph, #durationbyuser_graph { width : 100%; height: 320px; } @@ -13969,7 +14075,7 @@ footer { width : 94.5%; } - #queriesbytype_graph, #lockbytype_graph, #databasesessions_graph, #usersessions_graph, #hostsessions_graph, #databaseconnections_graph, #userconnections_graph, #hostconnections_graph, #logstype_graph, #tableanalyzes_graph, #tablevacuums_graph, #tuplevacuums_graph, #pagevacuums_graph, #queriesbydatabase_graph, #queriesbyapplication_graph, #queriesbyuser_graph, #queriesbyhost_graph, #histogram_query_times_graph, #histogram_session_times_graph, #durationbyuser_graph { + #queriesbytype_graph, #lockbytype_graph, #databasesessions_graph, #usersessions_graph, #hostsessions_graph, #appsessions_graph, #databaseconnections_graph, #userconnections_graph, #hostconnections_graph, #logstype_graph, #tableanalyzes_graph, #tablevacuums_graph, #tuplevacuums_graph, #pagevacuums_graph, #queriesbydatabase_graph, #queriesbyapplication_graph, #queriesbyuser_graph, #queriesbyhost_graph, #histogram_query_times_graph, #histogram_session_times_graph, #durationbyuser_graph { width : 94.5%; }