]> granicus.if.org Git - pgbadger/commitdiff
Add --exclude-query option to exclude types of queries by specifying a regex - Isaac...
authorDarold <gilles@darold.net>
Sat, 23 Jun 2012 08:55:00 +0000 (10:55 +0200)
committerDarold <gilles@darold.net>
Sat, 23 Jun 2012 08:55:00 +0000 (10:55 +0200)
README
doc/pgBadger.pod
pgbadger

diff --git a/README b/README
index ab498267af4d7c6fe02ce8c987104f26e23af94c..f515dac1ce9a6a5dd8fdf4127760c53298295824 100644 (file)
--- a/README
+++ b/README
@@ -41,12 +41,16 @@ SYNOPSIS
         -v | --version         : show current version
         --pie-limit num        : do not show pie data lower that num%, show a sum of them instead.
         -w | -watch-mode       : only report errors just like logwatch could do.
+        --exclude-query regex  : any query matching the given regex will be excluded
+                                 from the report. For example: "^(COPY|VACUUM|COMMIT)"
+                                 you can use this option multiple time.
 
     Examples:
 
             pgbadger -p -g /var/log/postgresql.log
             pgbadger -p -g /var/log/postgres.log.2.gz /var/log/postgres.log.1.gz /var/log/postgres.log
             pgbadger -p -g `ls /var/log/postgresql/postgresql-2012-05-*`
+            pgbadger -p -g --exclude-query="^(COPY|VACUUM|COMMIT)" /var/log/postgresql.log
 
     Reporting errors every week by cron job:
 
index 64fc56789c85bbaa71599f3b3faa744b4f101dc9..c27eff2823fc59f0a9917eaaef3cf6821b6ce361 100644 (file)
@@ -43,12 +43,17 @@ Options:
     -v | --version         : show current version
     --pie-limit num        : do not show pie data lower that num%, show a sum of them instead.
     -w | -watch-mode       : only report errors just like logwatch could do.
+    --exclude-query regex  : any query matching the given regex will be excluded
+                             from the report. For example: "^(COPY|VACUUM|COMMIT)"
+                             you can use this option multiple time.
 
 Examples:
 
         pgbadger -p -g /var/log/postgresql.log
         pgbadger -p -g /var/log/postgres.log.2.gz /var/log/postgres.log.1.gz /var/log/postgres.log
         pgbadger -p -g `ls /var/log/postgresql/postgresql-2012-05-*`
+       pgbadger -p -g --exclude-query="^(COPY|VACUUM|COMMIT)" /var/log/postgresql.log
+
 
 Reporting errors every week by cron job:
 
index 78d2fc15d9075748537904a21a0f832b3dedcdea..40619e1202058cf4d3092c47ae612764729a630b 100755 (executable)
--- a/pgbadger
+++ b/pgbadger
@@ -64,6 +64,7 @@ my $regex_prefix_dbuser = '';
 my $quiet = 0;
 my $progress = 0;
 my $error_only = 0;
+my @exclude_query = ();
 
 my $NUMPROGRESS = 10000;
 my @DIMENSIONS = (800,300);
@@ -107,6 +108,7 @@ my $result = GetOptions (
        "pie-limit=i"   => \$pie_percentage_limit,
        "image-format=s"=> \$img_format,
        "w|watch-mode!" => \$error_only,
+       "exclude-query=s" => \@exclude_query,
 );
 
 if ($ver) {
@@ -187,6 +189,15 @@ if (not defined $tmpfh) {
 $tmpfh->close();
 unlink($outfile) if (-e $outfile);
 
+# Testing regex syntaxe
+if ($#exclude_query >= 0) {
+       foreach my $r (@exclude_query) {
+               eval { m/$r/i; };
+               if ($@) {
+                       die "FATAL: invalid regex '$r', $!\n";
+               }
+       }
+}
 # Check start/end date time
 if ($from) {
        if ($from =~ /^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/) {
@@ -500,6 +511,9 @@ Options:
                             enabled with this option.
     --pie-limit num        : pie data lower than num% will show a sum instead.
     -w | -watch-mode       : only report errors just like logwatch could do.
+    --exclude-query regex  : any query matching the given regex will be excluded
+                            from the report. For example: "^(COPY|VACUUM|COMMIT)"
+                            you can use this option multiple time.
 
 Examples:
 
@@ -507,6 +521,7 @@ Examples:
        pgbadger -p -g /var/log/postgres.log.2.gz /var/log/postgres.log.1.gz \
                       /var/log/postgres.log
        pgbadger -p -g `ls /var/log/postgresql/postgresql-2012-05-*`
+       pgbadger -p -g --exclude-query="^(COPY|VACUUM|COMMIT)" /var/log/postgresql.log
 
 Reporting errors every week by cron job:
 
@@ -2521,8 +2536,19 @@ sub parse_query
                        # Cleanup and normalize the current query
                        $cur_info{query} =~ s/^[\t\s]+//s;
                        $cur_info{query} =~ s/[\t\s]+$//s;
+                       # Should we have to exclude some queries
+                       if ($#exclude_query >= 0) {
+                               foreach (@exclude_query) {
+                                       if ($cur_info{query} =~ /$_/i) {
+                                               $cur_info{query} = '';
+                                               return;
+                                       }
+                               }
+                       }
                        $cur_info{query} = substr($cur_info{query}, 0, $maxlength) . '[...]' if (($maxlength > 0) && (length($cur_info{query}) > $maxlength));
                        $cur_info{query} .= ';' if (substr($cur_info{query}, -1, 1) ne ';');
+
+
                        my $normalized = &normalize_query($cur_info{query});
 
                        # Stores global statistics