1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-09-19 00:53:19 +00:00

- have some dirs

This commit is contained in:
Steve Schnepp 2012-02-13 18:24:46 +01:00
parent 0b089ea777
commit 08346aac58
687 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,114 @@
#!/usr/bin/perl -w
# Plugin for monitor postgres connections without DBI.
#
# Licenced under GPL v2.
#
# Usage:
#
# Symlink into /etc/munin/plugins/ and add the monitored
# database to the filename. e.g.:
#
# ln -s /usr/share/munin/plugins/pg__connections \
# /etc/munin/plugins/pg_<databasename>_connections
# This should, however, be given through autoconf and suggest.
#
# If required, give username, password and/or Postgresql server
# host through environment variables.
#
# You must also activate Postgresql statistics. See
# http://www.postgresql.org/docs/7.4/interactive/monitoring-stats.html
# for how to enable this. Specifically, the following lines must
# exist in your postgresql.conf:
#
# stats_start_collector = true
# stats_block_level = true
#
#
# Parameters:
#
# config (required)
#
# Config variables:
#
# dbhost - Which database server to use. Defaults to
# 'localhost'.
# dbname - Which database to use. Defaults to template1
# dbuser - A Postgresql user account with read permission to
# the given database. Defaults to
# 'postgres'. Anyway, Munin must be told which user
# this plugin should be run as.
# dbpass - The corresponding password, if
# applicable. Default to undef. Remember that
# pg_hba.conf must be configured accordingly.
#
# Magic markers
#%# family=auto
#%# capabilities=autoconf
use strict;
my $psql = $ENV{'psql'} || '/usr/bin/psql';
my $dbhost = $ENV{'dbhost'} || '127.0.0.1';
my $dbname = $ENV{'dbname'} || 'template1';
my $dbuser = $ENV{'dbuser'} || 'munin';
#my $dbuserx = $ENV{'dbuserx'} || '';
my $dbport = $ENV{'dbport'} || '5432';
my $dbpass = $ENV{'dbpass'} || 'munin';
my $COMMAND = "PGPASSWORD='$dbpass' '$psql' '$dbname' -h '$dbhost' -U '$dbuser' -p '$dbport' -A -F, -t ";
if (exists $ARGV[0]) {
if ($ARGV[0] eq "config") {
my $sqlCommand = "$COMMAND -c 'SHOW max_connections;'";
my ($max_connections) = `$sqlCommand`;
my $warning = int ($max_connections * 0.7);
my $critical = int ($max_connections * 0.8);
print "graph_title PostgresSQL active connections\n";
print "graph_args -l 0 --base 1000\n";
print "graph_vlabel Connections\n";
print "graph_category Postgresql\n";
print "graph_info Shows active Postgresql connections from $dbname\n";
$sqlCommand = "$COMMAND -c 'select datname, count(*) from pg_stat_activity group by datname;'";
open(SERVICE, "$sqlCommand |")
or die("Could not execute '$sqlCommand': $!");
my $setarea = "yes";
while (<SERVICE>) {
my ($datname, $curr_conn) = (m/(\w+).*?(\d+(?:\.\d+)?)/);
print "$datname.label $datname active connections\n";
print "$datname.info $datname active connections\n";
print "$datname.type GAUGE\n";
if ($setarea eq "yes") {
print "$datname.draw AREA\n";
$setarea="";
} else {
print "$datname.draw STACK\n";
}
}
print "max_connections.label Max. connections\n";
print "max_connections.info Max. connections\n";
print "max_connections.type GAUGE\n";
print "warning $warning\n";
print "critical $critical\n";
exit 0;
}
}
# select datname, count(*) from pg_stat_activity group by datname
my $sqlCommand = "$COMMAND -c 'SHOW max_connections;'";
my ($max_connections) = `$sqlCommand`;
$sqlCommand = "$COMMAND -c 'select datname, count(*) from pg_stat_activity group by datname;'";
open(SERVICE, "$sqlCommand |")
or die("Could not execute '$sqlCommand': $!");
while (<SERVICE>) {
my ($datname, $curr_conn) = (m/(\w+).*?(\d+(?:\.\d+)?)/);
print "$datname.value $curr_conn\n";
}
print "max_connections.value $max_connections\n";

