diff options
author | Greg Sabino Mullane | 2009-05-11 15:29:30 +0000 |
---|---|---|
committer | Greg Sabino Mullane | 2009-05-11 15:29:30 +0000 |
commit | ba0deedf303f34a64cab2c7d88d48b8827ceb9f6 (patch) | |
tree | 6aecee1d36ff85833f49b4a8b793b7e5fd3da903 | |
parent | 37844aaae9cab070793c27fa88327a63d0eb425b (diff) |
Use statement_timeout in addition to alarm.
Per requests from many people.
-rw-r--r-- | MANIFEST | 1 | ||||
-rw-r--r-- | META.yml | 4 | ||||
-rw-r--r-- | Makefile.PL | 2 | ||||
-rwxr-xr-x | check_postgres.pl | 29 | ||||
-rw-r--r-- | check_postgres.pl.html | 17 | ||||
-rw-r--r-- | t/04_timeout.t | 27 |
6 files changed, 63 insertions, 17 deletions
@@ -47,6 +47,7 @@ t/02_txn_wraparound.t t/02_version.t t/02_wal_files.t t/03_translations.t +t/04_timeout.t t/99_cleanup.t t/99_perlcritic.t t/99_pod.t @@ -1,6 +1,6 @@ --- #YAML:1.0 name : check_postgres.pl -version : 2.8.0 +version : 2.8.1 abstract : Postgres monitoring script author: - Greg Sabino Mullane <[email protected]> @@ -30,7 +30,7 @@ recommends: provides: check_postgres: file : check_postgres.pl - version : 2.8.0 + version : 2.8.1 keywords: - Postgres diff --git a/Makefile.PL b/Makefile.PL index 39a80e6f7..031cf6839 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -6,7 +6,7 @@ use strict; use warnings; use 5.006001; -my $VERSION = '2.8.0'; +my $VERSION = '2.8.1'; if ($VERSION =~ /_/) { print "WARNING! This is a test version ($VERSION) and should not be used in production!\n"; diff --git a/check_postgres.pl b/check_postgres.pl index c351b1dc1..dabd3e8f1 100755 --- a/check_postgres.pl +++ b/check_postgres.pl @@ -29,7 +29,7 @@ $Data::Dumper::Varname = 'POSTGRES'; $Data::Dumper::Indent = 2; $Data::Dumper::Useqq = 1; -our $VERSION = '2.8.0'; +our $VERSION = '2.8.1'; use vars qw/ %opt $PSQL $res $COM $SQL $db /; @@ -506,7 +506,7 @@ our $nohost = 0; our $ERROR = ''; $opt{test} = 0; -$opt{timeout} = 10; +$opt{timeout} = 30; die $USAGE unless GetOptions( @@ -699,7 +699,7 @@ Other options: --PSQL=FILE location of the psql executable; avoid using if possible -v, --verbose verbosity level; can be used more than once to increase the level -h, --help display this help information - -t X, --timeout=X how long in seconds before we timeout. Defaults to 10 seconds. + -t X, --timeout=X how long in seconds before we timeout. Defaults to 30 seconds. --symlinks create named symlinks to the main program for each action Actions: @@ -1585,14 +1585,17 @@ sub run_command { } } - push @args, '-c', $string; - - $VERBOSE >= 3 and warn Dumper \@args; - local $SIG{ALRM} = sub { die 'Timed out' }; my $timeout = $arg->{timeout} || $opt{timeout}; + my $dbtimeout = $timeout * 1000; alarm 0; + $string = "BEGIN;SET statement_timeout=$dbtimeout;COMMIT;$string"; + + push @args, '-c', $string; + + $VERBOSE >= 3 and warn Dumper \@args; + my $start = $opt{showtime} ? [gettimeofday()] : 0; open my $oldstderr, '>&', \*STDERR or ndie msg('runcommand-nodupe'); open STDERR, '>', $errorfile or ndie msg('runcommand-noerr'); @@ -1608,7 +1611,7 @@ sub run_command { if ($err =~ /Timed out/) { ndie msg('runcommand-timeout', $timeout); } - else { + else {ndie $res; ndie msg('runcommand-err'); } } @@ -1631,6 +1634,10 @@ sub run_command { ndie "$db->{error}"; } + elsif ($db->{error} =~ /statement timeout/) { + ndie msg('runcommand-timeout', $timeout); + } + if (!$db->{ok} and !$arg->{failok} and !$arg->{noverify}) { ## Check if problem is due to backend being too old for this check @@ -4747,7 +4754,7 @@ sub show_dbstats { B<check_postgres.pl> - a Postgres monitoring script for Nagios, MRTG, Cacti, and others -This documents describes check_postgres.pl version 2.8.0 +This documents describes check_postgres.pl version 2.8.1 =head1 SYNOPSIS @@ -6092,6 +6099,10 @@ Items not specifically attributed are by Greg Sabino Mullane. =over 4 +=item B<Version 2.8.1> (May, 2009) + + Added timeout via statement_timeout in addition to perl alarm (Greg) + =item B<Version 2.8.0> (May 4, 2009) Added internationalization support (Greg) diff --git a/check_postgres.pl.html b/check_postgres.pl.html index 6fc2470ec..b0ece0659 100644 --- a/check_postgres.pl.html +++ b/check_postgres.pl.html @@ -96,7 +96,7 @@ <hr /> <h1><a name="name">NAME</a></h1> <p><strong>check_postgres.pl</strong> - a Postgres monitoring script for Nagios, MRTG, Cacti, and others</p> -<p>This documents describes check_postgres.pl version 2.8.0</p> +<p>This documents describes check_postgres.pl version 2.8.1</p> <p> </p> <hr /> @@ -1328,13 +1328,19 @@ 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_0"><strong>Version 2.8.0</strong> (May ??, 2009)</a></strong></dt> +<dt><strong><a name="item_1"><strong>Version 2.8.1</strong> (May, 2009)</a></strong></dt> + +<dd> +<pre> + Added timeout via statement_timeout in addition to perl alarm (Greg)</pre> +</dd> +<dt><strong><a name="item_0"><strong>Version 2.8.0</strong> (May 4, 2009)</a></strong></dt> <dd> <pre> Added internationalization support (Greg) Added the 'disabled_triggers' check (Greg) - Added the prepared_txns' check (Greg) + Added the 'prepared_txns' check (Greg) Added the 'new_version_cp' and 'new_version_pg' checks (Greg) French translations (Guillaume Lelarge) Make the backends search return ok if no matches due to inclusion rules, @@ -1350,7 +1356,8 @@ feature requests, and commit notices, send email to <a href="mailto:check_postgr Set stats to zero if we bail early due to USERWHERECLAUSE (Andras Fabian) Add additional items to dbstats output (Andras Fabian) Remove --schema option from the fsm_ checks. (Greg Mullane and Robert Treat) - Various fixes. (Jeff Boes) + Handle case when ENV{PGUSER} is set. (Andy Lester) + Many various fixes. (Jeff Boes) Fix --dbservice: check version and use ENV{PGSERVICE} for old versions (Cédric Villemain)</pre> </dd> <dt><strong><a name="item_3"><strong>Version 2.7.3</strong> (February 10, 2009)</a></strong></dt> @@ -1366,7 +1373,7 @@ feature requests, and commit notices, send email to <a href="mailto:check_postgr <pre> Fix to prevent multiple groupings if db arguments given.</pre> </dd> -<dt><strong><a name="item_1"><strong>Version 2.7.1</strong> (February 6, 2009)</a></strong></dt> +<dt><strong><strong>Version 2.7.1</strong> (February 6, 2009)</strong></dt> <dd> <pre> diff --git a/t/04_timeout.t b/t/04_timeout.t new file mode 100644 index 000000000..64e6857b0 --- /dev/null +++ b/t/04_timeout.t @@ -0,0 +1,27 @@ +#!perl + +## Test the timeout functionality + +use 5.006; +use strict; +use warnings; +use Data::Dumper; +use Test::More tests => 2; +use lib 't','.'; +use CP_Testing; + +use vars qw/$dbh $SQL $t $res/; + +my $cp = CP_Testing->new( {default_action => 'custom_query'} ); + +$dbh = $cp->test_database_handle(); + +$t=q{Setting the --timeout flag works as expected}; +$res = $cp->run('--query="SELECT pg_sleep(2)" -w 7 --timeout=1'); +like ($res, qr{Command timed out}, $t); + +$t=q{Setting the --timeout flag works as expected}; +$res = $cp->run('--query="SELECT pg_sleep(1)" -w 7 --timeout=2'); +like ($res, qr{Invalid format}, $t); + +exit; |