source: trunk/packages/xvm-munin-config/master/usr/share/xvm-munin-master-config/plugins/postgres_locks @ 2635

Last change on this file since 2635 was 1761, checked in by broder, 16 years ago

Initial checkin of xvm-munin-config package

  • Property svn:executable set to *
File size: 2.2 KB
Line 
1#!/usr/bin/perl -w
2# -*- perl -*-
3#
4# Show postgres lock statistics
5#
6# Parameters:
7#
8#       config   (required)
9#
10# Config variables:
11#
12#       dbhost     - Which database server to use. Defaults to
13#                    'localhost'.
14#       dbport     - Which port on the database server to connect to.
15#                    Defaults to '5432'.
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.
23#
24# Magic markers
25#%# family=auto
26#%# capabilities=suggest
27
28use strict;
29use DBI;
30
31# See postgress_block_read_ for docs
32
33my $dbhost = $ENV{'dbhost'} || '';
34my $dbport = $ENV{'dbport'} || '';
35my $dbname = $ENV{'dbname'} || 'template1';
36my $dbuser = $ENV{'dbuser'} || 'postgres';
37
38if ($ARGV[0] && $ARGV[0] eq "config") {
39    print <<EOF;
40graph_title Postgres locks
41graph_args --base 1000
42graph_vlabel Locks
43graph_category Postgresql
44graph_info Shows Postgresql locks
45locks.label Locks
46locks.info Locks (more info here, please... :)
47locks.type GAUGE
48locks.warning 5
49locks.critical 10
50exlocks.label Exclusive locks
51exlocks.info Exclusive locks (here too, please... :)
52exlocks.type GAUGE
53exlocks.warning 5
54exlocks.critical 10
55EOF
56} else {
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,
61                            '',
62                            {RaiseError =>1}) || die "Unable to access Database $dbname on host $dbhost as user $dbuser.\nError returned was: ". $DBI::errstr;
63
64    my $sql="SELECT mode,COUNT(mode) FROM pg_locks GROUP BY mode ORDER BY mode;";
65    my $sth = $Dbh->prepare ($sql);
66    $sth->execute ();
67    my $locks = 0;
68    my $exlocks = 0;
69    while (my ($mode, $count) = $sth->fetchrow ()) {
70        if ($mode =~ /exclusive/i) {
71            $exlocks = $exlocks + $count;
72        }
73        $locks = $locks+$count;
74    }
75    print "locks.value $locks\n";
76    print "exlocks.value $exlocks\n";
77}
Note: See TracBrowser for help on using the repository browser.