View file

@ -0,0 +1,159 @@
#!/usr/bin/perl
# Plugin to monitor Postgresql memory usage; gives number of blocks
# read from disk and from memory, showing how much of the database is
# served from Postgresql's memory buffer.
#
# PLEASE NOTE: This plugin may not present the whole truth - the truth
# may actually be even better than this plugin will show you! That is
# because Postgresql statistics only considers memory block reads from
# its own allocated memory. When Postgresql reads from disk, it may
# actually still be read from memory, but from the _kernel_'s
# memory. Summarily, your database server may run even better than
# this plugin will indicate. See
# http://www.postgresql.org/docs/7.4/interactive/monitoring-stats.html
# for a (short) description.
#
# Copyright Bjørn Ruberg <bjorn@linpro.no> 2006
#
# Licenced under GPL v2.
#
# Usage:
#
# Symlink into /etc/munin/plugins/ and add the monitored
# database to the filename. e.g.:
#
# ln -s /usr/share/munin/plugins/postgres_block_read_ \
# /etc/munin/plugins/postgres_block_read_SomeDatabase
# This should, however, be given through autoconf and suggest.
#
# If required, give username, password and/or Postgresql server
# host through environment variables.
#
# You must also activate Postgresql statistics. See
# http://www.postgresql.org/docs/7.4/interactive/monitoring-stats.html
# for how to enable this. Specifically, the following lines must
# exist in your postgresql.conf:
#
# stats_start_collector = true
# stats_block_level = true
#
#
# Parameters:
#
# config (required)
#
# Config variables:
#
# dbhost - Which database server to use. Defaults to
# 'localhost'.
# dbuser - A Postgresql user account with read permission to
# the given database. Defaults to
# 'postgres'. Anyway, Munin must be told which user
# this plugin should be run as.
# dbpass - The corresponding password, if
# applicable. Default to undef. Remember that
# pg_hba.conf must be configured accordingly.
#
# Magic markers
#%# family=auto
#%# capabilities=autoconf suggest
use strict;
use DBI;
use Data::Dumper;
use vars qw ( $debug $suggest $configure $dbh );
# Need these variables at an early stage to enable
# autoconf and suggest
my $dbhost = $ENV{'dbhost'} || ''; # Connect to localhost by default
my $dbname = $ENV{'dbname'} || 'template1';
my $dbuser = $ENV{'dbuser'} || 'postgres';
my $dbpass = $ENV{'dbpass'} || '';
if (exists $ARGV[0]) {
if ($ARGV[0] eq 'autoconf') {
# Check for DBD::Pg
if (! eval "require DBD::Pg;") {
print "no (DBD::Pg not found)";
exit 1;
}
# Then we try to detect Postgres presence by connecting to
# 'template1'.
my $dsn = "dbi:Pg:dbname=template1";
$dsn .= ";host=$dbhost" if $dbhost;
my $tempdbh = DBI->connect ($dsn, $dbuser, $dbpass);
if ($tempdbh) {
print "yes\n";
exit 0;
} else {
print "no (Can't connect to given host, please check environment settings)\n";
exit 1;
}
} elsif ($ARGV[0] eq 'debug') {
# Set debug flag
$debug = 1;
} elsif ($ARGV[0] eq 'config') {
# Set config flag
$configure = 1;
} elsif ($ARGV[0] eq 'suggest') {
# doesn't always work
my @datasources = DBI->data_sources ('Pg');
foreach my $dsn (grep !/\=template\d$/, @datasources) {
(my $db = $dsn) =~ s/^.*=//;
print "$db\n";
}
exit 0;
}
}
# Must do this here, after checking for autoconf/suggest/etc, because the
# plugin must be able to run before it is linked to the databases.
my (undef, undef, undef, $dbname) = split (/_/, $0, 4);
die "No dbname configured (did you make the proper symlink?)" unless $dbname;
my @datasources = DBI->data_sources ('Pg')
or die ("Can't read any possible data sources: $?");
my $dsn = "DBI:Pg:dbname=$dbname";
$dsn .= ";host=$dbhost" if $dbhost;
print "#$dsn\n" if $debug;
my $dbh = DBI->connect ($dsn, $dbuser, $dbpass, {RaiseError =>1});
unless($dbh) {
die("Database $dbname\@$dbhost (". $DBI::errstr .")\n");
}
if ($configure) {
print <<EOF;
graph_title Postgres data reads from $dbname
graph_args --base 1000
graph_vlabel Blocks read per \${graph_period}
graph_category Postgresql
graph_info Shows number of blocks read from disk and from memory
from_disk.label Read from disk
from_disk.info Read from disk
from_disk.type DERIVE
from_disk.min 0
from_disk.draw AREA
from_memory.label Cached in memory
from_memory.info Cached in memory
from_memory.type DERIVE
from_memory.min 0
from_memory.draw STACK
EOF
} else {
my $sql = "SELECT (SUM (heap_blks_read) + SUM (idx_blks_read) + ";
$sql .= "SUM (toast_blks_read) + SUM (tidx_blks_read)) AS disk, ";
$sql .= "(SUM (heap_blks_hit) +SUM (idx_blks_hit) + ";
$sql .= "SUM (toast_blks_hit) + SUM (tidx_blks_hit)) AS mem ";
$sql .= "from pg_statio_user_tables ";
print "# $sql\n" if $debug;
my $sth = $dbh->prepare ($sql);
$sth->execute();
if ($sth->rows > 0) {
printf ("# Rows: %d\n", $sth->rows) if $debug;
my ($disk, $mem) = $sth->fetchrow_array();
print "from_disk.value $disk\n";
print "from_memory.value $mem\n";
}
}

