[check_postgres] [commit] Add two new actions from Robert Treat: fsm_pages and fsm_relations.

check_postgres at bucardo.org check_postgres at bucardo.org
Thu Sep 25 22:26:51 UTC 2008


Committed by Greg Sabino Mullane <greg at endpoint.com>

Add two new actions from Robert Treat: fsm_pages and fsm_relations.
Bump version to 2.2.0

---
 .perlcriticrc          |    2 +-
 check_postgres.pl      |  160 ++++++++++++++++++++++++++++++++++++++++++++++-
 check_postgres.pl.html |   49 +++++++++++++--
 index.html             |    6 +-
 t/99_spellcheck.t      |    6 ++
 5 files changed, 210 insertions(+), 13 deletions(-)

diff --git a/.perlcriticrc b/.perlcriticrc
index 98f0b82..8c42758 100644
--- a/.perlcriticrc
+++ b/.perlcriticrc
@@ -4,7 +4,7 @@ verbose = 8
 severity = 1
 
 [Documentation::PodSpelling]
-stop_words = Mullane Nagios Slony nols salesrep psql dbname postgres USERNAME usernames dbuser pgpass nagios stderr showperf symlinked timesync criticals quirm lancre exabytes sami includeuser excludeuser flagg tardis WAL tablespaces tablespace perflimit burrick mallory grimm oskar ExclusiveLock garrett artemus queryname speedtest checksum checksums morpork klatch pluto faceoff slon greg watson franklin wilkins scott Sabino Seklecki dbpass autovacuum Astill refactoring NAGIOS localhost cronjob symlink symlinks backends snazzo logfile syslog parens plugin Cwd Ioannis Tambouras schemas SQL MRTG mrtg uptime datallowconn dbhost dbport ok
+stop_words = Mullane Nagios Slony nols salesrep psql dbname postgres USERNAME usernames dbuser pgpass nagios stderr showperf symlinked timesync criticals quirm lancre exabytes sami includeuser excludeuser flagg tardis WAL tablespaces tablespace perflimit burrick mallory grimm oskar ExclusiveLock garrett artemus queryname speedtest checksum checksums morpork klatch pluto faceoff slon greg watson franklin wilkins scott Sabino Seklecki dbpass autovacuum Astill refactoring NAGIOS localhost cronjob symlink symlinks backends snazzo logfile syslog parens plugin Cwd Ioannis Tambouras schemas SQL MRTG mrtg uptime datallowconn dbhost dbport ok contrib pageslots robert dylan emma fsm
 
 ## Severity 5:
 [-Subroutines::ProhibitNestedSubs]
diff --git a/check_postgres.pl b/check_postgres.pl
index 3e32dcb..4cc3329 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.1.5';
+our $VERSION = '2.2.0';
 
 use vars qw/ %opt $PSQL $res $COM $SQL $db /;
 
@@ -123,6 +123,7 @@ die $USAGE unless
 			   'checktype=s', ## used by custom_query only
 			   'reverse',     ## used by custom_query only
 			   'repinfo=s',   ## used by replicate_row only
+			   'schema=s',    ## used by fsm_* checks only
 			   )
 	and keys %opt
 	and ! @ARGV;
