#!/usr/bin/perl -w # -*- perl -*- # # Show postgres lock statistics # # Parameters: # # config (required) # # Config variables: # # dbhost - Which database server to use. Defaults to # 'localhost'. # dbport - Which port on the database server to connect to. # Defaults to '5432'. # dbuser - A Postgresql user account with read permission to # the given database. Defaults to # 'postgres'. Anyway, Munin must be told which user # this plugin should be run as. # dbpass - The corresponding password, if # applicable. Default to undef. Remember that # pg_hba.conf must be configured accordingly. # # Magic markers #%# family=auto #%# capabilities=suggest use strict; use DBI; # See postgress_block_read_ for docs my $dbhost = $ENV{'dbhost'} || ''; my $dbport = $ENV{'dbport'} || ''; my $dbname = $ENV{'dbname'} || 'template1'; my $dbuser = $ENV{'dbuser'} || 'postgres'; if ($ARGV[0] && $ARGV[0] eq "config") { print <connect ($Con, $dbuser, '', {RaiseError =>1}) || die "Unable to access Database $dbname on host $dbhost as user $dbuser.\nError returned was: ". $DBI::errstr; my $sql="SELECT mode,COUNT(mode) FROM pg_locks GROUP BY mode ORDER BY mode;"; my $sth = $Dbh->prepare ($sql); $sth->execute (); my $locks = 0; my $exlocks = 0; while (my ($mode, $count) = $sth->fetchrow ()) { if ($mode =~ /exclusive/i) { $exlocks = $exlocks + $count; } $locks = $locks+$count; } print "locks.value $locks\n"; print "exlocks.value $exlocks\n"; }