View file

@ -0,0 +1,48 @@
#!/usr/bin/perl -w
use strict;
use DBI;
my $dbhost = $ENV{'dbhost'} || '127.0.0.1';
my $dbname = $ENV{'dbname'} || 'template1';
my $dbuser = $ENV{'dbuser'} || 'postgres';
my $dbpass = $ENV{'dbpass'} || '';
if ($ARGV[0] && $ARGV[0] eq "config") {
print <<EOF;
graph_title Postgres locks
graph_args -l 0 --base 1000
graph_vlabel Locks
graph_category Postgresql
graph_info Shows Postgresql locks
locks.label Locks
locks.info Locks (more info here, please... :)
locks.type GAUGE
locks.warning 5
locks.critical 10
exlocks.label Exclusive locks
exlocks.info Exclusive locks (here too, please... :)
exlocks.type GAUGE
exlocks.warning 5
exlocks.critical 10
EOF
} else {
my $Con = "DBI:Pg:dbname=$dbname;host=$dbhost";
my $Dbh = DBI->connect ($Con,
$dbuser,
$dbpass,
{RaiseError =>1}) || die "Unable to access Database $dbname on host $dbhost as user $dbuser.\nError returned was: ". $DBI::errstr;
my $sql="SELECT mode,COUNT(mode) FROM pg_locks GROUP BY mode ORDER BY mode;";
my $sth = $Dbh->prepare ($sql);
$sth->execute ();
my $locks = 0;
my $exlocks = 0;
while (my ($mode, $count) = $sth->fetchrow ()) {
if ($mode =~ /exclusive/i) {
$exlocks = $exlocks + $count;
}
$locks = $locks+$count;
}
print "locks.value $locks\n";
print "exlocks.value $exlocks\n";
}

View file

