From b252bd9c5fd88d174174365d86e5fe73d25bbecc Mon Sep 17 00:00:00 2001 From: Jean-Samuel Reynaud Date: Mon, 20 Oct 2008 17:23:23 +0200 Subject: [PATCH] Initial version --- plugins/other/slony_ | 104 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100755 plugins/other/slony_ diff --git a/plugins/other/slony_ b/plugins/other/slony_ new file mode 100755 index 00000000..f1e725c6 --- /dev/null +++ b/plugins/other/slony_ @@ -0,0 +1,104 @@ +#!/usr/bin/perl +# -*- perl -*- +# Jean-Samuel Reynaud +# Based on postgres_locks +# +# Wildcard-plugin to monitor slony latency. To monitor a +# slony cluster, link slony_ to this file. E.g. +# +# ln -s /usr/share/munin/node/plugins-auto/slony_ /etc/munin/node.d/slony__my_cluster +# +# ...will monitor my_cluster's slony cluster +# +# Show slony latency +# +# Parameters: +# +# config +# autoconf +# +# +# +# Configuration variables: +# +# PGHOST - Database server to use. Defaults to using ident +# authentication with the local server. +# PGPORT - Port to connect to. Defaults to '5432'. +# PGDATABASE - Database to connect to. Defaults to 'template1'. +# PGUSER - User to connect as, if necessary. +# PGPASSWORD - Corresponding password to use, if necessary. +# +# (See libpq documentation for more.) +# Note that PGDATABASE will default to 'template1' in this plugin, and +# without PGHOST it will try ident authentication with the local server, +# as the user that the plugin is running as. +# +# Configuration example: +# +# # Use local server, ident authentication with the 'postgres' user. +# [slony_*] +# user postgres +# +# # Use local server, TCP authentication with a username and password. +# [slony_*] +# env.PGHOST localhost +# env.PGUSER someuser +# env.PGDATABASE somedb +# env.PGPASSWORD somepassword +# +# Magic markers +#%# family=auto +#%# capabilities= + +use strict; +use warnings; +use DBI; + + +my $cluster = $0; +$cluster =~ s/^.*slony_([\w\d\._\-]*)$/$1/; + +# Default to template1 database. +$ENV{'PGDATABASE'} ||= 'template1'; + + +my $dbh = DBI->connect ('dbi:Pg:', '', '', {RaiseError =>1}) + || die "Unable to access database.\nError returned was: ". $DBI::errstr; + +if ($ARGV[0] && $ARGV[0] eq "config") { + print <prepare ($sql); + $sth->execute (); + my $locks = 0; + my $exlocks = 0; + while (my ($no_id,$comment, $conninfo) = $sth->fetchrow ()) { + $conninfo =~ s/.*host=([\w\d\._\-]*)\s.*/$1/; + $no_id = sprintf("slave_%u",$no_id); +print<prepare ($sql); + $sth->execute (); + my $locks = 0; + my $exlocks = 0; + while (my ($no_id,$nb_event, $lag) = $sth->fetchrow ()) { + $no_id = sprintf("slave_%u",$no_id); + print "$no_id.value $lag\n" + } +}