From: Greg Sabino Mullane <greg@endpoint.com> Date: Fri, 24 Oct 2008 00:17:59 +0000 (-0400) Subject: Minor tweaks to get to 2.3.10 X-Git-Tag: 2.9.0~214 X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=800c4d5c45d963801e7953bede1960a9c2b7120b;p=check_postgres.git Minor tweaks to get to 2.3.10 --- diff --git a/check_postgres.pl b/check_postgres.pl index 39f2076e1..798292868 100755 --- a/check_postgres.pl +++ b/check_postgres.pl @@ -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. diff --git a/check_postgres.pl.asc b/check_postgres.pl.asc index 69d1501be..03457801b 100644 --- a/check_postgres.pl.asc +++ b/check_postgres.pl.asc @@ -1,6 +1,6 @@ -----BEGIN PGP SIGNATURE----- -iEYEABEDAAYFAkkA55oACgkQvJuQZxSWSshliwCgp5aeU5Sr3S+J7hNXa1H39rY8 -/5kAoJMd3TUKzKqx1eCzl8qz3bJWt6vI -=3ThO +iEYEABEDAAYFAkkBFAUACgkQvJuQZxSWSsi+vQCgtCrFcTN8cNaSP7P3E0cXT+3y +UGwAoN0MOBvvy824q0cKPhfADAZoobcF +=eG9F -----END PGP SIGNATURE----- diff --git a/check_postgres.pl.html b/check_postgres.pl.html index c9cba991d..f02c09f5b 100644 --- a/check_postgres.pl.html +++ b/check_postgres.pl.html @@ -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> diff --git a/index.html b/index.html index 773ff8725..4b5b8b48a 100644 --- a/index.html +++ b/index.html @@ -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="/https/git.postgresql.org/check_postgres/check_postgres.pl.html">Documentation for check_postgres 2.3.9</a></li> + <li><a href="/https/git.postgresql.org/check_postgres/check_postgres.pl.html">Documentation for check_postgres 2.3.10</a></li> </ul> <ul> - <li><a href="/https/git.postgresql.org/check_postgres/check_postgres.pl">Download check_postgres.pl 2.3.9</a></li> - <li><a href="/https/git.postgresql.org/check_postgres/check_postgres.pl.asc">PGP signature for check_postgres.pl 2.3.9</a></li> + <li><a href="/https/git.postgresql.org/check_postgres/check_postgres.pl">Download check_postgres.pl 2.3.10</a></li> + <li><a href="/https/git.postgresql.org/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>