@ -0,0 +1,67 @@
#!/bin/bash
db=$(basename $0 | sed 's/^postgres_queries2_//g')
if [ "$db" == "" ];then
echo "error/no db" >&2
exit 1
fi
#echo $db
if [ "$1" == "config" ];then
cat << EOF
graph_title Postgres queries2 on $db
graph_args --base 1000
graph_vlabel Queries per \${graph_period}
graph_category PostgreSQL
graph_info Shows number of select, insert, update and delete queries
sel_seq.label s_selects
sel_seq.info Sequential selects on all tables
sel_seq.type DERIVE
sel_seq.min 0
sel_seq_rows.label s_select rows
sel_seq_rows.info Rows returned from sequential selects
sel_seq_rows.type DERIVE
sel_seq.min 0
sel_idx.label i_selects
sel_idx.info Sequential selects on all indexes
sel_idx.type DERIVE
sel_seq.min 0
sel_idx_rows.label i_select rows
sel_idx_rows.info Rows returned form index selects
sel_idx_rows.type DERIVE
sel_seq_rows.min 0
inserts.label inserts
inserts.info Rows inserted on all tables
inserts.type DERIVE
inserts.min 0
updates.label updates
updates.info Rows updated on all tables
updates.type DERIVE
updates.min 0
deletes.label deletes
deletes.info Rows deleted from all tables
deletes.type DERIVE
deletes.min 0
EOF
else
psql -At $db << EOF
select
'sel_seq.value ' || SUM(seq_scan) || E'\n' ||
'sel_seq_rows.value ' || SUM(seq_tup_read) || E'\n' ||
'sel_idx.value ' || SUM(idx_scan) || E'\n' ||
'sel_idx_rows.value ' || SUM(idx_tup_fetch) || E'\n' ||
'inserts.value ' || SUM(n_tup_ins) || E'\n' ||
'updates.value ' || SUM(n_tup_upd) || E'\n' ||
'deletes.value ' || SUM(n_tup_del)
from pg_stat_all_tables;
EOF
# my $sql = "SELECT SUM(seq_scan),SUM(seq_tup_read), ";
# $sql .= "SUM(idx_scan),SUM(idx_tup_fetch), ";
# $sql .= "SUM(n_tup_ins),SUM(n_tup_upd),SUM(n_tup_del) ";
# $sql .= "from pg_stat_all_tables";
# echo 1
fi

View file

