Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / postgresql / slony_ @ c5ab6538

Historique | Voir | Annoter | Télécharger (2,76 ko)

1
#!/usr/bin/perl
2
# -*- perl -*-
3
# Jean-Samuel Reynaud <js.reynaud@free.fr>
4
# Based on postgres_locks
5
#
6
# Wildcard-plugin to monitor slony latency. To monitor a
7
# slony cluster, link slony_<cluster_schema> to this file. E.g.
8
#
9
#    ln -s /usr/share/munin/node/plugins-auto/slony_ /etc/munin/node.d/slony__my_cluster
10
#
11
# ...will monitor my_cluster's slony cluster
12
#
13
# Show slony latency
14
#
15
# Parameters:
16
#
17
# 	config
18
# 	autoconf
19
#
20
#
21
#
22
# Configuration variables:
23
#
24
#	PGHOST		- Database server to use. Defaults to using ident
25
#			  authentication with the local server.
26
#	PGPORT		- Port to connect to. Defaults to '5432'.
27
#	PGDATABASE	- Database to connect to. Defaults to 'template1'.
28
#	PGUSER		- User to connect as, if necessary.
29
#	PGPASSWORD	- Corresponding password to use, if necessary.
30
#
31
#	(See libpq documentation for more.)
32
#	Note that PGDATABASE will default to 'template1' in this plugin, and
33
#	without PGHOST it will try ident authentication with the local server,
34
#	as the user that the plugin is running as.
35
#
36
# Configuration example:
37
#
38
#	# Use local server, ident authentication with the 'postgres' user.
39
#	[slony_*]
40
#	user postgres
41
#
42
#	# Use local server, TCP authentication with a username and password.
43
#	[slony_*]
44
#	env.PGHOST localhost
45
#	env.PGUSER someuser
46
#	env.PGDATABASE somedb
47
#	env.PGPASSWORD somepassword
48
#
49
# Magic markers
50
#%# family=auto
51
#%# capabilities=
52

    
53
use strict;
54
use warnings;
55
use DBI;
56

    
57

    
58
my $cluster = $0;
59
$cluster =~ s/^.*slony_([\w\d\._\-]*)$/$1/;
60

    
61
# Default to template1 database.
62
$ENV{'PGDATABASE'} ||= 'template1';
63

    
64

    
65
my $dbh = DBI->connect ('dbi:Pg:', '', '', {RaiseError =>1})
66
    || die "Unable to access database.\nError returned was: ". $DBI::errstr;
67

    
68
if ($ARGV[0] && $ARGV[0] eq "config") {
69
    print <<EOF;
70
graph_title Slony latency
71
graph_args --base 1000
72
graph_vlabel Latency in seconds
73
graph_category PostgreSQL
74
graph_info Shows Slony latency
75
EOF
76
my $sql="select no_id,no_comment,pa_conninfo from $cluster.sl_node join $cluster.sl_path on (pa_server=no_id) where pa_client= $cluster.getlocalnodeid('$cluster'::name);";
77
    my $sth = $dbh->prepare ($sql);
78
    $sth->execute ();
79
    my $locks = 0;
80
    my $exlocks = 0;
81
    while (my ($no_id,$comment, $conninfo) = $sth->fetchrow ()) {
82
        $conninfo =~ s/.*host=([\w\d\._\-]*)\s.*/$1/;
83
        $no_id = sprintf("slave_%u",$no_id);
84
print<<EOF
85
$no_id.label $conninfo
86
$no_id.info $comment
87
$no_id.type GAUGE
88
$no_id.warning 60
89
$no_id.critical 1800
90
$no_id.min 0
91
EOF
92
}
93
} else {
94

    
95
    my $sql="select st_received,st_lag_num_events,EXTRACT(EPOCH FROM st_lag_time)::integer from $cluster.sl_status;";
96
    my $sth = $dbh->prepare ($sql);
97
    $sth->execute ();
98
    my $locks = 0;
99
    my $exlocks = 0;
100
    while (my ($no_id,$nb_event, $lag) = $sth->fetchrow ()) {
101
        $no_id = sprintf("slave_%u",$no_id);
102
        print "$no_id.value $lag\n"
103
    }
104
}