Minor tweaks to get to 2.3.10
authorGreg Sabino Mullane <[email protected]>
Fri, 24 Oct 2008 00:17:59 +0000 (20:17 -0400)
committerGreg Sabino Mullane <[email protected]>
Fri, 24 Oct 2008 00:17:59 +0000 (20:17 -0400)
check_postgres.pl
check_postgres.pl.asc
check_postgres.pl.html
index.html

index 39f2076e1b22ea80289373666d24dc315b336aa9..798292868e00284f791dcc1ece81f62f74f5a0f6 100755 (executable)
@@ -28,7 +28,7 @@ $Data::Dumper::Varname = 'POSTGRES';
 $Data::Dumper::Indent = 2;
 $Data::Dumper::Useqq = 1;
 
-our $VERSION = '2.3.9';
+our $VERSION = '2.3.10';
 
 use vars qw/ %opt $PSQL $res $COM $SQL $db /;
 
@@ -1327,6 +1327,7 @@ sub validate_range {
                                $type =~ /positive/ ? 'a positive' : 'an';
                }
                if (length $warning and length $critical and $warning > $critical) {
+                       return if $opt{reverse};
                        ndie qq{The 'warning' option cannot be greater than the 'critical' option\n};
                }
        }
@@ -1665,12 +1666,12 @@ SELECT
   ROUND(CASE WHEN otta=0 THEN 0.0 ELSE sml.relpages/otta::numeric END,1) AS tbloat,
   CASE WHEN relpages < otta THEN 0 ELSE relpages::bigint - otta END AS wastedpages,
   CASE WHEN relpages < otta THEN 0 ELSE bs*(sml.relpages-otta)::bigint END AS wastedbytes,
-  CASE WHEN relpages < otta THEN pg_size_pretty(0) ELSE pg_size_pretty((bs*(relpages-otta))::bigint) END AS wastedsize,
+  CASE WHEN relpages < otta THEN '0 bytes'::text ELSE (bs*(relpages-otta))::bigint || ' bytes' END AS wastedsize,
   iname, ituples::bigint, ipages::bigint, iotta,
   ROUND(CASE WHEN iotta=0 OR ipages=0 THEN 0.0 ELSE ipages/iotta::numeric END,1) AS ibloat,
   CASE WHEN ipages < iotta THEN 0 ELSE ipages::bigint - iotta END AS wastedipages,
   CASE WHEN ipages < iotta THEN 0 ELSE bs*(ipages-iotta) END AS wastedibytes,
-  CASE WHEN ipages < iotta THEN pg_size_pretty(0) ELSE pg_size_pretty((bs*(ipages-iotta))::bigint) END AS wastedisize
+  CASE WHEN ipages < iotta THEN '0 bytes' ELSE (bs*(ipages-iotta))::bigint || ' bytes' END AS wastedisize
 FROM (
   SELECT
     schemaname, tablename, cc.reltuples, cc.relpages, bs,
@@ -1712,9 +1713,7 @@ WHERE sml.relpages - otta > $MINPAGES OR ipages - iotta > $MINIPAGES
 ORDER BY wastedbytes DESC LIMIT $LIMIT
 };
 
-       (my $SQL2 = $SQL) =~ s/pg_size_pretty\((.+?)\) /$1 || ' bytes' /g;
-
-       my $info = run_command($SQL, { version => {'8.0' => $SQL2}});
+       my $info = run_command($SQL);
 
        if (defined $info->{db}[0] and exists $info->{db}[0]{error}) {
                ndie $info->{db}[0]{error};
@@ -1732,10 +1731,7 @@ ORDER BY wastedbytes DESC LIMIT $LIMIT
                        next;
                }
 