@ -0,0 +1,172 @@
#!/usr/bin/perl
# (Temporary) source: http://munin.projects.linpro.no/ticket/63
# Written by Bjørn Ruberg (bjorn@linpro.no) 2006
# Rewritten by Moses Moore 2006-04-08 moc.iazom@sesom
# Licenced under GPL
# Magic markers
#%# family=auto
#%# capabilities=autoconf suggest
use strict;
use DBI;
use vars qw ( $debug $suggest $configure $dbh );
# Package maintainers should provide an environment
# file for the /etc/munin/plugin-conf.d/ directory
# to override these values if necessary.
# NOTE: The plugin (also when auto configured) should
# be run by the postgresql user account.
# Need these variables at an early stage to enable
# autoconf and suggest
my $dbhost = $ENV{'dbhost'} || ''; # Connect to localhost by default
my $dbname = $ENV{'dbname'} || 'template1';
my $dbuser = $ENV{'dbuser'} || 'postgres';
my $dbpass = $ENV{'dbpass'} || '';
if (exists $ARGV[0]) {
if ($ARGV[0] eq 'autoconf') {
# Check for DBD::Pg
if (! eval "require DBD::Pg;") {
print "no (DBD::Pg not found)";
exit 1;
}
# Then we try to detect Postgres presence by connecting to
# 'template1'.
my $dsn = "dbi:Pg:dbname=template1";
$dsn .= ";host=$dbhost" if $dbhost;
my $tempdbh = DBI->connect ($dsn, $dbuser, $dbpass);
if ($tempdbh) {
print "yes\n";
exit 0;
} else {
print "no (Can't connect to given host, please check environment settings)\n";
exit 1;
}
} elsif ($ARGV[0] and $ARGV[0] eq 'debug') {
# Set config flag
$debug = 1;
} elsif ($ARGV[0] and $ARGV[0] eq 'config') {
# Set config flag
$configure = 1;
} elsif ($ARGV[0] eq 'suggest') {
# doesn't always work
my @datasources = DBI->data_sources ('Pg');
foreach my $dsn (grep !/\=template\d$/, @datasources) {
(my $db = $dsn) =~ s/^.*=//;
print "$db\n";
}
exit 0;
}
}
# Must do this here, after checking for autoconf/suggest/etc, because the
# plugin must be able to run before it is linked to the databases.
my (undef, undef, $dbname) = split (/_/, $0, 3);
die "No dbname configured (did you make the proper symlink?)" unless $dbname;
my @datasources = DBI->data_sources ('Pg')
or die ("Can't read any possible data sources: $?");
my $dsn = "DBI:Pg:dbname=$dbname";
$dsn .= ";host=$dbhost" if $dbhost;
print "#$dsn\n" if $debug;
my $dbh = DBI->connect ($dsn, $dbuser, $dbpass, {RaiseError =>1});
unless($dbh) {
die("Database $dbname\@$dbhost (". $DBI::errstr .")\n");
}
if ($configure) {
print <<_EOM;
graph_title Postgres database $dbname
graph_args -l 0 --base 1024
graph_vlabel bytes
graph_category Postgresql
graph_info Size
size.label Database size (bytes)
size.info Database size
size.type GAUGE
size.draw AREA
indexsize.label Index size (bytes)
indexsize.info Index size
indexsize.type GAUGE
indexsize.draw STACK
metasize.label Meta database size (bytes)
metasize.info Meta database size
metasize.type GAUGE
metasize.draw STACK
metaindexsize.label Meta index size (bytes)
metaindexsize.info Meta index size
metaindexsize.type GAUGE
metaindexsize.draw STACK
_EOM
} else {
my $database_pages = 0;
my $database_indexes = 0;
my $metadatabase_pages = 0;
my $metadatabase_indexes = 0;
my @names = $dbh->tables;
# Find relfilenode and relpages from the given table
my $q_ind = "SELECT relkind, relfilenode, relpages FROM pg_class
WHERE relname = ?
UNION
SELECT relkind, relfilenode, relpages FROM pg_class
WHERE relfilenode IN (SELECT indexrelid FROM pg_index
WHERE indrelid IN (SELECT relfilenode FROM pg_class
WHERE relname = ?))";
my $sth = $dbh->prepare ($q_ind) or die $dbh->errstr;
# Iterate over the tables in the database
foreach my $table (@names) {
my $meta = 1;
print "#TABLE: $table\n" if $debug;
my $table_pages = 0;
my $table_indexes = 0;
my $metatable_pages = 0;
my $metatable_indexes = 0;
# "public" tables are the user data
$meta = 0 if $table =~ /^public\./;
$table =~ s/^.*\.//;
# Call the query with $table twice for each side of the UNION
$sth->execute ($table, $table) or die $dbh->errstr;
while (my ($relkind, $relfilenode, $relpages) = $sth->fetchrow_array) {
if ($relkind eq 'r') {
$table_pages += $relpages if $meta == 0;
$metatable_pages += $relpages if $meta == 1;
} elsif ($relkind eq 'i') {
$table_indexes += $relpages if $meta == 0;
$metatable_indexes += $relpages if $meta == 1;
}
# Define the query
my $q2 = "SELECT SUM(relpages)
FROM pg_class
WHERE relname IN (?, ?)";
my $sth2 = $dbh->prepare ($q2);
$sth2->execute ("pg_toast_${relfilenode}",
"pg_toast_${relfilenode}_index");
my $relpages = $sth2->fetchrow_array;
if ($relkind eq 'r') {
$table_pages += $relpages if $meta == 0;
$metatable_pages += $relpages if $meta == 1;
} elsif ($relkind eq 'i') {
$table_indexes += $relpages if $meta == 0;
$metatable_indexes += $relpages if $meta == 1;
}
print "#\tR:$relfilenode\tP:$table_pages\tI:$table_indexes\n" if $debug;
}
$database_pages += $table_pages;
$database_indexes += $table_indexes;
$metadatabase_pages += $metatable_pages;
$metadatabase_indexes += $metatable_indexes;
}
$sth->finish;
$dbh->disconnect;
print "size\.value " . $database_pages * 8192 . "\n";
print "indexsize\.value " . $database_indexes * 8192 . "\n";
print "metasize\.value " . $metadatabase_pages * 8192 . "\n";
print "metaindexsize\.value " . $metadatabase_indexes * 8192 . "\n";
}

