From: Darold Gilles Date: Mon, 13 Apr 2015 11:55:34 +0000 (+0200) Subject: Add --enable-checksum to show a md5 hash of each reported queries. Thanks to Thomas... X-Git-Tag: v7.0~16 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=010ef30ab5253b0944bae03c92c50dc181fbbadf;p=pgbadger Add --enable-checksum to show a md5 hash of each reported queries. Thanks to Thomas Reiss for the feature request. --- diff --git a/doc/pgBadger.pod b/doc/pgBadger.pod index eaf84d5..8e47c09 100644 --- a/doc/pgBadger.pod +++ b/doc/pgBadger.pod @@ -132,6 +132,7 @@ Options: mode. --log-duration : force pgbadger to associate log entries generated by both log_duration = on and log_statement = 'all' + --enable-checksum : used to add a md5 sum under each query report. pgBadger is able to parse a remote log file using a passwordless ssh connection. Use the -r or --remote-host to set the host ip address or hostname. There's also diff --git a/pgbadger b/pgbadger index d391888..ffeb70b 100755 --- a/pgbadger +++ b/pgbadger @@ -236,6 +236,7 @@ my $nomultiline = 0; my $noreport = 0; my $log_duration = 0; my $logfile_list = ''; +my $enable_checksum = 0; my $NUMPROGRESS = 10000; my @DIMENSIONS = (800, 300); @@ -384,6 +385,7 @@ my $result = GetOptions( 'noclean!' => \$noclean, 'noreport!' => \$noreport, 'log-duration!' => \$log_duration, + 'enable-checksum!' => \$enable_checksum, ); die "FATAL: use pgbadger --help\n" if (not $result); @@ -395,6 +397,15 @@ if ($ver) { } &usage() if ($help); +# Try to load Digest::MD5 when asked +if ($enable_checksum) { + if (eval {require Digest::MD5;1} ne 1) { + die("Can not load Perl module Digest::MD5.\n"); + } else { + Digest::MD5->import('md5_hex'); + } +} + # Rewrite some command line arguments as lists &compute_arg_list(); @@ -1722,6 +1733,7 @@ Options: mode. --log-duration : force pgbadger to associate log entries generated by both log_duration = on and log_statement = 'all' + --enable-checksum : used to add a md5 sum under each query report. pgBadger is able to parse a remote log file using a passwordless ssh connection. @@ -6873,6 +6885,8 @@ sub print_lock_queries_report my $max_time = &convert_time($top_locked_queries[$i]->[4]); my $avg_time = &convert_time($top_locked_queries[$i]->[2] / ($top_locked_queries[$i]->[1] || 1)); my $query = &highlight_code($top_locked_queries[$i]->[0]); + my $md5 = ''; + $md5 = 'md5: ' . md5_hex($top_locked_queries[$i]->[0]) if ($enable_checksum); my $k = $top_locked_queries[$i]->[0]; my $example = qq{

}; $example = '' if (scalar keys %{$normalyzed_info{$k}{samples}} <= 1); @@ -6885,7 +6899,7 @@ sub print_lock_queries_report $max_time $avg_time -
$query
+
$query
$md5 $example
@@ -6895,6 +6909,8 @@ sub print_lock_queries_report my $idx = 1; foreach my $d (sort {$b <=> $a} keys %{$normalyzed_info{$k}{samples}}) { $query = &highlight_code($normalyzed_info{$k}{samples}{$d}{query}); + $md5 = ''; + $md5 = 'md5: ' . md5_hex($normalyzed_info{$k}{samples}{$d}{query}) if ($enable_checksum); my $details = "[ Date: $normalyzed_info{$k}{samples}{$d}{date}"; $details .= " - Duration: " . &convert_time($d) if ($normalyzed_info{$k}{samples}{$d}{duration}); $details .= " - Database: $normalyzed_info{$k}{samples}{$d}{db}" if ($normalyzed_info{$k}{samples}{$d}{db}); @@ -6905,7 +6921,7 @@ sub print_lock_queries_report $details .= " ]"; print $fh qq{
-
$query
+
$query
$md5
$details
}; @@ -6955,6 +6971,8 @@ sub print_lock_queries_report $rank = 1; for (my $i = 0 ; $i <= $#top_locked_info ; $i++) { my $query = &highlight_code($top_locked_info[$i]->[2]); + my $md5 = ''; + $md5 = 'md5: ' . md5_hex($top_locked_info[$i]->[2]) if ($enable_checksum); my $details = "[ Date: " . ($top_locked_info[$i]->[1] || ''); $details .= " - Database: $top_locked_info[$i]->[3]" if ($top_locked_info[$i]->[3]); $details .= " - User: $top_locked_info[$i]->[4]" if ($top_locked_info[$i]->[4]); @@ -6968,7 +6986,7 @@ sub print_lock_queries_report $rank $time -
$query
+
$query
$md5
$details
@@ -7026,6 +7044,8 @@ sub print_tempfile_report my $max_size = &pretty_print_size($top_temporary[$i]->[4]); my $avg_size = &pretty_print_size($top_temporary[$i]->[2] / ($top_temporary[$i]->[1] || 1)); my $query = &highlight_code($top_temporary[$i]->[0]); + my $md5 = ''; + $md5 = 'md5: ' . md5_hex($top_temporary[$i]->[0]) if ($enable_checksum); my $example = qq{

}; $example = '' if (scalar keys %{$normalyzed_info{$top_temporary[$i]->[0]}{samples}} == 0); print $fh qq{ @@ -7037,7 +7057,7 @@ sub print_tempfile_report $max_size $avg_size -
$query
+
$query
$md5 $example
@@ -7048,6 +7068,8 @@ sub print_tempfile_report my $idx = 1; foreach my $d (sort {$b <=> $a} keys %{$normalyzed_info{$k}{samples}}) { $query = &highlight_code($normalyzed_info{$k}{samples}{$d}{query}); + my $md5 = ''; + $md5 = 'md5: ' . md5_hex($normalyzed_info{$k}{samples}{$d}{query}) if ($enable_checksum); my $details = "Duration: " . &convert_time($d) . "
"; $details .= "Database: $normalyzed_info{$k}{samples}{$d}{db}
" if ($normalyzed_info{$k}{samples}{$d}{db}); $details .= "User: $normalyzed_info{$k}{samples}{$d}{user}
" if ($normalyzed_info{$k}{samples}{$d}{user}); @@ -7056,7 +7078,7 @@ sub print_tempfile_report $details .= "Bind query: yes
" if ($normalyzed_info{$k}{samples}{$d}{bind}); print $fh qq{
-
$query
+
$query
$md5
$details
@@ -7114,12 +7136,14 @@ sub print_tempfile_report $details .= " - Bind yes: yes" if ($top_tempfile_info[$i]->[7]); $details .= " ]"; my $query = &highlight_code($top_tempfile_info[$i]->[2]); + my $md5 = ''; + $md5 = 'md5: ' . md5_hex($top_tempfile_info[$i]->[2]) if ($enable_checksum); print $fh qq{ $rank $size -
$query
+
$query
$md5
$details
@@ -7243,12 +7267,14 @@ sub print_slowest_individual_queries $details .= " - Bind query: yes" if ($top_slowest[$i]->[7]); $details .= " ]"; my $query = &highlight_code($top_slowest[$i]->[2]); + my $md5 = ''; + $md5 = 'md5: ' . md5_hex($top_slowest[$i]->[2]) if ($enable_checksum); print $fh qq{ $rank $duration -
$query
+
$query
$md5
$details
@@ -7301,6 +7327,8 @@ sub print_time_consuming my $max = &convert_time($normalyzed_info{$k}{max}); my $avg = &convert_time($normalyzed_info{$k}{average}); my $query = &highlight_code($k); + my $md5 = ''; + $md5 = 'md5: ' . md5_hex($k) if ($enable_checksum); my $details = ''; my %hourly_count = (); my %hourly_duration = (); @@ -7369,7 +7397,7 @@ sub print_time_consuming $max $avg -
$query
+
$query
$md5

Times Reported Time consuming queries #$rank

@@ -7435,9 +7463,11 @@ sub print_time_consuming $details .= " - Bind query: yes" if ($normalyzed_info{$k}{samples}{$d}{bind}); $details .= " ]"; $query = &highlight_code($normalyzed_info{$k}{samples}{$d}{query}); + my $md5 = ''; + $md5 = 'md5: ' . md5_hex($normalyzed_info{$k}{samples}{$d}{query}) if ($enable_checksum); print $fh qq{
-
$query
+
$query
$md5
$details
}; @@ -7496,6 +7526,8 @@ sub print_most_frequent my $max = &convert_time($normalyzed_info{$k}{max}); my $avg = &convert_time($normalyzed_info{$k}{average}); my $query = &highlight_code($k); + my $md5 = ''; + $md5 = 'md5: ' . md5_hex($k) if ($enable_checksum); my %hourly_count = (); my %hourly_duration = (); my $days = 0; @@ -7565,7 +7597,7 @@ sub print_most_frequent $max $avg -
$query
+
$query
$md5

Times Reported Time consuming queries #$rank

@@ -7632,9 +7664,11 @@ sub print_most_frequent $details .= " - Bind query: yes" if ($normalyzed_info{$k}{samples}{$d}{bind}); $details .= " ]"; $query = &highlight_code($normalyzed_info{$k}{samples}{$d}{query}); + my $md5 = ''; + $md5 = 'md5: ' . md5_hex($normalyzed_info{$k}{samples}{$d}{query}) if ($enable_checksum); print $fh qq{
-
$query
+
$query
$md5
$details
}; @@ -7696,6 +7730,8 @@ sub print_slowest_queries my $max = &convert_time($normalyzed_info{$k}{max}); my $avg = &convert_time($normalyzed_info{$k}{average}); my $query = &highlight_code($k); + my $md5 = ''; + $md5 = 'md5: ' . md5_hex($k) if ($enable_checksum); my $details = ''; my %hourly_count = (); my %hourly_duration = (); @@ -7766,7 +7802,7 @@ sub print_slowest_queries $duration -
$query
+
$query
$md5

Times Reported Time consuming queries #$rank

@@ -7833,9 +7869,11 @@ sub print_slowest_queries $details .= " - Bind query: yes" if ($normalyzed_info{$k}{samples}{$d}{bind}); $details .= " ]"; $query = &highlight_code($normalyzed_info{$k}{samples}{$d}{query}); + my $md5 = ''; + $md5 = 'md5: ' . md5_hex($normalyzed_info{$k}{samples}{$d}{query}) if ($enable_checksum); print $fh qq{
-
$query
+
$query
$md5
$details
};