@@ -185,6 +186,8 @@ our $action_info = {
  custom_query        => [0, 'Run a custom query.'],
  database_size       => [0, 'Report if a database is too big.'],
  disk_space          => [1, 'Checks space of local disks Postgres is using.'],
+ fsm_pages           => [1, 'Checks percentage of pages used in free space map.'],
+ fsm_relations       => [1, 'Checks percentage of relations used in free space map.'],
  index_size          => [0, 'Checks the size of indexes only.'],
  table_size          => [0, 'Checks the size of tables only.'],
  relation_size       => [0, 'Checks the size of tables and indexes.'],
@@ -497,6 +500,8 @@ our %testaction = (
 				  txn_idle         => 'ON: stats_command_string(<8.3) VERSION: 8.0',
 				  txn_time         => 'VERSION: 8.3',
 				  wal_files        => 'VERSION: 8.1',
+				  fsm_pages        => 'VERSION: 8.2',
+				  fsm_relations    => 'VERSION: 8.2',
 );
 if ($opt{test}) {
 	print "BEGIN TEST MODE\n";
@@ -679,6 +684,12 @@ check_replicate_row() if $action eq 'replicate_row';
 ## See how close we are to autovacuum_freeze_max_age
 check_autovac_freeze() if $action eq 'autovac_freeze';
 
+## See how many pages we have used up compared to max_fsm_pages
+check_fsm_pages() if $action eq 'fsm_pages';
+
+## See how many relations we have used up compared to max_fsm_relations
+check_fsm_relations() if $action eq 'fsm_relations';
+
 finishup();
 
 exit 0;
@@ -2032,6 +2043,110 @@ sub check_disk_space {
 } ## end of check_disk_space
 
 
+sub check_fsm_pages {
+
+	## Check on the percentage of free space map pages in use
+	## Supports: Nagios
+	## Must run as superuser
+	## Requires pg_freespacemap contrib module
+	## Takes an optional --schema argument, defaults to 'public'
+	## Critical and warning are a percentage of max_fsm_pages
+	## Example: --critical=95
+
+	my ($warning, $critical) = validate_range
+		({
+		  type              => 'percent',
+		  default_warning   => '85%',
+		  default_critical  => '95%',
+		  });
+
+    my $schema = ($opt{schema}) ? $opt{schema} : 'public';
+
+	(my $w = $warning) =~ s/\D//;
+	(my $c = $critical) =~ s/\D//;
+	my $SQL = qq{SELECT pages, maxx, ROUND(100*(pages/maxx)) AS percent\n}.
+	 		  qq{FROM (SELECT\n}.
+			  qq{ (SUM(GREATEST(interestingpages,storedpages))+COUNT(DISTINCT(relfilenode)))*8 AS pages,\n}.
+			  qq{ (SELECT setting::NUMERIC FROM pg_settings WHERE name = 'max_fsm_pages') AS maxx\n}.
+			  qq{ FROM $schema.pg_freespacemap_relations) x};
+
+	my $info = run_command($SQL, {regex => qr[\w+] } );
+
+	for $db (@{$info->{db}}) {
+	  SLURP: while ($db->{slurp} =~ /\s*(\d+) \|\s+(\d+) \|\s+(\d+)$/gsm) {
+			my ($pages,$max,$percent) = ($1,$2,$3);
+
+			my $msg = "fsm page slots used: $pages of $max ($percent%)";
+			if (length $critical and $percent >= $c) {
+				add_critical $msg;
+			}
+			elsif (length $warning and $percent >= $w) {
+				add_warning $msg;
+			}
+			else {
+				add_ok $msg;
+			}
+		}
+
+	}
+
+	return;
+
+} ## end of check_fsm_pages
+
+
+sub check_fsm_relations {
+
+	## Check on the % of free space map relations in use
+	## Supports: Nagios
+	## Must run as superuser
+	## Requires pg_freespacemap contrib module
+	## Takes an optional --schema argument, defaults to 'public'
+	## Critical and warning are a percentage of max_fsm_relations
+	## Example: --critical=95
+
+	my ($warning, $critical) = validate_range
+		({
+		  type              => 'percent',
+		  default_warning   => '85%',
+		  default_critical  => '95%',
+		  });
+
+    my $schema = ($opt{schema}) ? $opt{schema} : 'public';
+
+	(my $w = $warning) =~ s/\D//;
+	(my $c = $critical) =~ s/\D//;
+
+	my $SQL = qq{SELECT maxx, cur, ROUND(100*(cur/maxx))\n}.
+			  qq{FROM (SELECT\n}.
+			  qq{ (SELECT COUNT(*) FROM $schema.pg_freespacemap_relations) AS cur,\n}.
+			  qq{ (SELECT setting::NUMERIC FROM pg_settings WHERE name='max_fsm_relations') AS maxx) x\n};
+
+	my $info = run_command($SQL, {regex => qr[\w+] } );
+
+	for $db (@{$info->{db}}) {
+	  SLURP: while ($db->{slurp} =~ /\s*(\d+) \|\s+(\d+) \|\s+(\d+)$/gsm) {
+			my ($max,$cur,$percent) = ($1,$2,$3);
+
+			my $msg = "fsm relations used: $cur of $max ($percent%)";
+			if (length $critical and $percent >= $c) {
+				add_critical $msg;
+			}
+			elsif (length $warning and $percent >= $w) {
+				add_warning $msg;
+			}
+			else {
+				add_ok $msg;
+			}
+		}
+
+	}
+
+	return;
+
+} ## end of check_fsm_relations
+
+
 sub check_wal_files {
 
 	## Check on the number of WAL files in use
@@ -2723,9 +2838,11 @@ sub check_txn_time {
 
 	my $found = 0;
 	for $db (@{$info->{db}}) {
+
 		if (!exists $db->{ok}) {
 			ndie 'Query failed';
 		}
+
 		if ($db->{slurp} !~ /\w/ and $USERWHERECLAUSE) {
 			add_ok 'T-EXCLUDE-USEROK';
 			next;
@@ -3294,7 +3411,7 @@ sub check_replicate_row {
 =head1 NAME
 
 B<check_postgres.pl> - a Postgres monitoring script for Nagios, MRTG, and others
-This documents describes check_postgres.pl version 2.1.5
+This documents describes check_postgres.pl version 2.2.0
 
 =head1 SYNOPSIS
 
@@ -3790,6 +3907,41 @@ Example 2: Check that all file systems starting with /dev/sda are smaller than 1
 For MRTG output, returns the size in bytes of the file system on the first line, 
 and the name of the file system on the fourth line.
 
+=head2 B<fsm_pages>
+
+(C<symlink: check_postgres_fsm_pages>) Checks how close a cluster is to the Postgres B<max_fsm_pages> setting.
+This action will only work for databases of 8.2 or higher, and it requires the contrib
+module B<pg_freespacemap> be installed. The I<--warning> and I<--critical> options should be expressed
+as percentages. The number of used pages in the free-space-map is determined by looking in the
+pg_freespacemap_relations view, and running a formula based on the formula used for
+outputting free-space-map pageslots in the vacuum verbose command. The default values are B<85%> for the 
+warning and B<95%> for the critical.
+
+Example 1: Give a warning when our cluster has used up 76% of the free-space pageslots, with pg_freespacemap installed in database robert 
+
+  check_postgres_autovac_freeze --dbname=robert --warning="76%"
+
+While you need to pass in the name of the database where pg_freespacemap is installed (and optionally a schema name if you have
+installed the module in a non-standard schema), you only need to run this check once per cluster. Also, checking this information
+does require obtaining special locks on the free-space-map, so it is recommend you do not run this check with short intervals.
+
+=head2 B<fsm_relations>
+
+(C<symlink: check_postgres_fsm_relations>) Checks how close a cluster is to the Postgres B<max_fsm_relations> setting. 
+This action will only work for databases of 8.2 or higher, and it requires the contrib module B<pg_freespacemap> be 
+installed. The I<--warning> and I<--critical> options should be expressed as percentages. The number of used relations 
+in the free-space-map is determined by looking in the pg_freespacemap_relations view. The default values are B<85%> for 
+the warning and B<95%> for the critical.
+
+Example 1: Give a warning when our cluster has used up 80% of the free-space relations, with pg_freespacemap installed in database dylan, in non-standard schema emma
+
+  check_postgres_autovac_freeze --dbname=dylan --warning="75%" --schema=emma
+
+While you need to pass in the name of the database where pg_freespacemap is installed (and optionally a schema name
+if you have installed the module in a non-standard schema), you only need to run this check once per cluster. Also,
+checking this information does require obtaining special locks on the free-space-map, so it is recommend you do not
+run this check with short intervals.
+
 =head2 B<index_size>
 
 =head2 B<table_size>
@@ -4366,9 +4518,9 @@ Items not specifically attributed are by Greg Sabino Mullane.
 
 =over 4
 
-=item B<Version 2.1.5> (September 23, 2008)
+=item B<Version 2.2.0> (September 2008)
 
- Don't use STDERR bareword. (Chris Butler)
+ Add fsm_pages and fsm_relations actions. (Robert Treat)
 
 =item B<Version 2.1.4> (September 22, 2008)
 
diff --git a/check_postgres.pl.html b/check_postgres.pl.html
index 550b668..f298219 100644
--- a/check_postgres.pl.html
+++ b/check_postgres.pl.html
@@ -42,6 +42,8 @@
 		<li><a href="#custom_query"><strong>custom_query</strong></a></li>
 		<li><a href="#database_size"><strong>database_size</strong></a></li>
 		<li><a href="#disk_space"><strong>disk_space</strong></a></li>
+		<li><a href="#fsm_pages"><strong>fsm_pages</strong></a></li>
+		<li><a href="#fsm_relations"><strong>fsm_relations</strong></a></li>
 		<li><a href="#index_size"><strong>index_size</strong></a></li>
 		<li><a href="#table_size"><strong>table_size</strong></a></li>
 		<li><a href="#relation_size"><strong>relation_size</strong></a></li>
@@ -87,7 +89,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.1.4</p>
+This documents describes check_postgres.pl version 2.2.0</p>
 <p>
 </p>
 <hr />
@@ -395,7 +397,7 @@ is reached. The default values for <em>--warning</em> and <em>--critical</em> ar
 You can also filter the databases by use of the 
 <em>--include</em> and <em>--exclude</em> options. See the <a href="#basic_filtering">BASIC FILTERING</a> section 
 for more details.</p>
-<p>Example 1: Give a warning when the number of connections on host quirm reaches 120, and a critical if it reaches 140.</p>
+<p>Example 1: Give a warning when the number of connections on host quirm reaches 120, and a critical if it reaches 150.</p>
 <pre>
   check_postgres_backends --host=quirm --warning=120 --critical=150</pre>
 <p>Example 2: Give a critical when we reach 75% of our max_connections setting on hosts lancre or lancre2.</p>
@@ -432,7 +434,7 @@ before they can be considered by this test. If you really want to adjust these
 values, you can look for the variables <em>$MINPAGES</em> and <em>$MINIPAGES</em> at the top of the 
 <code>check_bloat</code> subroutine.</p>
 <p>The schema named 'information_schema' is excluded from this test, as the only tables 
-it contains are small ans do not change.</p>
+it contains are small and do not change.</p>
 <p>Please note that the values computed by this action are not precise, and 
 should be used as a guideline only. Great effort was made to estimate the 
 correct size of a table, but in the end it is only an estimate. The correct 
@@ -488,7 +490,7 @@ value. However, an option of <em>--reverse</em> will trigger the alert if the re
 <p>Example 1: Warn if any relation over 100 pages is named &quot;rad&quot;:</p>
 <pre>
   check_postgres_custom_query --checktype=string -w &quot;rad&quot; --query=&quot;SELECT relname FROM pg_class WHERE relpages &gt; 100&quot; --port=5432</pre>
-<p>Example 2: Give a critical if the &quot;foobar&quot; function returns over 5GB of bytes:</p>
+<p>Example 2: Give a critical if the &quot;foobar&quot; function returns a number over 5MB:</p>
 <pre>
   check_postgres_custom_query --port=5432 --critical='5MB'--checktype=size --query=&quot;SELECT foobar()&quot;</pre>
 <p>Example 2: Warn if the function &quot;snazzo&quot; returns less than 42:</p>
@@ -556,6 +558,37 @@ maps to a file system: these can be included or excluded. See the
 and the name of the file system on the fourth line.</p>
 <p>
 </p>
+<h2><a name="fsm_pages"><strong>fsm_pages</strong></a></h2>
+<p>(<code>symlink: check_postgres_fsm_pages</code>) Checks how close a cluster is to the Postgres <strong>max_fsm_pages</strong> setting.
+This action will only work for databases of 8.2 or higher, and it requires the contrib
+module <strong>pg_freespacemap</strong> be installed. The <em>--warning</em> and <em>--critical</em> options should be expressed
+as percentages. The number of used pages in the free-space-map is determined by looking in the
+pg_freespacemap_relations view, and running a formula based on the formula used for
+outputting free-space-map pageslots in the vacuum verbose command. The default values are <strong>85%</strong> for the 
+warning and <strong>95%</strong> for the critical.</p>
+<p>Example 1: Give a warning when our cluster has used up 76% of the free-space pageslots, with pg_freespacemap installed in database robert</p>
+<pre>
+  check_postgres_autovac_freeze --dbname=robert --warning=&quot;76%&quot;</pre>
+<p>While you need to pass in the name of the database where pg_freespacemap is installed (and optionally a schema name if you have
+installed the module in a non-standard schema), you only need to run this check once per cluster. Also, checking this information
+does require obtaining special locks on the free-space-map, so it is recommend you do not run this check with short intervals.</p>
+<p>
+</p>
+<h2><a name="fsm_relations"><strong>fsm_relations</strong></a></h2>
+<p>(<code>symlink: check_postgres_fsm_relations</code>) Checks how close a cluster is to the Postgres <strong>max_fsm_relations</strong> setting. 
+This action will only work for databases of 8.2 or higher, and it requires the contrib module <strong>pg_freespacemap</strong> be 
+installed. The <em>--warning</em> and <em>--critical</em> options should be expressed as percentages. The number of used relations 
+in the free-space-map is determined by looking in the pg_freespacemap_relations view. The default values are <strong>85%</strong> for 
+the warning and <strong>95%</strong> for the critical.</p>
+<p>Example 1: Give a warning when our cluster has used up 80% of the free-space relations, with pg_freespacemap installed in database dylan, in non-standard schema emma</p>
+<pre>
+  check_postgres_autovac_freeze --dbname=dylan --warning=&quot;75%&quot; --schema=emma</pre>
+<p>While you need to pass in the name of the database where pg_freespacemap is installed (and optionally a schema name
+if you have installed the module in a non-standard schema), you only need to run this check once per cluster. Also,
+checking this information does require obtaining special locks on the free-space-map, so it is recommend you do not
+run this check with short intervals.</p>
+<p>
+</p>
 <h2><a name="index_size"><strong>index_size</strong></a></h2>
 <p>
 </p>
@@ -1058,6 +1091,12 @@ 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.2.0</strong> (September 2008)</a></strong></dt>
+
+<dd>
+<pre>
+ Add fsm_pages and fsm_relations actions. (Robert Treat)</pre>
+</dd>
 <dt><strong><a name="item_4"><strong>Version 2.1.4</strong> (September 22, 2008)</a></strong></dt>
 
 <dd>
@@ -1085,7 +1124,7 @@ feature requests, and commit notices, send email to <a href="mailto:check_postgr
 <pre>
  Don't check databases with datallowconn false for the &quot;autovac_freeze&quot; action.</pre>
 </dd>
-<dt><strong><a name="item_0"><strong>Version 2.1.0</strong> (July 18, 2008)</a></strong></dt>
+<dt><strong><strong>Version 2.1.0</strong> (July 18, 2008)</strong></dt>
 
 <dd>
 <pre>
diff --git a/index.html b/index.html
index 98c41be..0f16157 100644
--- a/index.html
+++ b/index.html
@@ -21,13 +21,13 @@ 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.1.4</b>, and was released on September 22, 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.2.0</b>, and was released on September 25, 2008.</p>
 
 <ul>
- <li><a href="/check_postgres/check_postgres.pl.html">Documentation for check_postgres 2.1.4</a></li>
+ <li><a href="/check_postgres/check_postgres.pl.html">Documentation for check_postgres 2.2.0</a></li>
 </ul>
 <ul>
- <li><a href="/check_postgres/check_postgres.pl">Download check_postgres.pl 2.1.4</a></li>
+ <li><a href="/check_postgres/check_postgres.pl">Download check_postgres.pl 2.2.0</a></li>
  <li><a href="/check_postgres/check_postgres.pl.asc">PGP signature for check_postgres.pl</a></li>
 </ul>
 
diff --git a/t/99_spellcheck.t b/t/99_spellcheck.t
index d9f44cd..74cfb5c 100644
--- a/t/99_spellcheck.t
+++ b/t/99_spellcheck.t
@@ -184,6 +184,7 @@ backends
 burrick
 checksum
 checksums
+contrib
 cperl
 criticals
 cronjob
@@ -193,6 +194,8 @@ dbname
 dbpass
 dbport
 dbuser
+dylan
+emma
 exabytes
 excludeuser
 ExclusiveLock
@@ -200,6 +203,7 @@ faceoff
 finishup
 flagg
 franklin
+fsm
 garrett
 greg
 grimm
@@ -221,6 +225,7 @@ NAGIOS
 nols
 ok
 oskar
+pageslots
 perflimit
 pgpass
 pluto
@@ -230,6 +235,7 @@ PSQL
 queryname
 quirm
 refactoring
+robert
 runtime
 salesrep
 sami
-- 
1.5.5.4



More information about the Check_postgres mailing list