View file

@ -0,0 +1,2 @@
Check http://aouyar.github.com/PyMunin/ to get the most recent versionof the
PyMunin Multi graph Munin Plugins and documentation.

View file

@ -0,0 +1,49 @@
#!/bin/bash
#
# Plugin to monitor PostgreSQL Backends
#
# Author:
# Guilherme Augusto da Rocha Silva <gars.dba@gmail.com>
#
# Created:
# 5th of november 2007
#
# Usage:
# Place in /etc/munin/plugins/ (or link it there using ln -s)
#
# Parameters:
# config (required)
#
# General info:
# Require permission for database access and read (no writes are processed).
# Recomended user is PostgreSQL database owner (default: postgres).
#
# Log info:
# 2007/11/30 - Review on comments
#
dbserver='localhost'
dbuser='postgres'
if [ "$1" = "config" ]; then
maximum=$(psql -h ${dbserver} -U ${dbuser} -tc "SHOW max_connections;" | bc)
reserved=$(psql -h ${dbserver} -U ${dbuser} -tc "SHOW superuser_reserved_connections;" | bc)
warning=$(((maximum-reserved)*70/100))
critical=$(((maximum-reserved)*90/100))
echo 'graph_args --base 1000 --lower-limit 0 --upper-limit '${maximum}
echo 'graph_category Postgresql'
echo 'graph_info Shows open backends on the PostgreSQL Server.'
echo 'graph_scale no'
echo 'graph_title PostgreSQL Active Backends'
echo 'graph_vlabel Number of active backends'
echo 'backends.label backends'
echo 'backends.type GAUGE'
echo 'backends.min 0'
echo 'backends.max '${maximum}
echo 'backends.warning '${warning}
echo 'backends.critical '${critical}
echo 'backends.info Number of open sessions.'
exit 0
fi
echo 'backends.value '$(psql -h ${dbserver} -U ${dbuser} -tc "SELECT SUM(numbackends) FROM pg_stat_database;" | bc)

View file

@ -0,0 +1,59 @@
#!/bin/bash
#
# Plugin to monitor PostgreSQL Locks
#
# Author:
# Guilherme Augusto da Rocha Silva <gars.dba@gmail.com>
#
# Created:
# 5th of november 2007
#
# Modified:
# 22th of September 2011 by Nozomu Kaneko <nozom.kaneko@gmail.com>
#
# Usage:
# Place in /etc/munin/plugins/ (or link it there using ln -s)
#
# Parameters:
# config (required)
#
# General info:
# Require permission for database access and read (no writes are processed).
# Recomended user is PostgreSQL database owner (default: postgres).
#
# Log info:
#
dbserver='localhost'
dbuser='postgres'
modes="AccessExclusive AccessShare Exclusive RowExclusive RowShare Share ShareRowExclusive ShareUpdateExclusive"
if [ "$1" = "config" ]; then
echo 'graph_args --lower-limit 0'
echo 'graph_category Postgresql'
echo 'graph_info Shows active locks on database server.'
echo 'graph_scale no'
echo 'graph_title PostgreSQL Active Locks'
echo 'graph_vlabel Number of active locks'
for mode in $modes; do
echo $mode.label $mode
echo $mode.info `echo $mode | perl -pe 's/(.)([A-Z])/$1 $2/g'` Lock.
done
exit 0
fi
for mode in $modes; do
eval ${mode}=0
done
eval $(psql -h ${dbserver} -U ${dbuser} template1 -tc "SELECT trim(mode, 'Lock'), COUNT(*) FROM pg_locks GROUP BY mode ORDER BY 1;" | while read name sep num
do
test -z "${name}" && continue
echo ${name}=${num}
done)
for mode in $modes; do
echo ${mode}.value $(eval echo \$$mode)
done

View file

