4 # Show postgres lock statistics
12 # dbhost - Which database server to use. Defaults to
14 # dbport - Which port on the database server to connect to.
16 # dbuser - A Postgresql user account with read permission to
17 # the given database. Defaults to
18 # 'postgres'. Anyway, Munin must be told which user
19 # this plugin should be run as.
20 # dbpass - The corresponding password, if
21 # applicable. Default to undef. Remember that
22 # pg_hba.conf must be configured accordingly.
26 #%# capabilities=suggest
31 # See postgress_block_read_ for docs
33 my $dbhost = $ENV{'dbhost'} || '';
34 my $dbport = $ENV{'dbport'} || '';
35 my $dbname = $ENV{'dbname'} || 'template1';
36 my $dbuser = $ENV{'dbuser'} || 'postgres';
38 if ($ARGV[0] && $ARGV[0] eq "config") {
40 graph_title Postgres locks
41 graph_args --base 1000
43 graph_category Postgresql
44 graph_info Shows Postgresql locks
46 locks.info Locks (more info here, please... :)
50 exlocks.label Exclusive locks
51 exlocks.info Exclusive locks (here too, please... :)
57 my $Con = "DBI:Pg:dbname=$dbname";
58 $Con .= ";host=$dbhost" if $dbhost;
59 $Con .= ";port=$dbport" if $dbport;
60 my $Dbh = DBI->connect ($Con, $dbuser,
62 {RaiseError =>1}) || die "Unable to access Database $dbname on host $dbhost as user $dbuser.\nError returned was: ". $DBI::errstr;
64 my $sql="SELECT mode,COUNT(mode) FROM pg_locks GROUP BY mode ORDER BY mode;";
65 my $sth = $Dbh->prepare ($sql);
69 while (my ($mode, $count) = $sth->fetchrow ()) {
70 if ($mode =~ /exclusive/i) {
71 $exlocks = $exlocks + $count;
73 $locks = $locks+$count;
75 print "locks.value $locks\n";
76 print "exlocks.value $exlocks\n";