root / plugins / postgresql / postgres_locks @ 17f78427
Historique | Voir | Annoter | Télécharger (1,31 ko)
| 1 | 60640849 | Bj?rn Ruberg | #!/usr/bin/perl -w |
|---|---|---|---|
| 2 | use strict; |
||
| 3 | use DBI; |
||
| 4 | |||
| 5 | my $dbhost = $ENV{'dbhost'} || '127.0.0.1';
|
||
| 6 | 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 | 29bdf34e | dipohl | graph_category db |
| 16 | 60640849 | Bj?rn Ruberg | 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 | my $Con = "DBI:Pg:dbname=$dbname;host=$dbhost"; |
||
| 30 | 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 | } |
