]> granicus.if.org Git - pgbadger/commitdiff
Add --include-query and --include-file to specify regx of the queries that must only...
authorDarold Gilles <gilles@darold.net>
Wed, 24 Oct 2012 12:12:14 +0000 (14:12 +0200)
committerDarold Gilles <gilles@darold.net>
Wed, 24 Oct 2012 12:12:14 +0000 (14:12 +0200)
README
doc/pgBadger.pod
pgbadger

diff --git a/README b/README
index 844069b4c7d80535a9ed074fb65f03f329ccce3b..337faac6002671c6b3bf75b7c0428a3e0f7ec4b4 100644 (file)
--- 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.
index 001a04db08982536ca77a12573b05237aea96133..efda275b13ba618efe7d681f898ceaefbaf007db 100644 (file)
@@ -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.
index 980c0ecc4a83e42c630e3678013848f4088f59ec..d656b5431eee5e945a1797e075149999b92e172e 100755 (executable)
--- 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 = <IN>;
+       close(IN);
+       chomp(@exclq);
+       map {s/\r//;} @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));