@ -0,0 +1,57 @@
#!/bin/bash
#
# Plugin to monitor PostgreSQL Database Ratios (blocks read X blocks hit)
#
# Author:
# Guilherme Augusto da Rocha Silva <gars.dba@gmail.com>
#
# Created:
# 5th of november 2007
#
# Usage:
# Place in /etc/munin/plugins/ (or link it there using ln -s)
#
# Parameters:
# config (required)
#
# General info:
# Require permission for database access and read (no writes are processed).
# Recomended user is PostgreSQL database owner (default: postgres).
#
# Log info:
# 2007/11/30 - Review on comments
#
dbserver='localhost'
dbuser='postgres'
if [ "$1" = "config" ]; then
echo 'graph_args --base 1000 --lower-limit 0 --upper-limit 100'
echo 'graph_category Postgresql'
echo 'graph_info Shows each database read/hit (%) on the PostgreSQL Server.'
echo 'graph_scale no'
echo 'graph_title PostgreSQL Database Hit/Read Ratios'
echo 'graph_vlabel % of blocks read and hits'
psql -h ${dbserver} -U ${dbuser} -tc "SELECT datname FROM pg_stat_database WHERE datname != 'template0' ORDER BY 1;" | while read name
do
test -z "${name}" && continue
echo ${name}'.label '${name}
echo ${name}'.type GAUGE'
echo ${name}'.min 0'
echo ${name}'.max 100'
if [ "${name}" == "template0" ]; then
echo ${name}'.info PostgreSQL template database.'
elif [ "${name}" == "template1" ]; then
echo ${name}'.info PostgreSQL and/or user template database.'
elif [ "${name}" == "postgres" ]; then
echo ${name}'.info User postgres database.'
else
echo ${name}'.info User defined database.'
echo ${name}'.critical 50:min'
echo ${name}'.warning 75:min'
fi
done
exit 0
fi
psql -h ${dbserver} -U ${dbuser} -tc "SELECT '\n'||datname||'.value '||(CASE WHEN (blks_hit > 0) THEN ROUND((blks_hit::NUMERIC / (blks_hit + blks_read)::NUMERIC) * 100, 2) ELSE 0 END)::TEXT FROM pg_stat_database WHERE datname != 'template0' ORDER BY datname;"

View file

@ -0,0 +1,57 @@
#!/bin/bash
#
# Plugin to monitor PostgreSQL Database Sizes
#
# Author:
# Guilherme Augusto da Rocha Silva <gars.dba@gmail.com>
#
# Created:
# 5th of november 2007
#
# Usage:
# Place in /etc/munin/plugins/ (or link it there using ln -s)
#
# Parameters:
# config (required)
#
# General info:
# Require permission for database access and read (no writes are processed).
# Recomended user is PostgreSQL database owner (default: postgres).
#
# Log info:
# 2007/11/30 - Review on comments
#
dbserver='localhost'
dbuser='postgres'
if [ "$1" = "config" ]; then
echo 'graph_args --base 1024 --lower-limit 0'
echo 'graph_category Postgresql'
echo 'graph_info Shows each database size on the PostgreSQL Server.'
echo 'graph_title PostgreSQL Database Sizes'
echo 'graph_vlabel Size (bytes)'
psql -h ${dbserver} -U ${dbuser} -tc "SELECT datname FROM pg_database ORDER BY 1;" | while read name
do
test -z "${name}" && continue
echo ${name}'.label '${name}
echo ${name}'.type GAUGE'
if [ "${name}" == "template0" ]; then
echo ${name}'.info PostgreSQL template database.'
elif [ "${name}" == "template1" ]; then
echo ${name}'.info PostgreSQL and/or user template database.'
elif [ "${name}" == "postgres" ]; then
echo ${name}'.info User postgres database.'
else
echo ${name}'.info User defined database.'
fi
done
exit 0
fi
psql -h ${dbserver} -U ${dbuser} -tc "SELECT datname, PG_DATABASE_SIZE(oid) FROM pg_database ORDER BY 1;" | while read name sep num
do
test -z "${name}" && continue
echo ${name}'.value '${num}
done

View file

