[check_postgres] dbstats nagios output

Giles Westwood giles.westwood at semantico.com
Thu Oct 29 12:50:12 UTC 2009


Hi list,

We use pnp4nagios for all our graphing so we actually needed a nagios 
performance output for dbstats. I've also included a pnp template for 
displaying the data.

My Perl isn't great but anyway here is the code I modified:-


	if ($OUTPUT eq 'nagios'){
		print "POSTGRES_DB_STATS OK: | ";
	}
	
	for $db (@{$info->{db}}) {
	  SLURP: for my $row (split /\n/ => $db->{slurp}) {
			my @stats = split /\s*\|\s*/ => $row;
             ((defined($_) and length($_)) or $_ = 0) for @stats;
			(my $dbname = shift @stats) =~ s/^\s*//;
			next SLURP if skip_item($dbname);
			## If dbnames were specififed, use those for filtering as well
			if (@{$opt{dbname}}) {
				my $keepit = 0;
				for my $drow (@{$opt{dbname}}) {
					for my $d (split /,/ => $drow) {
						$d eq $dbname and $keepit = 1;
					}
				}
				next SLURP unless $keepit;
			}
			if ($OUTPUT eq'nagios'){
				my $template = 'commits=%d rollbacks=%d read=%d hit=%d idxscan=%d 
idxtupread=%d idxtupfetch=%d idxblksread=%d idxblkshit=%d seqscan=%d 
seqtupread=%d ret=%d fetch=%d ins=%d upd=%d del=%d';
				my $msg = sprintf "$template", @stats, (0,0,0,0,0,0,0,0,0,0,0,0,0);
				if ($dbname =~ /postgres|template|root/) {
					my $foo = "bar";
				}else {
					print "\'${dbname}_marker\'=1 $msg ";
				}
			} else {
				my $template = 'backends:%d commits:%d rollbacks:%d read:%d hit:%d 
idxscan:%d idxtupread:%d idxtupfetch:%d idxblksread:%d idxblkshit:%d 
seqscan:%d seqtupread:%d ret:%d fetch:%d ins:%d upd:%d del:%d';
				my $msg = sprintf "$template", @stats, (0,0,0,0,0,0,0,0,0,0,0,0,0);
				print "$msg dbname:$dbname\n";
			}
		}
	if ($OUTPUT eq 'nagios'){
		print "\n";
	}


-- 
Giles Westwood, Systems Administrator,
Semantico, Floor 1, 21-23 Dyke Road, Brighton BN1 3FE
<http://www.semantico.com/>
<mailto:Giles.Westwood at semantico.com>
<tel:+44-1273-358231> <fax:+44-1273-723232>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://mail.endcrypt.com/pipermail/check_postgres/attachments/20091029/208c770b/attachment.html 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://mail.endcrypt.com/pipermail/check_postgres/attachments/20091029/208c770b/attachment-0001.html 


More information about the Check_postgres mailing list