/[munin-modules]/postgres_locks
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /postgres_locks

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3 - (hide annotations)
Tue Jun 12 11:13:25 2007 UTC (12 years, 7 months ago) by dpavlin
File size: 1367 byte(s)
fix warnings

1 dpavlin 1 #!/usr/bin/perl -w
2     use strict;
3     use DBI;
4    
5 dpavlin 3 my $dbhost = $ENV{'dbhost'} || '';
6 dpavlin 1 my $dbname = $ENV{'dbname'} || 'template1';
7     my $dbuser = $ENV{'dbuser'} || 'postgres';
8     my $dbpass = $ENV{'dbpass'} || '';
9    
10     if ($ARGV[0] && $ARGV[0] eq "config") {
11     print <<EOF;
12     graph_title Postgres locks
13     graph_args -l 0 --base 1000
14     graph_vlabel Locks
15     graph_category Postgresql
16     graph_info Shows Postgresql locks
17     locks.label Locks
18     locks.info Locks (more info here, please... :)
19     locks.type GAUGE
20     locks.warning 5
21     locks.critical 10
22     exlocks.label Exclusive locks
23     exlocks.info Exclusive locks (here too, please... :)
24     exlocks.type GAUGE
25     exlocks.warning 5
26     exlocks.critical 10
27     EOF
28     } else {
29 dpavlin 3 my $Con = "DBI:Pg:dbname=$dbname" . ( $dbhost ? ";host=$dbhost" : "" );
30 dpavlin 1 my $Dbh = DBI->connect ($Con,
31     $dbuser,
32     $dbpass,
33     {RaiseError =>1}) || die "Unable to access Database $dbname on host $dbhost as user $dbuser.\nError returned was: ". $DBI::errstr;
34    
35     my $sql="SELECT mode,COUNT(mode) FROM pg_locks GROUP BY mode ORDER BY mode;";
36     my $sth = $Dbh->prepare ($sql);
37     $sth->execute ();
38     my $locks = 0;
39     my $exlocks = 0;
40     while (my ($mode, $count) = $sth->fetchrow ()) {
41     if ($mode =~ /exclusive/i) {
42     $exlocks = $exlocks + $count;
43     }
44     $locks = $locks+$count;
45     }
46     print "locks.value $locks\n";
47     print "exlocks.value $exlocks\n";
48     }

Properties

Name Value
svn:executable

  ViewVC Help
Powered by ViewVC 1.1.26