@ -0,0 +1,54 @@
#!/bin/bash
#
# Plugin to monitor PostgreSQL Tablespaces Size
#
# Author:
# Guilherme Augusto da Rocha Silva <gars.dba@gmail.com>
#
# Created:
# 5th of november 2007
#
# Usage:
# Place in /etc/munin/plugins/ (or link it there using ln -s)
#
# Parameters:
# config (required)
#
# General info:
# Require permission for database access and read (no writes are processed).
# Recomended user is PostgreSQL database owner (default: postgres).
#
# Log info:
#
dbserver='localhost'
dbuser='postgres'
if [ "$1" = "config" ]; then
echo 'graph_args --base 1024 --lower-limit 0'
echo 'graph_category Postgresql'
echo 'graph_info Shows each tablespace size on the PostgreSQL Server.'
echo 'graph_title PostgreSQL Tablespace Sizes'
echo 'graph_vlabel Size (bytes)'
psql -h ${dbserver} -U ${dbuser} -tc "SELECT spcname FROM pg_tablespace ORDER BY 1;" | while read name
do
test -z "${name}" && continue
echo ${name}'.label '${name}
echo ${name}'.type GAUGE'
if [ "${name}" == "pg_global" ]; then
echo ${name}'.info Tablespace for shared system catalogs.'
elif [ "${name}" == "pg_default" ]; then
echo ${name}'.info Default tablespace of the template1 and template0 databases (and, therefore, the default tablespace for other databases, unless user defined ones).'
else
echo ${name}'.info User defined tablespace.'
fi
done
exit 0
fi
psql -h ${dbserver} -U ${dbuser} -tc "SELECT spcname, PG_TABLESPACE_SIZE(oid) FROM pg_tablespace ORDER BY 1;" | while read name sep num
do
test -z "${name}" && continue
echo ${name}'.value '${num}
done

View file

@ -0,0 +1,43 @@
#!/bin/bash
#
# Plugin to monitor PostgreSQL Commits and Rollbacks in Transactions
#
# Author:
# Guilherme Augusto da Rocha Silva <gars.dba@gmail.com>
#
# Created:
# 9th of november 2007
#
# Usage:
# Place in /etc/munin/plugins/ (or link it there using ln -s)
#
# Parameters:
# config (required)
#
# General info:
# Require permission for database access and read (no writes are processed).
# Recomended user is PostgreSQL database owner (default: postgres).
#
# Log info:
#
dbserver='localhost'
dbuser='postgres'
if [ "$1" = "config" ]; then
echo 'graph_args --base 1000 --lower-limit 0'
echo 'graph_category Postgresql'
echo 'graph_info Shows summarized commits and rollbacks in transactions on the PostgreSQL Server.'
echo 'graph_title PostgreSQL Transactions'
echo 'graph_vlabel Number of Commits and Rollbacks'
echo 'commits.label commits'
echo 'commits.min 0'
echo 'commits.info Number of transaction commits.'
echo 'rollbacks.label rollbacks'
echo 'rollbacks.min 0'
echo 'rollbacks.info Number of transaction rollbacks.'
exit 0
fi
psql -h ${dbserver} -U ${dbuser} -tc "SELECT '\ncommits.value '||SUM(xact_commit)::TEXT || '\nrollbacks.value '||SUM(xact_rollback)::TEXT FROM pg_stat_database;"

104
plugins/postgresql/slony_ Executable file
View file

@ -0,0 +1,104 @@
#!/usr/bin/perl
# -*- perl -*-
# Jean-Samuel Reynaud <js.reynaud@free.fr>
# Based on postgres_locks
#
# Wildcard-plugin to monitor slony latency. To monitor a
# slony cluster, link slony_<cluster_schema> 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 <<EOF;
graph_title Slony latency
graph_args --base 1000
graph_vlabel Latency in seconds
graph_category PostgreSQL
graph_info Shows Slony latency
EOF
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);";
my $sth = $dbh->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<<EOF
$no_id.label $conninfo
$no_id.info $comment
$no_id.type GAUGE
$no_id.warning 60
$no_id.critical 1800
$no_id.min 0
EOF
}
} else {
my $sql="select st_received,st_lag_num_events,EXTRACT(EPOCH FROM st_lag_time)::integer from $cluster.sl_status;";
my $sth = $dbh->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"
}
}