-               ## 8.0 does not have pg_size_pretty, so we'll do it ourselves
-               if ($db->{version} eq '8.0') {
-                       $db->{slurp} =~ s/\| (\d+) bytes/'| ' . pretty_size($1,1)/ge;
-               }
+               $db->{slurp} =~ s/\| (\d+) bytes/'| ' . pretty_size($1,1)/ge;
                my $max = -1;
                my $maxmsg = '?';
          SLURP: for (split /\n/o => $db->{slurp}) {
@@ -3538,6 +3534,7 @@ sub check_sequence {
                my (@crit,@warn,@ok);
                my $maxp = 0;
                my %seqinfo;
+               my %seqperf;
                my $multidb = @{$info->{db}} > 1 ? "$db->{dbname}." : '';
          SLURP: while ($db->{slurp} =~ /\s*(.+?)\s+\| (.+?)\s+\| (.+?)\s*$/gsm) {
                        my ($schema, $seq, $seqname) = ($1,$2,$3);
@@ -3551,13 +3548,13 @@ sub check_sequence {
                        }
                        my ($last, $slots, $used, $percent, $left) = ($1,$2,$3,$4,$5);
                        my $msg = "$seqname=$percent\% (calls left=$left)";
+                       $seqperf{$percent}{$seqname} = [$left, " $multidb$seqname=$percent|$slots|$used|$left"];
                        if ($percent >= $maxp) {
                                $maxp = $percent;
                                push @{$seqinfo{$percent}} => $MRTG ? [$seqname,$percent,$slots,$used,$left] : $msg;
                        }
                        next if $MRTG;
 
-                       $db->{perf} .= " $multidb$seqname=$percent|$slots|$used|$left";
                        if (length $critical and $percent >= $c) {
                                push @crit => $msg;
                        }
@@ -3569,6 +3566,14 @@ sub check_sequence {
                        my $msg = join ' | ' => map { $_->[0] } @{$seqinfo{$maxp}};
                        do_mrtg({one => $maxp, msg => $msg});
                }
+               my $limit = 0;
+         PERF: for my $val (sort { $b <=> $a } keys %seqperf) {
+                       for my $seq (sort { $seqperf{$val}{$a}->[0] <=> $seqperf{$val}{$b}->[0] or $a cmp $b } keys %{$seqperf{$val}}) {
+                               last PERF if exists $opt{perflimit} and $limit++ >= $opt{perflimit};
+                               $db->{perf} .= $seqperf{$val}{$seq}->[1];
+                       }
+               }
+
                if (@crit) {
                        add_critical join ' ' => @crit;
                }
@@ -3595,7 +3600,7 @@ sub check_sequence {
 =head1 NAME
 
 B<check_postgres.pl> - a Postgres monitoring script for Nagios, MRTG, and others
-This documents describes check_postgres.pl version 2.3.9
+This documents describes check_postgres.pl version 2.3.10
 
 =head1 SYNOPSIS
 
@@ -4739,6 +4744,12 @@ Items not specifically attributed are by Greg Sabino Mullane.
 
 =over 4
 
+=item B<Version 2.3.10>
+
+ Fix minor warning in action check_bloat with multiple databases.
+ Allow warning to be greater than critical when using the --reverse option.
+ Support the --perflimit option for the check_sequence action.
+
 =item B<Version 2.3.9>
 
  Minor tweak to way we store the default port.
index 69d1501bed30c8a1590e8bcf852876c6a3509bca..03457801ba6edfcc76c0fae15b6c495124d291be 100644 (file)
@@ -1,6 +1,6 @@
 -----BEGIN PGP SIGNATURE-----
 
-iEYEABEDAAYFAkkA55oACgkQvJuQZxSWSshliwCgp5aeU5Sr3S+J7hNXa1H39rY8
-/5kAoJMd3TUKzKqx1eCzl8qz3bJWt6vI
-=3ThO
+iEYEABEDAAYFAkkBFAUACgkQvJuQZxSWSsi+vQCgtCrFcTN8cNaSP7P3E0cXT+3y
+UGwAoN0MOBvvy824q0cKPhfADAZoobcF
+=eG9F
 -----END PGP SIGNATURE-----
index c9cba991d36ad9e1a7d3a04515292f9fdab62caa..f02c09f5b3af13269cb2470d912e466ee487ea95 100644 (file)
@@ -90,7 +90,7 @@
 <hr />
 <h1><a name="name">NAME</a></h1>
 <p><strong>check_postgres.pl</strong> - a Postgres monitoring script for Nagios, MRTG, and others
-This documents describes check_postgres.pl version 2.3.9</p>
+This documents describes check_postgres.pl version 2.3.10</p>
 <p>
 </p>
 <hr />
@@ -1122,6 +1122,14 @@ feature requests, and commit notices, send email to <a href="mailto:check_postgr
 <h1><a name="history">HISTORY</a></h1>
 <p>Items not specifically attributed are by Greg Sabino Mullane.</p>
 <dl>
+<dt><strong><a name="item_version_2_2e3_2e10"><strong>Version 2.3.10</strong></a></strong></dt>
+
+<dd>
+<pre>
+ Fix minor warning in action check_bloat with multiple databases.
+ Allow warning to be greater than critical when using the --reverse option.
+ Support the --perflimit option for the check_sequence action.</pre>
+</dd>
 <dt><strong><a name="item_version_2_2e3_2e9"><strong>Version 2.3.9</strong></a></strong></dt>
 
 <dd>
index 773ff8725882ec74aaf7f73b7e15d1314c183788..4b5b8b48ad10f158d4a9eec0e528e5061f8229cc 100644 (file)
@@ -21,14 +21,14 @@ h1 {
 
 <h1>check_postgres.pl</h1>
 
-<p><b>check_postgres.pl</b> is a script for checking the state of one or more Postgres databases and reporting back in a Nagios-friendly manner. It was developed by Greg Sabino Mullane of <a href="http://www.endpoint.com/">End Point Corporation</a> and is BSD-licensed. The latest version is <b>2.3.9</b>, and was released on October 23, 2008.</p>
+<p><b>check_postgres.pl</b> is a script for checking the state of one or more Postgres databases and reporting back in a Nagios-friendly manner. It was developed by Greg Sabino Mullane of <a href="http://www.endpoint.com/">End Point Corporation</a> and is BSD-licensed. The latest version is <b>2.3.10</b>, and was released on October 23, 2008.</p>
 
 <ul>
- <li><a href="/check_postgres/check_postgres.pl.html">Documentation for check_postgres 2.3.9</a></li>
+ <li><a href="/check_postgres/check_postgres.pl.html">Documentation for check_postgres 2.3.10</a></li>
 </ul>
 <ul>
- <li><a href="/check_postgres/check_postgres.pl">Download check_postgres.pl 2.3.9</a></li>
- <li><a href="/check_postgres/check_postgres.pl.asc">PGP signature for check_postgres.pl 2.3.9</a></li>
+ <li><a href="/check_postgres/check_postgres.pl">Download check_postgres.pl 2.3.10</a></li>
+ <li><a href="/check_postgres/check_postgres.pl.asc">PGP signature for check_postgres.pl 2.3.10</a></li>
 </ul>
 
 <p>The latest development version can be downloaded via git:</p>