From: Darold Gilles Date: Wed, 24 Oct 2012 12:12:14 +0000 (+0200) Subject: Add --include-query and --include-file to specify regx of the queries that must only... X-Git-Tag: v3.2~115 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fb5fef1ccc866ac54be218d10043258d8b2c2c4e;p=pgbadger Add --include-query and --include-file to specify regx of the queries that must only be included in the report. Thanks to Marc Cousin for the feature request. --- diff --git a/README b/README index 844069b..337faac 100644 --- a/README +++ b/README @@ -60,6 +60,11 @@ SYNOPSIS you can use this option multiple time. --exclude-file filename: path of the file which contains all the regex to use to exclude queries from the report. One regex per line. + --include-query regex : any query that do not match the given regex will be + excluded from the report. For example: "(table_1|table_2)" + you can use this option multiple time. + --include-file filename: path of the file which contains all the regex of the + queries to include from the report. One regex per line. --disable-error : do not generate error report. --disable-hourly : do not generate hourly reports. --disable-type : do not generate query type report. diff --git a/doc/pgBadger.pod b/doc/pgBadger.pod index 001a04d..efda275 100644 --- a/doc/pgBadger.pod +++ b/doc/pgBadger.pod @@ -62,6 +62,11 @@ Options: you can use this option multiple time. --exclude-file filename: path of the file which contains all the regex to use to exclude queries from the report. One regex per line. + --include-query regex : any query that do not match the given regex will be + excluded from the report. For example: "(table_1|table_2)" + you can use this option multiple time. + --include-file filename: path of the file which contains all the regex of the + queries to include from the report. One regex per line. --disable-error : do not generate error report. --disable-hourly : do not generate hourly reports. --disable-type : do not generate query type report. diff --git a/pgbadger b/pgbadger index 980c0ec..d656b54 100755 --- a/pgbadger +++ b/pgbadger @@ -74,6 +74,8 @@ my $progress = 1; my $error_only = 0; my @exclude_query = (); my $exclude_file = ''; +my @include_query = (); +my $include_file = ''; my $disable_error = 0; my $disable_hourly = 0; my $disable_type = 0; @@ -147,6 +149,8 @@ my $result = GetOptions( "image-format=s" => \$img_format, "exclude-query=s" => \@exclude_query, "exclude-file=s" => \$exclude_file, + "include-query=s" => \@exclude_query, + "include-file=s" => \$exclude_file, "disable-error!" => \$disable_error, "disable-hourly!" => \$disable_hourly, "disable-type!" => \$disable_type, @@ -289,6 +293,26 @@ if ($#exclude_query >= 0) { } } +# Loading included query from file if any +if ($include_file) { + open(IN, "$include_file") or die "FATAL: can't read file $include_file: $!\n"; + my @exclq = ; + close(IN); + chomp(@exclq); + map {s/ //;} @exclq; + foreach my $r (@exclq) { + &check_regex($r, '--include-file'); + } + push(@include_query, @exclq); +} + +# Testing regex syntaxe +if ($#include_query >= 0) { + foreach my $r (@include_query) { + &check_regex($r, '--include-query'); + } +} + my $other_syslog_line = qr/^(...)\s+(\d+)\s(\d+):(\d+):(\d+)\s([^\s]+)\s([^\[]+)\[(\d+)\]:\s\[(\d+)\-\d+\]\s*(.*)/; my $orphan_syslog_line = qr/^...\s+\d+\s\d+:\d+:\d+\s[^\s]+\s[^\[]+\[\d+\]:/; my $orphan_stderr_line = qr/[^']*\d+-\d+-\d+\s\d+:\d+:\d+[\.\d]*\s[^\s]+[^']*/; @@ -879,6 +903,11 @@ Options: you can use this option multiple time. --exclude-file filename: path of the file which contains all the regex to use to exclude queries from the report. One regex per line. + --include-query regex : any query that do not match the given regex will be + excluded from the report. For example: "(table_1|table_2)" + you can use this option multiple time. + --include-file filename: path of the file which contains all the regex of the + queries to include from the report. One regex per line. --disable-error : do not generate error report. --disable-hourly : do not generate hourly reports. --disable-type : do not generate query type report. @@ -3536,6 +3565,16 @@ sub store_queries } } + # Should we have to include only some queries + if ($#include_query >= 0) { + foreach (@include_query) { + if ($cur_info{$t_pid}{query} !~ /$_/i) { + $cur_info{$t_pid}{query} = ''; + return; + } + } + } + # Truncate the query if requested by the user $cur_info{$t_pid}{query} = substr($cur_info{$t_pid}{query}, 0, $maxlength) . '[...]' if (($maxlength > 0) && (length($cur_info{$t_pid}{query}) > $maxlength));