From: Guillaume Le Bihan Date: Thu, 19 Mar 2015 17:30:00 +0000 (+0100) Subject: Add a list of user involved to the time consuming queries panel and to the Most frequ... X-Git-Tag: v7.0~13^2~5 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=30a98aada5c7f746bf4c62c6c162cdf1a74179c0;p=pgbadger Add a list of user involved to the time consuming queries panel and to the Most frequent queries one. --- diff --git a/pgbadger b/pgbadger index 1a6dd58..c3056bd 100755 --- a/pgbadger +++ b/pgbadger @@ -913,6 +913,7 @@ my %overall_stat = (); my %overall_checkpoint = (); my @top_slowest = (); my %normalyzed_info = (); +my %normalyzed_user = (); my %error_info = (); my %logs_type = (); my %per_minute_info = (); @@ -2953,6 +2954,7 @@ sub set_top_locked_info push(@top_locked_info, $tmp_top_locked_info[$i]); last if ($i == $end_top); } + } # Stores the top N slowest queries @@ -2984,6 +2986,23 @@ sub set_top_sample $normalyzed_info{$norm}{samples}{$dt}{app} = $app; $normalyzed_info{$norm}{samples}{$dt}{bind} = $bind; + # Gathering data into normalyzed_user, to display importance of each user for each time consuming query + my $duration; + my $us; + foreach my $k (sort {$b <=> $a} keys %{$normalyzed_info{$norm}{samples}}) { + if (!exists $normalyzed_info{$norm}{samples}{$k}{used}) { + $user = $normalyzed_info{$norm}{samples}{$k}{user}; + + if (!exists $normalyzed_user{$norm}{$user}) { + $normalyzed_user{$norm}{$user}{Duration} = 0; + $normalyzed_user{$norm}{$user}{numberRequests} = 0; + } + $normalyzed_user{$norm}{$user}{Duration} += $k; + $normalyzed_user{$norm}{$user}{numberRequests} += 1; + $normalyzed_info{$norm}{samples}{$k}{used} = 1; + } + } + if ($sample > 0) { my $i = 1; foreach my $k (sort {$b <=> $a} keys %{$normalyzed_info{$norm}{samples}}) { @@ -7394,6 +7413,38 @@ sub print_time_consuming

+}; + print $fh qq{ + +
+ +
+

+ +
+
+}; + + my $idx = 1; + foreach my $d (sort {$normalyzed_user{$k}{$b}{Duration} <=> $normalyzed_user{$k}{$a}{Duration}} keys %{$normalyzed_user{$k}}) { + if ($normalyzed_user{$k}{$d}{Duration} > 0) { + my $details = "[User: $d"; + $details .= " - Total duration for this user: ".&convert_time($normalyzed_user{$k}{$d}{Duration}) if ($normalyzed_user{$k}{$d}{Duration}); + $details .= " - Number of requests: $normalyzed_user{$k}{$d}{numberRequests}" if ($normalyzed_user{$k}{$d}{numberRequests}); + $details .= " ]\n"; + print $fh qq{ +
$details
+ }; + $idx++; + } + } + print $fh qq{ +
+

+
+ +}; + print $fh qq{ }; @@ -7557,9 +7608,43 @@ sub print_most_frequent

+}; + + print $fh qq{ + +
+ +
+

+ +
+
+}; + + my $idx = 1; + foreach my $d (sort {$normalyzed_user{$k}{$b}{numberRequests} <=> $normalyzed_user{$k}{$a}{numberRequests}} keys %{$normalyzed_user{$k}}) { + if ($normalyzed_user{$k}{$d}{Duration} > 0) { + my $details = "[User: $d"; + $details .= " - Total duration for this user: ".&convert_time($normalyzed_user{$k}{$d}{Duration}) if ($normalyzed_user{$k}{$d}{Duration}); + $details .= " - Number of requests: $normalyzed_user{$k}{$d}{numberRequests}" if ($normalyzed_user{$k}{$d}{numberRequests}); + $details .= " ]\n"; + print $fh qq{ +
$details
+ }; + $idx++; + } + } + print $fh qq{ +
+

+
+ +}; + print $fh qq{ }; + $rank++; } if (scalar keys %normalyzed_info == 0) { @@ -9052,13 +9137,6 @@ sub parse_query if ($extension eq 'tsung') { delete $tsung_session{$prefix_vars{'t_pid'}} } - } elsif (!$disable_session && ($prefix_vars{'t_loglevel'} eq 'WARNING')) { - if ($prefix_vars{'t_query'} =~ /terminating connection/) { - delete $current_sessions{$prefix_vars{'t_pid'}}; - if ($extension eq 'tsung') { - delete $tsung_session{$prefix_vars{'t_pid'}} - } - } } # Do not process DEALLOCATE lines @@ -10860,12 +10938,10 @@ sub build_log_line_prefix_regex my $re = qr{ ( - (?:--)[\ \t\S]* # single line comments + (?:--|\#)[\ \t\S]* # single line comments | (?:<>|<=>|>=|<=|==|=|!=|!|<<|>>|<|>|\|\||\||&&|&|-|\+|\*(?!/)|/(?!\*)|\%|~|\^|\?) # operators and tests - (?:\#|\@\-\@|\@\@|\#\#|<\->|\&<|\&>|<<\||\|>>|\&<\||\|\&>|<\^|>\^|\?\#|\?\-|\?\||\?\-\||\?\|\||\@>|<\@|\~=) - # Geometric Operators | [\[\]\(\),;.] # punctuation (parenthesis, comma) |