From f72afb9b7d90358f69b0036fc9ab9c90a0f5451f Mon Sep 17 00:00:00 2001 From: Greg Sabino Mullane Date: Thu, 11 Dec 2008 18:17:19 -0500 Subject: [PATCH] Add --noidle flag (Selena Deckelmann) Bump version to 2.5.1 --- check_postgres.pl | 25 ++++++++++++++++++------- check_postgres.pl.asc | 6 +++--- check_postgres.pl.html | 17 +++++++++++++---- index.html | 8 ++++---- 4 files changed, 38 insertions(+), 18 deletions(-) diff --git a/check_postgres.pl b/check_postgres.pl index adba69516..1a831ba62 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.5.0'; +our $VERSION = '2.5.1'; use vars qw/ %opt $PSQL $res $COM $SQL $db /; @@ -129,6 +129,7 @@ die $USAGE unless 'reverse', ## used by custom_query only 'repinfo=s', ## used by replicate_row only 'schema=s', ## used by fsm_* checks only + 'noidle', ## used by backends only ) and keys %opt and ! @ARGV; @@ -925,7 +926,7 @@ sub run_command { ## Don't set any default values if a service is being used - if (length $opt{dbservice}->[0]) { + if (defined $opt{dbservice} and length $opt{dbservice}->[0]) { $conn->{dbname} = []; $conn->{port} = []; $conn->{dbuser} = []; @@ -1624,6 +1625,7 @@ sub check_backends { my $warning = $opt{warning} || '90%'; my $critical = $opt{critical} || '95%'; + my $noidle = $opt{noidle} || 0; my $validre = qr{^(\-?)(\d+)(\%?)$}; if ($warning !~ $validre) { @@ -1646,7 +1648,9 @@ sub check_backends { } my $MAXSQL = q{SELECT setting FROM pg_settings WHERE name = 'max_connections'}; - $SQL = "SELECT COUNT(*), ($MAXSQL), datname FROM pg_stat_activity GROUP BY 2,3"; + my $NOIDLE = $noidle ? q{WHERE current_query <> ''} : ''; + my $GROUPBY = q{GROUP BY 2,3}; + $SQL = "SELECT COUNT(*), ($MAXSQL), datname FROM pg_stat_activity $NOIDLE $GROUPBY"; my $info = run_command($SQL, {regex => qr[\s*\d+ \| \d+\s+\|] } ); ## There may be no entries returned if we catch pg_stat_activity at the right @@ -3744,7 +3748,7 @@ sub show_dbstats { =head1 NAME B - a Postgres monitoring script for Nagios, MRTG, Cacti, and others -This documents describes check_postgres.pl version 2.5.0 +This documents describes check_postgres.pl version 2.5.1 =head1 SYNOPSIS @@ -4057,9 +4061,9 @@ given. This choice does not use the B setting. Second, the percentage of available connections can be given. Third, a negative number can be given which represents the number of connections left until B is reached. The default values for I<--warning> and I<--critical> are '90%' and '95%'. -You can also filter the databases by use of the -I<--include> and I<--exclude> options. See the L section -for more details. +You can also specify I<--noidle> to return a count of non-idle processes. +You can also filter the databases by use of the <--include> and I<--exclude> options. +See the L section for more details. Example 1: Give a warning when the number of connections on host quirm reaches 120, and a critical if it reaches 150. @@ -4970,6 +4974,13 @@ Items not specifically attributed are by Greg Sabino Mullane. =over 4 +=item B + + Add support for --noidle flag to prevent backends action from counting idle processes. + Patch by Selena Deckelmann. + + Fix small undefined warning when not using --dbservice. + =item B Add support for the pg_Service.conf file with the --dbservice option. diff --git a/check_postgres.pl.asc b/check_postgres.pl.asc index 2b7865c2e..82036ad61 100644 --- a/check_postgres.pl.asc +++ b/check_postgres.pl.asc @@ -1,6 +1,6 @@ -----BEGIN PGP SIGNATURE----- -iEYEABEDAAYFAkkUSswACgkQvJuQZxSWSsiXmwCg/h+pQ6XtaKgYXUBUQMg1r+1j -r3EAoNfqJ6npPLwZK167eLldICaVrXqC -=MB+t +iEYEABEDAAYFAklBn3MACgkQvJuQZxSWSsh+uQCfYBnecQ2pqKyHckTNEddpAUTE +q1wAnit4d7RDbxD6OhPGvTNWBIxWVpf7 +=CQ87 -----END PGP SIGNATURE----- diff --git a/check_postgres.pl.html b/check_postgres.pl.html index 9fe92ba6f..1b6c7681b 100644 --- a/check_postgres.pl.html +++ b/check_postgres.pl.html @@ -92,7 +92,7 @@

NAME

check_postgres.pl - a Postgres monitoring script for Nagios, MRTG, Cacti, and others -This documents describes check_postgres.pl version 2.5.0

+This documents describes check_postgres.pl version 2.5.1


@@ -417,9 +417,9 @@ given. This choice does not use the max_connections setting. Se percentage of available connections can be given. Third, a negative number can be given which represents the number of connections left until max_connections is reached. The default values for --warning and --critical are '90%' and '95%'. -You can also filter the databases by use of the ---include and --exclude options. See the BASIC FILTERING section -for more details.

+You can also specify --noidle to return a count of non-idle processes. +You can also filter the databases by use of the <--include> and --exclude options. +See the BASIC FILTERING section for more details.

Example 1: Give a warning when the number of connections on host quirm reaches 120, and a critical if it reaches 150.

   check_postgres_backends --host=quirm --warning=120 --critical=150
@@ -1213,6 +1213,15 @@ feature requests, and commit notices, send email to HISTORY

Items not specifically attributed are by Greg Sabino Mullane.

+
Version 2.5.1
+ +
+
+  Add support for --noidle flag to prevent backends action from counting idle processes.
+  Patch by Selena Deckelmann.
+
+  Fix small undefined warning when not using --dbservice.
+
Version 2.5.0
diff --git a/index.html b/index.html index 6b438698d..6fb4df343 100644 --- a/index.html +++ b/index.html @@ -21,14 +21,14 @@ h1 {

check_postgres.pl

-

check_postgres.pl 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 End Point Corporation and is BSD-licensed. The latest version is 2.5.0, and was released on December 04, 2008.

+

check_postgres.pl 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 End Point Corporation and is BSD-licensed. The latest version is 2.5.1, and was released on December 11, 2008.

The latest development version can be downloaded via git:

-- 2.39.5