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 /check_postgres.pl | |
parent | 37844aaae9cab070793c27fa88327a63d0eb425b (diff) |
Use statement_timeout in addition to alarm.
Per requests from many people.
Diffstat (limited to 'check_postgres.pl')
-rwxr-xr-x | check_postgres.pl | 29 |
1 files changed, 20 insertions, 9 deletions
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) |