mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-09-18 21:50:56 +00:00
Adding postgres standby commands + munin.
This commit is contained in:
parent
ed01ce4307
commit
7f593c2470
10 changed files with 1324 additions and 7 deletions
|
@ -4,7 +4,8 @@
|
|||
199.15.250.229 app02 app02.newsblur.com push
|
||||
199.15.252.156 app03 app03.newsblur.com dev
|
||||
199.15.252.109 app04 app04.newsblur.com www
|
||||
199.15.253.218 db01 db01.newsblur.com
|
||||
# 199.15.253.218 db01 db01.newsblur.com
|
||||
199.15.249.101 db01 db01.newsblur.com
|
||||
199.15.252.50 db02 db02.newsblur.com
|
||||
199.15.253.226 db03 db03.newsblur.com
|
||||
199.15.249.98 db04 db04.newsblur.com
|
||||
|
|
168
config/munin/pg_newsblur_connections
Executable file
168
config/munin/pg_newsblur_connections
Executable file
|
@ -0,0 +1,168 @@
|
|||
#!/usr/bin/perl -w
|
||||
# Plugin to monitor pg_stat_activity
|
||||
#
|
||||
# Copyright Dalibo <cedric.villemain@dalibo.com> 2007
|
||||
# Based on a plugin (postgres_block_read_) from Björn Ruberg <bjorn@linpro.no>
|
||||
#
|
||||
# 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/8.1/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;
|
||||
use DBI;
|
||||
use vars qw ( $debug $configure );
|
||||
use constant _PGMINI => 70400;
|
||||
|
||||
my $dbhost = $ENV{'dbhost'} || '';
|
||||
my $dbname = $ENV{'dbname'} || 'template1';
|
||||
my $dbuser = $ENV{'dbuser'} || 'postgres';
|
||||
my $dbport = $ENV{'dbport'} || '5432';
|
||||
my $dbpass = $ENV{'dbpass'} || '';
|
||||
my $statscope = $ENV{'statscope'} || 'user';
|
||||
|
||||
my $dsn = "DBI:Pg:dbname=$dbname";
|
||||
$dsn .=";host=$dbhost;port=$dbport" if $dbhost;
|
||||
my $pg_server_version;
|
||||
|
||||
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;
|
||||
}
|
||||
my $dbh = DBI->connect ($dsn,
|
||||
$dbuser,
|
||||
$dbpass,
|
||||
{RaiseError =>1});
|
||||
if ($dbh) {
|
||||
$pg_server_version = $dbh->{'pg_server_version'};
|
||||
if ($pg_server_version < (_PGMINI)) {
|
||||
$pg_server_version =~ /(\d)(\d){2,2}(\d){2,2}/;
|
||||
print "PostgreSQL Server version " . (_PGMINI) . " or above is needed. Current is $1.$2.$3 \n";
|
||||
exit 1;
|
||||
}
|
||||
print "yes\n";
|
||||
exit 0;
|
||||
} else {
|
||||
print "no Unable to access Database $dbname on host $dbhost as user $dbuser.\nError returned was: ". $DBI::errstr;
|
||||
exit 1;
|
||||
}
|
||||
} elsif ($ARGV[0] eq 'debug') {
|
||||
# Set debug flag
|
||||
$debug = 1;
|
||||
} elsif ($ARGV[0] eq 'config') {
|
||||
# Set config flag
|
||||
$configure = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ($configure) {
|
||||
print "graph_title PostgreSQL connections to $dbname\n";
|
||||
print "graph_vlabel Number / \${graph_period}\n";
|
||||
print "graph_category Postgresql \n";
|
||||
print "graph_info Connections to $dbname, sum=waiting+active\n";
|
||||
print "graph_args --base 1000\n";
|
||||
|
||||
print "waiting.label Waiting \n";
|
||||
print "waiting.draw AREA\n";
|
||||
print "waiting.type GAUGE\n";
|
||||
print "waiting.min 0\n";
|
||||
print "waiting.info Number of connections waiting for a lock to release\n";
|
||||
|
||||
print "active.label Active \n";
|
||||
print "active.draw STACK\n";
|
||||
print "active.type GAUGE\n";
|
||||
print "active.min 0\n";
|
||||
print "active.info Number of active connections \n";
|
||||
|
||||
print "idle.label Idle\n";
|
||||
print "idle.draw LINE\n";
|
||||
print "idle.type GAUGE\n";
|
||||
print "idle.min 0\n";
|
||||
print "idle.info Number of idle connections (including 'idle in transaction')\n";
|
||||
}
|
||||
else {
|
||||
print "# $dsn\n" if $debug;
|
||||
my $dbh = DBI->connect ($dsn,
|
||||
$dbuser,
|
||||
$dbpass,
|
||||
{RaiseError =>1});
|
||||
unless($dbh) {
|
||||
die ("no Unable to access Database $dbname on host $dbhost as user $dbuser.\nError returned was: ". $DBI::errstr."\n");
|
||||
}
|
||||
my $sql = "select count(*), waiting from pg_stat_activity ";
|
||||
$sql .= " where datname = ? group by waiting ";
|
||||
print "# $sql\n" if $debug;
|
||||
my $sth = $dbh->prepare($sql);
|
||||
$sth->execute($dbname);
|
||||
printf ("# Rows: %d\n", $sth->rows) if $debug;
|
||||
if ($sth->rows > 0) {
|
||||
my $c_waiting = 0;
|
||||
my $c_active = 0;
|
||||
while (my ($count, $waiting) = $sth->fetchrow_array()) {
|
||||
if ($waiting) {
|
||||
$c_waiting = $count;
|
||||
} else {
|
||||
$c_active = $count;
|
||||
}
|
||||
}
|
||||
print "waiting.value $c_waiting\n";
|
||||
print "active.value $c_active\n";
|
||||
}
|
||||
|
||||
$sql = "select count(*) from pg_stat_activity ";
|
||||
$sql .= " where datname = ? and current_query like '<IDLE>%'";
|
||||
print "# $sql\n" if $debug;
|
||||
$sth = $dbh->prepare($sql);
|
||||
$sth->execute($dbname);
|
||||
printf ("# Rows: %d\n", $sth->rows) if $debug;
|
||||
if ($sth->rows > 0) {
|
||||
my ($idle) = $sth->fetchrow_array();
|
||||
print "idle.value $idle\n";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
exit 0;
|
||||
|
129
config/munin/pg_newsblur_db_size
Executable file
129
config/munin/pg_newsblur_db_size
Executable file
|
@ -0,0 +1,129 @@
|
|||
#!/usr/bin/perl -w
|
||||
# Plugin to monitor database size.
|
||||
#
|
||||
# Copyright Dalibo <cedric.villemain@dalibo.com> 2007
|
||||
# Based on a plugin (postgres_block_read_) from Björn Ruberg <bjorn@linpro.no>
|
||||
#
|
||||
# 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__db_size \
|
||||
# /etc/munin/plugins/pg_<databasename>_db_size
|
||||
# This should, however, be given through autoconf and suggest.
|
||||
#
|
||||
# If required, give username, password and/or Postgresql server
|
||||
# host through environment variables.
|
||||
#
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# The config variables need to be write like this :
|
||||
# [pg_foobase*]
|
||||
# user foouser
|
||||
# env.dbname foobase
|
||||
#
|
||||
# Magic markers
|
||||
#%# family=auto
|
||||
#%# capabilities=autoconf
|
||||
|
||||
use strict;
|
||||
use DBI;
|
||||
use vars qw ( $debug $configure );
|
||||
use constant _PGMINI => 70400;
|
||||
|
||||
my $dbhost = $ENV{'dbhost'} || '';
|
||||
my $dbname = $ENV{'dbname'} || 'template1';
|
||||
my $dbuser = $ENV{'dbuser'} || 'postgres';
|
||||
my $dbport = $ENV{'dbport'} || '5432';
|
||||
my $dbpass = $ENV{'dbpass'} || '';
|
||||
my $statscope = $ENV{'statscope'} || 'user';
|
||||
|
||||
my $dsn = "DBI:Pg:dbname=$dbname";
|
||||
$dsn .=";host=$dbhost;port=$dbport" if $dbhost;
|
||||
my $pg_server_version;
|
||||
|
||||
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;
|
||||
}
|
||||
my $dbh = DBI->connect ($dsn,
|
||||
$dbuser,
|
||||
$dbpass,
|
||||
{RaiseError =>1});
|
||||
if ($dbh) {
|
||||
$pg_server_version = $dbh->{'pg_server_version'};
|
||||
if ($pg_server_version < (_PGMINI)) {
|
||||
$pg_server_version =~ /(\d)(\d){2,2}(\d){2,2}/;
|
||||
print "PostgreSQL Server version " . (_PGMINI) . " or above is needed. Current is $1.$2.$3 \n";
|
||||
exit 1;
|
||||
}
|
||||
print "yes\n";
|
||||
exit 0;
|
||||
} else {
|
||||
print "no Unable to access Database $dbname on host $dbhost as user $dbuser.\nError returned was: ". $DBI::errstr;
|
||||
exit 1;
|
||||
}
|
||||
} elsif ($ARGV[0] eq 'debug') {
|
||||
# Set debug flag
|
||||
$debug = 1;
|
||||
} elsif ($ARGV[0] eq 'config') {
|
||||
# Set config flag
|
||||
$configure = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ($configure) {
|
||||
print "graph_title $dbname database size\n";
|
||||
print "graph_vlabel Bytes\n";
|
||||
print "graph_category Postgresql \n";
|
||||
print "graph_args --base 1024\n";
|
||||
print "graph_info $dbname database size evolution\n";
|
||||
|
||||
print "db_size.label size\n";
|
||||
print "db_size.draw AREA\n";
|
||||
print "db_size.type GAUGE\n";
|
||||
print "db_size.min 0\n";
|
||||
print "db_size.info $dbname size\n";
|
||||
}
|
||||
else {
|
||||
print "# $dsn\n" if $debug;
|
||||
my $dbh = DBI->connect ($dsn,
|
||||
$dbuser,
|
||||
$dbpass,
|
||||
{RaiseError =>1});
|
||||
unless($dbh) {
|
||||
die ("no Unable to access Database $dbname on host $dbhost as user $dbuser.\nError returned was: ". $DBI::errstr."\n");
|
||||
}
|
||||
my $sql = "select pg_database_size(?);";
|
||||
print "# $sql\n" if $debug;
|
||||
my $sth = $dbh->prepare($sql);
|
||||
$sth->execute($dbname);
|
||||
printf ("# Rows: %d\n", $sth->rows) if $debug;
|
||||
if ($sth->rows > 0) {
|
||||
my ($db_size) = $sth->fetchrow_array();
|
||||
print "db_size.value $db_size\n";
|
||||
}
|
||||
}
|
||||
exit 0;
|
216
config/munin/pg_newsblur_locks
Executable file
216
config/munin/pg_newsblur_locks
Executable file
|
@ -0,0 +1,216 @@
|
|||
#!/usr/bin/perl -w
|
||||
# Plugin to monitor postgres locks.
|
||||
#
|
||||
# Copyright Dalibo <cedric.villemain@dalibo.com> 2007
|
||||
# Based on a plugin (postgres_block_read_) from Björn Ruberg <bjorn@linpro.no>
|
||||
#
|
||||
# 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__locks \
|
||||
# /etc/munin/plugins/pg_<databasename>_locks
|
||||
# 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/8.1/interactive/monitoring-locks.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.
|
||||
#
|
||||
# The config variables need to be write like this :
|
||||
# [pg_foobase*]
|
||||
# user foouser
|
||||
# env.dbname foobase
|
||||
#
|
||||
# Magic markers
|
||||
#%# family=auto
|
||||
#%# capabilities=autoconf
|
||||
|
||||
use strict;
|
||||
use DBI;
|
||||
use vars qw ( $debug $configure );
|
||||
use constant _PGMINI => 70400;
|
||||
|
||||
my $dbhost = $ENV{'dbhost'} || '';
|
||||
my $dbname = $ENV{'dbname'} || 'template1';
|
||||
my $dbuser = $ENV{'dbuser'} || 'postgres';
|
||||
my $dbport = $ENV{'dbport'} || '5432';
|
||||
my $dbpass = $ENV{'dbpass'} || '';
|
||||
my $statscope = $ENV{'statscope'} || 'user';
|
||||
|
||||
my $dsn = "DBI:Pg:dbname=$dbname";
|
||||
$dsn .=";host=$dbhost;port=$dbport" if $dbhost;
|
||||
my $pg_server_version;
|
||||
|
||||
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;
|
||||
}
|
||||
my $dbh = DBI->connect ($dsn,
|
||||
$dbuser,
|
||||
$dbpass,
|
||||
{RaiseError =>1});
|
||||
if ($dbh) {
|
||||
$pg_server_version = $dbh->{'pg_server_version'};
|
||||
if ($pg_server_version < (_PGMINI)) {
|
||||
$pg_server_version =~ /(\d)(\d){2,2}(\d){2,2}/;
|
||||
print "PostgreSQL Server version " . (_PGMINI) . " or above is needed. Current is $1.$2.$3 \n";
|
||||
exit 1;
|
||||
}
|
||||
print "yes\n";
|
||||
exit 0;
|
||||
} else {
|
||||
print "no Unable to access Database $dbname on host $dbhost as user $dbuser.\nError returned was: ". $DBI::errstr;
|
||||
exit 1;
|
||||
}
|
||||
} elsif ($ARGV[0] eq 'debug') {
|
||||
# Set debug flag
|
||||
$debug = 1;
|
||||
} elsif ($ARGV[0] eq 'config') {
|
||||
# Set config flag
|
||||
$configure = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ($configure) {
|
||||
print "graph_title PostgresSQL locks for database $dbname\n";
|
||||
print "graph_info Show $dbname Postgresql locks\n";
|
||||
print "graph_vlabel Locks\n";
|
||||
print "graph_category Postgresql\n";
|
||||
print "graph_args --base 1000\n";
|
||||
|
||||
print "accessshare.label Access Share Lock\n";
|
||||
print "accessshare.draw LINE\n";
|
||||
print "accessshare.type GAUGE\n";
|
||||
print "accessshare.min 0\n";
|
||||
print "accessshare.info Read only queries\n";
|
||||
|
||||
print "rowshare.label Row Share Lock\n";
|
||||
print "rowshare.draw LINE\n";
|
||||
print "rowshare.type GAUGE\n";
|
||||
print "rowshare.min 0\n";
|
||||
print "rowshare.info SELECT FOR SHARE and SELECT FOR UPDATE locks\n";
|
||||
|
||||
print "rowexclusive.label Row Exclusive Lock\n";
|
||||
print "rowexclusive.draw LINE\n";
|
||||
print "rowexclusive.type GAUGE\n";
|
||||
print "rowexclusive.min 0\n";
|
||||
print "rowexclusive.info Write queries locks\n";
|
||||
|
||||
print "shareupdateexclusive.label Share Update Exclusive Lock\n";
|
||||
print "shareupdateexclusive.draw LINE\n";
|
||||
print "shareupdateexclusive.type GAUGE\n";
|
||||
print "shareupdateexclusive.min 0\n";
|
||||
print "shareupdateexclusive.info VACUUM, ANALYZE, CREATE INDEX CONCURRENTLY.\n";
|
||||
|
||||
print "share.label Share Lock\n";
|
||||
print "share.draw LINE\n";
|
||||
print "share.type GAUGE\n";
|
||||
print "share.min 0\n";
|
||||
print "share.info CREATE INDEX.\n";
|
||||
|
||||
print "sharerowexclusive.label Share Row Exclusive Lock\n";
|
||||
print "sharerowexclusive.draw LINE\n";
|
||||
print "sharerowexclusive.type GAUGE\n";
|
||||
print "sharerowexclusive.min 0\n";
|
||||
print "sharerowexclusive.info Locks from application.\n";
|
||||
|
||||
print "exclusive.label Exclusive Lock\n";
|
||||
print "exclusive.draw LINE\n";
|
||||
print "exclusive.type GAUGE\n";
|
||||
print "exclusive.min 0\n";
|
||||
print "exclusive.info Locks from application or some operation on system catalogs.\n";
|
||||
|
||||
print "accessexclusive.label Access Exclusive Lock\n";
|
||||
print "accessexclusive.draw LINE\n";
|
||||
print "accessexclusive.type GAUGE\n";
|
||||
print "accessexclusive.min 0\n";
|
||||
print "accessexclusive.info ALTER TABLE, DROP TABLE, TRUNCATE, REINDEX, CLUSTER, VACUUM FULL, LOCK TABLE.\n";
|
||||
} else {
|
||||
print "# $dsn\n" if $debug;
|
||||
my $dbh = DBI->connect ($dsn,
|
||||
$dbuser,
|
||||
$dbpass,
|
||||
{RaiseError =>1});
|
||||
unless($dbh) {
|
||||
die ("no Unable to access Database $dbname on host $dbhost as user $dbuser.\nError returned was: ". $DBI::errstr."\n");
|
||||
}
|
||||
my $sql="SELECT mode, count(mode) FROM pg_locks ";
|
||||
$sql .="where database = (select oid from pg_database where datname = ?) ";
|
||||
$sql .="group by mode";
|
||||
print "# $sql\n" if $debug;
|
||||
my $accessshare = 0;
|
||||
my $rowshare = 0;
|
||||
my $rowexclusive = 0;
|
||||
my $shareupdateexclusive = 0;
|
||||
my $share = 0;
|
||||
my $sharerowexclusive = 0;
|
||||
my $exclusive = 0;
|
||||
my $accessexclusive = 0;
|
||||
my $sth = $dbh->prepare ($sql);
|
||||
$sth->execute ($dbname);
|
||||
printf ("# Rows: %d\n", $sth->rows) if $debug;
|
||||
if ($sth->rows > 0) {
|
||||
while (my ($mode, $count) = $sth->fetchrow_array()) {
|
||||
if ($mode =~ /accesssharelock/i) {
|
||||
$accessshare += $count;
|
||||
} elsif ($mode =~ /rowsharelock/i){
|
||||
$rowshare += $count;
|
||||
} elsif ($mode =~ /rowexclusivelock/i){
|
||||
$rowexclusive += $count;
|
||||
} elsif ($mode =~ /shareupdateexclusivelock/i){
|
||||
$shareupdateexclusive += $count;
|
||||
} elsif ($mode =~ /sharelock/i){
|
||||
$share += $count;
|
||||
} elsif ($mode =~ /sharerowexclusivelock/i){
|
||||
$sharerowexclusive += $count;
|
||||
} elsif ($mode =~ /exclusivelock/i){
|
||||
$exclusive += $count;
|
||||
} elsif ($mode =~ /accessexclusivelock/i){
|
||||
$accessexclusive += $count;
|
||||
}
|
||||
}
|
||||
}
|
||||
print "accessshare.value $accessshare\n";
|
||||
print "rowshare.value $rowshare\n";
|
||||
print "rowexclusive.value $rowexclusive\n";
|
||||
print "shareupdateexclusive.value $shareupdateexclusive\n";
|
||||
print "share.value $share\n";
|
||||
print "sharerowexclusive.value $sharerowexclusive\n";
|
||||
print "exclusive.value $exclusive\n";
|
||||
print "accessexclusive.value $accessexclusive\n";
|
||||
}
|
||||
exit 0;
|
||||
|
||||
|
||||
|
179
config/munin/pg_newsblur_stat_bgwriter
Executable file
179
config/munin/pg_newsblur_stat_bgwriter
Executable file
|
@ -0,0 +1,179 @@
|
|||
#!/usr/bin/perl -w
|
||||
# Plugin to monitor pg_stat_bgwriter
|
||||
#
|
||||
# Copyright Dalibo <cedric.villemain@dalibo.com> 2008
|
||||
# Based on a plugin (postgres_block_read_) from Björn Ruberg <bjorn@linpro.no>
|
||||
#
|
||||
# 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__stat_bgwriter \
|
||||
# /etc/munin/plugins/pg_<databasename>_stat_bgwriter
|
||||
# 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/8.1/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;
|
||||
use DBI;
|
||||
use vars qw ( $debug $configure );
|
||||
use constant _PGMINI => 80300;
|
||||
|
||||
my $dbhost = $ENV{'dbhost'} || '';
|
||||
my $dbname = $ENV{'dbname'} || 'template1';
|
||||
my $dbuser = $ENV{'dbuser'} || 'postgres';
|
||||
my $dbport = $ENV{'dbport'} || '5432';
|
||||
my $dbpass = $ENV{'dbpass'} || '';
|
||||
my $statscope = $ENV{'statscope'} || 'user';
|
||||
|
||||
my $dsn = "DBI:Pg:dbname=$dbname";
|
||||
$dsn .=";host=$dbhost;port=$dbport" if $dbhost;
|
||||
my $pg_server_version;
|
||||
|
||||
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;
|
||||
}
|
||||
my $dbh = DBI->connect ($dsn,
|
||||
$dbuser,
|
||||
$dbpass,
|
||||
{RaiseError =>1});
|
||||
if ($dbh) {
|
||||
$pg_server_version = $dbh->{'pg_server_version'};
|
||||
if ($pg_server_version < (_PGMINI)) {
|
||||
$pg_server_version =~ /(\d)(\d){2,2}(\d){2,2}/;
|
||||
print "PostgreSQL Server version " . (_PGMINI) . " or above is needed. Current is $1.$2.$3 \n";
|
||||
exit 1;
|
||||
}
|
||||
print "yes\n";
|
||||
exit 0;
|
||||
} else {
|
||||
print "no Unable to access Database $dbname on host $dbhost as user $dbuser.\nError returned was: ". $DBI::errstr;
|
||||
exit 1;
|
||||
}
|
||||
} elsif ($ARGV[0] eq 'debug') {
|
||||
# Set debug flag
|
||||
$debug = 1;
|
||||
} elsif ($ARGV[0] eq 'config') {
|
||||
# Set config flag
|
||||
$configure = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ($configure) {
|
||||
print "graph_title PostgreSQL stat bgwriter\n";
|
||||
print "graph_vlabel Number / \${graph_period}\n";
|
||||
print "graph_category Postgresql \n";
|
||||
print "graph_args --base 1000\n";
|
||||
|
||||
print "checkpoints_timed.label Checkpoints issued because of checkpoint_timeout\n";
|
||||
print "checkpoints_timed.draw LINE\n";
|
||||
print "checkpoints_timed.type DERIVE\n";
|
||||
print "checkpoints_timed.min 0\n";
|
||||
print "checkpoints_timed.graph_info Number of scheduled checkpoints\n";
|
||||
|
||||
print "checkpoints_req.label Checkpoint issued by request\n";
|
||||
print "checkpoints_req.draw LINE\n";
|
||||
print "checkpoints_req.type DERIVE\n";
|
||||
print "checkpoints_req.min 0\n";
|
||||
print "checkpoints_req.graph_info Number of requested checkpoint\n";
|
||||
|
||||
print "buffers_checkpoint.label Buffers write when checkpoint occured\n";
|
||||
print "buffers_checkpoint.draw LINE\n";
|
||||
print "buffers_checkpoint.type DERIVE\n";
|
||||
print "buffers_checkpoint.min 0\n";
|
||||
print "buffers_checkpoint.graph_info Number of buffers written when checkpoint \n";
|
||||
|
||||
print "buffers_clean.label Buffers write for cleaning\n";
|
||||
print "buffers_clean.draw LINE\n";
|
||||
print "buffers_clean.type DERIVE\n";
|
||||
print "buffers_clean.min 0\n";
|
||||
print "buffers_clean.graph_info Number of buffers written when cleaning\n";
|
||||
|
||||
print "maxwritten_clean.label Times cleaning scan is stopped because exceed bgwriter_lru_maxpages\n";
|
||||
print "maxwritten_clean.draw LINE\n";
|
||||
print "maxwritten_clean.type DERIVE\n";
|
||||
print "maxwritten_clean.min 0\n";
|
||||
print "maxwritten_clean.graph_info Number of stop in cleaning\n";
|
||||
|
||||
print "buffers_backend.label Number of buffers written by backends\n";
|
||||
print "buffers_backend.draw LINE\n";
|
||||
print "buffers_backend.type DERIVE\n";
|
||||
print "buffers_backend.min 0\n";
|
||||
print "buffers_backend.graph_info Number of buffers written by backends\n";
|
||||
|
||||
print "buffers_alloc.label Total number of buffers allocated\n";
|
||||
print "buffers_alloc.draw LINE\n";
|
||||
print "buffers_alloc.type DERIVE\n";
|
||||
print "buffers_alloc.min 0\n";
|
||||
print "buffers_alloc.graph_info Total number of buffers allocated\n";
|
||||
} else {
|
||||
print "# $dsn\n" if $debug;
|
||||
my $dbh = DBI->connect ($dsn,
|
||||
$dbuser,
|
||||
$dbpass,
|
||||
{RaiseError =>1});
|
||||
die ("no Unable to access Database $dbname on host $dbhost as user $dbuser.\nError returned was: ". $DBI::errstr."\n")
|
||||
unless($dbh);
|
||||
$pg_server_version = $dbh->{'pg_server_version'};
|
||||
|
||||
my $sql = "select checkpoints_timed, checkpoints_req, ";
|
||||
$sql .= " buffers_checkpoint, buffers_clean, ";
|
||||
$sql .= " maxwritten_clean, buffers_backend, ";
|
||||
$sql .= " buffers_alloc ";
|
||||
$sql .= "from pg_stat_bgwriter;";
|
||||
print "# $sql\n" if $debug;
|
||||
my $sth = $dbh->prepare($sql);
|
||||
$sth->execute();
|
||||
printf ("# Rows: %d\n", $sth->rows) if $debug;
|
||||
if ($sth->rows > 0) {
|
||||
my ($checkpoints_timed, $checkpoints_req, $buffers_checkpoint, $buffers_clean, $maxwritten_clean, $buffers_backend, $buffers_alloc) = $sth->fetchrow_array();
|
||||
print "checkpoints_timed.value $checkpoints_timed\n";
|
||||
print "checkpoints_req.value $checkpoints_req\n";
|
||||
print "buffers_checkpoint.value $buffers_checkpoint\n";
|
||||
print "buffers_clean.value $buffers_clean\n";
|
||||
print "maxwritten_clean.value $maxwritten_clean\n";
|
||||
print "buffers_backend.value $buffers_backend\n";
|
||||
print "buffers_alloc.value $buffers_alloc\n";
|
||||
}
|
||||
}
|
||||
|
||||
exit 0;
|
||||
|
201
config/munin/pg_newsblur_stat_database
Executable file
201
config/munin/pg_newsblur_stat_database
Executable file
|
@ -0,0 +1,201 @@
|
|||
#!/usr/bin/perl -w
|
||||
# Plugin to monitor pg_stat_database
|
||||
#
|
||||
# Copyright Dalibo <cedric.villemain@dalibo.com> 2007
|
||||
# Based on a plugin (postgres_block_read_) from Björn Ruberg <bjorn@linpro.no>
|
||||
#
|
||||
# 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__stat_database \
|
||||
# /etc/munin/plugins/pg_<databasename>_stat_database
|
||||
# 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/8.1/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;
|
||||
use DBI;
|
||||
use vars qw ( $debug $configure );
|
||||
use constant _PGMINI => 70400;
|
||||
|
||||
my $dbhost = $ENV{'dbhost'} || '';
|
||||
my $dbname = $ENV{'dbname'} || 'template1';
|
||||
my $dbuser = $ENV{'dbuser'} || 'postgres';
|
||||
my $dbport = $ENV{'dbport'} || '5432';
|
||||
my $dbpass = $ENV{'dbpass'} || '';
|
||||
|
||||
my $dsn = "DBI:Pg:dbname=$dbname";
|
||||
$dsn .=";host=$dbhost;port=$dbport" if $dbhost;
|
||||
my $pg_server_version;
|
||||
|
||||
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;
|
||||
}
|
||||
my $dbh = DBI->connect ($dsn,
|
||||
$dbuser,
|
||||
$dbpass,
|
||||
{RaiseError =>1});
|
||||
if ($dbh) {
|
||||
$pg_server_version = $dbh->{'pg_server_version'};
|
||||
if ($pg_server_version < (_PGMINI)) {
|
||||
$pg_server_version =~ /(\d)(\d){2,2}(\d){2,2}/;
|
||||
print "PostgreSQL Server version " . (_PGMINI) . " or above is needed. Current is $1.$2.$3 \n";
|
||||
exit 1;
|
||||
}
|
||||
print "yes\n";
|
||||
exit 0;
|
||||
} else {
|
||||
print "no Unable to access Database $dbname on host $dbhost as user $dbuser.\nError returned was: ". $DBI::errstr;
|
||||
exit 1;
|
||||
}
|
||||
} elsif ($ARGV[0] eq 'debug') {
|
||||
# Set debug flag
|
||||
$debug = 1;
|
||||
} elsif ($ARGV[0] eq 'config') {
|
||||
# Set config flag
|
||||
$configure = 1;
|
||||
}
|
||||
}
|
||||
|
||||
print "# $dsn\n" if $debug;
|
||||
my $dbh = DBI->connect ($dsn,
|
||||
$dbuser,
|
||||
$dbpass,
|
||||
{RaiseError =>1});
|
||||
|
||||
die ("no Unable to access Database $dbname on host $dbhost as user $dbuser.\nError returned was: ". $DBI::errstr."\n") unless($dbh);
|
||||
$pg_server_version = $dbh->{'pg_server_version'};
|
||||
|
||||
if ($configure) {
|
||||
print "graph_title PostgreSQL stat for database $dbname\n";
|
||||
print "graph_vlabel Number / \${graph_period}\n";
|
||||
print "graph_info Data from pg_stat_database.\n";
|
||||
print "graph_category Postgresql \n";
|
||||
print "graph_args --base 1000\n";
|
||||
|
||||
print "xact_commit.label Commits\n";
|
||||
print "xact_commit.graph no\n";
|
||||
print "xact_commit.draw LINE\n";
|
||||
print "xact_commit.type DERIVE\n";
|
||||
print "xact_commit.min 0\n";
|
||||
print "xact_commit.info Xact committed\n";
|
||||
print "xact_rollback.label Rollbacks\n";
|
||||
print "xact_rollback.draw LINE\n";
|
||||
print "xact_rollback.type DERIVE\n";
|
||||
print "xact_rollback.min 0\n";
|
||||
print "xact_rollback.negative xact_commit\n";
|
||||
print "xact_rollback.info Xact rollbacked\n";
|
||||
|
||||
print "blks_read.label Blocks Read\n";
|
||||
print "blks_read.graph no\n";
|
||||
print "blks_read.draw LINE\n";
|
||||
print "blks_read.type DERIVE\n";
|
||||
print "blks_read.min 0\n";
|
||||
print "blks_read.info Blocks read\n";
|
||||
print "blks_hit.label Blocks Hit\n";
|
||||
print "blks_hit.draw LINE\n";
|
||||
print "blks_hit.type DERIVE\n";
|
||||
print "blks_hit.min 0\n";
|
||||
print "blks_hit.negative blks_read\n";
|
||||
print "blks_hit.info Blocks hit\n";
|
||||
|
||||
if ($pg_server_version > 80300) {
|
||||
print "tup_returned.label Tuples returned \n";
|
||||
print "tup_returned.draw LINE\n";
|
||||
print "tup_returned.type DERIVE\n";
|
||||
print "tup_returned.min 0\n";
|
||||
print "tup_returned.info Number of tuple returned\n";
|
||||
|
||||
print "tup_fetched.label Tuples fetched \n";
|
||||
print "tup_fetched.draw LINE\n";
|
||||
print "tup_fetched.type DERIVE\n";
|
||||
print "tup_fetched.min 0\n";
|
||||
print "tup_fetched.info Number of tuple fetched\n";
|
||||
|
||||
print "tup_inserted.label Tuples inserted \n";
|
||||
print "tup_inserted.draw LINE\n";
|
||||
print "tup_inserted.type DERIVE\n";
|
||||
print "tup_inserted.min 0\n";
|
||||
print "tup_inserted.info Number of tuple inserted\n";
|
||||
|
||||
print "tup_updated.label Tuples updated\n";
|
||||
print "tup_updated.draw LINE\n";
|
||||
print "tup_updated.type DERIVE\n";
|
||||
print "tup_updated.min 0\n";
|
||||
print "tup_updated.info Number of tuple updated\n";
|
||||
|
||||
print "tup_deleted.label Tuples deleted\n";
|
||||
print "tup_deleted.draw LINE\n";
|
||||
print "tup_deleted.type DERIVE\n";
|
||||
print "tup_deleted.min 0\n";
|
||||
print "tup_deleted.info Number of tuple deleted\n";
|
||||
}
|
||||
}
|
||||
else {
|
||||
my $sql = "select xact_commit, xact_rollback, ";
|
||||
$sql .= " blks_read, blks_hit ";
|
||||
if ($pg_server_version > 80300){
|
||||
$sql .= ", tup_returned, tup_fetched, tup_inserted, tup_updated, tup_deleted ";
|
||||
}
|
||||
$sql .= " from pg_stat_database where datname=?";
|
||||
print "# $sql\n" if $debug;
|
||||
my $sth = $dbh->prepare($sql);
|
||||
$sth->execute($dbname);
|
||||
printf ("# Rows: %d\n", $sth->rows) if $debug;
|
||||
if ($sth->rows > 0) {
|
||||
my ($xact_commit, $xact_rollback, $blks_read, $blks_hit, $tup_returned, $tup_fetched, $tup_inserted, $tup_updated, $tup_deleted) = $sth->fetchrow_array();
|
||||
print "xact_commit.value $xact_commit\n";
|
||||
print "xact_rollback.value $xact_rollback\n";
|
||||
print "blks_read.value $blks_read\n";
|
||||
print "blks_hit.value $blks_hit\n";
|
||||
if ($pg_server_version > 80300){
|
||||
print "tup_returned.value $tup_returned\n";
|
||||
print "tup_fetched.value $tup_fetched\n";
|
||||
print "tup_inserted.value $tup_inserted\n";
|
||||
print "tup_updated.value $tup_updated\n";
|
||||
print "tup_deleted.value $tup_deleted\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exit 0;
|
||||
|
208
config/munin/pg_newsblur_stat_tables
Executable file
208
config/munin/pg_newsblur_stat_tables
Executable file
|
@ -0,0 +1,208 @@
|
|||
#!/usr/bin/perl -w
|
||||
# Plugin to monitor pg_stat_*_tables (user by default)
|
||||
#
|
||||
# Copyright Dalibo <cedric.villemain@dalibo.com> 2007
|
||||
# Based on a plugin (postgres_block_read_) from Björn Ruberg <bjorn@linpro.no>
|
||||
#
|
||||
# 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__stat_tables \
|
||||
# /etc/munin/plugins/pg_<databasename>_stat_tables
|
||||
# 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/8.1/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;
|
||||
use DBI;
|
||||
use vars qw ( $debug $configure );
|
||||
use constant _PGMINI => 70400;
|
||||
|
||||
my $dbhost = $ENV{'dbhost'} || '';
|
||||
my $dbname = $ENV{'dbname'} || 'template1';
|
||||
my $dbuser = $ENV{'dbuser'} || 'postgres';
|
||||
my $dbport = $ENV{'dbport'} || '5432';
|
||||
my $dbpass = $ENV{'dbpass'} || '';
|
||||
my $statscope = $ENV{'statscope'} || 'user';
|
||||
|
||||
my $dsn = "DBI:Pg:dbname=$dbname";
|
||||
$dsn .=";host=$dbhost;port=$dbport" if $dbhost;
|
||||
my $pg_server_version;
|
||||
|
||||
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;
|
||||
}
|
||||
my $dbh = DBI->connect ($dsn,
|
||||
$dbuser,
|
||||
$dbpass,
|
||||
{RaiseError =>1});
|
||||
if ($dbh) {
|
||||
$pg_server_version = $dbh->{'pg_server_version'};
|
||||
if ($pg_server_version < (_PGMINI)) {
|
||||
$pg_server_version =~ /(\d)(\d){2,2}(\d){2,2}/;
|
||||
print "PostgreSQL Server version " . (_PGMINI) . " or above is needed. Current is $1.$2.$3 \n";
|
||||
exit 1;
|
||||
}
|
||||
print "yes\n";
|
||||
exit 0;
|
||||
} else {
|
||||
print "no Unable to access Database $dbname on host $dbhost as user $dbuser.\nError returned was: ". $DBI::errstr;
|
||||
exit 1;
|
||||
}
|
||||
} elsif ($ARGV[0] eq 'debug') {
|
||||
# Set debug flag
|
||||
$debug = 1;
|
||||
} elsif ($ARGV[0] eq 'config') {
|
||||
# Set config flag
|
||||
$configure = 1;
|
||||
}
|
||||
}
|
||||
|
||||
print "# $dsn\n" if $debug;
|
||||
my $dbh = DBI->connect ($dsn,
|
||||
$dbuser,
|
||||
$dbpass,
|
||||
{RaiseError =>1});
|
||||
|
||||
die ("no Unable to access Database $dbname on host $dbhost as user $dbuser.\nError returned was: ". $DBI::errstr."\n") unless($dbh);
|
||||
$pg_server_version = $dbh->{'pg_server_version'};
|
||||
|
||||
if ($configure) {
|
||||
print "graph_title PostgreSQL stat $statscope tables from $dbname\n";
|
||||
print "graph_vlabel Number / \${graph_period}\n";
|
||||
print "graph_info Scan, fetch, insertion, deletion, updates ... all except analyze and vacuum last execution date.\n";
|
||||
print "graph_category Postgresql \n";
|
||||
print "graph_args --base 1000\n";
|
||||
|
||||
print "seq_scan.label Sequential scans initiated\n";
|
||||
print "seq_scan.draw LINE\n";
|
||||
print "seq_scan.type DERIVE\n";
|
||||
print "seq_scan.min 0\n";
|
||||
print "seq_scan.info Number of sequential scans initiated\n";
|
||||
|
||||
print "seq_tup_read.label Sequential tuple read\n";
|
||||
print "seq_tup_read.draw LINE\n";
|
||||
print "seq_tup_read.type DERIVE\n";
|
||||
print "seq_tup_read.min 0\n";
|
||||
print "seq_tup_read.info Number of tuple fetch\n";
|
||||
|
||||
print "idx_scan.label Index scans initiated\n";
|
||||
print "idx_scan.draw LINE\n";
|
||||
print "idx_scan.type DERIVE\n";
|
||||
print "idx_scan.min 0\n";
|
||||
print "idx_scan.info Number of index scans initiated\n";
|
||||
|
||||
print "idx_tup_fetch.label Index tuple fetch\n";
|
||||
print "idx_tup_fetch.draw LINE\n";
|
||||
print "idx_tup_fetch.type DERIVE\n";
|
||||
print "idx_tup_fetch.min 0\n";
|
||||
print "idx_tup_fetch.info Number of index tuple fetch\n";
|
||||
|
||||
print "n_tup_ins.label Tuples inserted \n";
|
||||
print "n_tup_ins.draw LINE\n";
|
||||
print "n_tup_ins.type DERIVE\n";
|
||||
print "n_tup_ins.min 0\n";
|
||||
print "n_tup_ins.info Number of tuple inserted\n";
|
||||
|
||||
print "n_tup_upd.label Tuples updated\n";
|
||||
print "n_tup_upd.draw LINE\n";
|
||||
print "n_tup_upd.type DERIVE\n";
|
||||
print "n_tup_upd.min 0\n";
|
||||
print "n_tup_upd.info Number of tuple updated\n";
|
||||
|
||||
print "n_tup_del.label Tuples deleted\n";
|
||||
print "n_tup_del.draw LINE\n";
|
||||
print "n_tup_del.type DERIVE\n";
|
||||
print "n_tup_del.min 0\n";
|
||||
print "n_tup_del.info Number of tuple deleted\n";
|
||||
|
||||
if ($pg_server_version > 80300) {
|
||||
print "n_tup_hot_upd.label Rows updated using HOT\n";
|
||||
print "n_tup_hot_upd.draw LINE\n";
|
||||
print "n_tup_hot_upd.type DERIVE\n";
|
||||
print "n_tup_hot_upd.min 0\n";
|
||||
print "n_tup_hot_upd.info Number of row updated by HOT\n";
|
||||
|
||||
print "n_live_tup.label Rows alive\n";
|
||||
print "n_live_tup.draw LINE\n";
|
||||
print "n_live_tup.type DERIVE\n";
|
||||
print "n_live_tup.min 0\n";
|
||||
print "n_live_tup.info Number of live row\n";
|
||||
|
||||
print "n_dead_tup.label Rows dead\n";
|
||||
print "n_dead_tup.draw LINE\n";
|
||||
print "n_dead_tup.type DERIVE\n";
|
||||
print "n_dead_tup.min 0\n";
|
||||
print "n_dead_tup.info Number of dead row\n";
|
||||
}
|
||||
} else {
|
||||
|
||||
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) ";
|
||||
if ($pg_server_version > 80300){
|
||||
$sql .= ", sum(n_tup_hot_upd), sum(n_live_tup), sum(n_dead_tup) ";
|
||||
}
|
||||
$sql .= " from pg_stat_".$statscope."_tables;";
|
||||
print "# $sql\n" if $debug;
|
||||
my $sth = $dbh->prepare($sql);
|
||||
$sth->execute();
|
||||
printf ("# Rows: %d\n", $sth->rows) if $debug;
|
||||
if ($sth->rows > 0) {
|
||||
my ($seq_scan, $seq_tup_read, $idx_scan, $idx_tup_fetch, $n_tup_ins, $n_tup_upd, $n_tup_del, $n_tup_hot_upd, $n_live_tup, $n_dead_tup) = $sth->fetchrow_array();
|
||||
print "seq_scan.value $seq_scan\n";
|
||||
print "seq_tup_read.value $seq_tup_read\n";
|
||||
print "idx_scan.value $idx_scan\n";
|
||||
print "idx_tup_fetch.value $idx_tup_fetch\n";
|
||||
print "n_tup_ins.value $n_tup_ins\n";
|
||||
print "n_tup_upd.value $n_tup_upd\n";
|
||||
print "n_tup_del.value $n_tup_del\n";
|
||||
if ($pg_server_version > 80300){
|
||||
print "n_tup_hot_upd.value $n_tup_hot_upd\n";
|
||||
print "n_live_tup.value $n_live_tup\n";
|
||||
print "n_dead_tup.value $n_dead_tup\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exit 0;
|
||||
|
195
config/munin/pg_newsblur_statio_tables
Executable file
195
config/munin/pg_newsblur_statio_tables
Executable file
|
@ -0,0 +1,195 @@
|
|||
#!/usr/bin/perl -w
|
||||
# Plugin to monitor pg_statio_*_tables (user by default)
|
||||
#
|
||||
# Copyright Dalibo <cedric.villemain@dalibo.com> 2007
|
||||
# Based on a plugin (postgres_block_read_) from Björn Ruberg <bjorn@linpro.no>
|
||||
#
|
||||
# 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__statio_tables \
|
||||
# /etc/munin/plugins/pg_<databasename>_statio_tables
|
||||
# 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/8.1/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;
|
||||
use DBI;
|
||||
use vars qw ( $debug $configure );
|
||||
use constant _PGMINI => 70400;
|
||||
|
||||
my $dbhost = $ENV{'dbhost'} || '';
|
||||
my $dbname = $ENV{'dbname'} || 'template1';
|
||||
my $dbuser = $ENV{'dbuser'} || 'postgres';
|
||||
my $dbport = $ENV{'dbport'} || '5432';
|
||||
my $dbpass = $ENV{'dbpass'} || '';
|
||||
my $statscope = $ENV{'statscope'} || 'user';
|
||||
|
||||
my $dsn = "DBI:Pg:dbname=$dbname";
|
||||
$dsn .=";host=$dbhost;port=$dbport" if $dbhost;
|
||||
my $pg_server_version;
|
||||
|
||||
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;
|
||||
}
|
||||
my $dbh = DBI->connect ($dsn,
|
||||
$dbuser,
|
||||
$dbpass,
|
||||
{RaiseError =>1});
|
||||
if ($dbh) {
|
||||
$pg_server_version = $dbh->{'pg_server_version'};
|
||||
if ($pg_server_version < (_PGMINI)) {
|
||||
$pg_server_version =~ /(\d)(\d){2,2}(\d){2,2}/;
|
||||
print "PostgreSQL Server version " . (_PGMINI) . " or above is needed. Current is $1.$2.$3 \n";
|
||||
exit 1;
|
||||
}
|
||||
print "yes\n";
|
||||
exit 0;
|
||||
} else {
|
||||
print "no Unable to access Database $dbname on host $dbhost as user $dbuser.\nError returned was: ". $DBI::errstr;
|
||||
exit 1;
|
||||
}
|
||||
} elsif ($ARGV[0] eq 'debug') {
|
||||
# Set debug flag
|
||||
$debug = 1;
|
||||
} elsif ($ARGV[0] eq 'config') {
|
||||
# Set config flag
|
||||
$configure = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ($configure) {
|
||||
print "graph_title PostgreSQL statio $statscope tables from $dbname\n";
|
||||
print "graph_info Read from memory and from disk for indexes, tables, toasted indexes and toasted tables\n";
|
||||
print "graph_vlabel Read from disk | Read from memory\n/\${graph_period}\n";
|
||||
print "graph_category Postgresql \n";
|
||||
print "graph_args --base 1000\n";
|
||||
|
||||
print "heap_blks_read.label Heap block read\n";
|
||||
print "heap_blks_read.graph no\n";
|
||||
print "heap_blks_read.draw LINE\n";
|
||||
print "heap_blks_read.type DERIVE\n";
|
||||
print "heap_blks_read.min 0\n";
|
||||
print "heap_blks_read.info Number of heap block read\n";
|
||||
|
||||
print "heap_blks_hit.label Heap\n";
|
||||
print "heap_blks_hit.negative heap_blks_read\n";
|
||||
print "heap_blks_hit.draw LINE\n";
|
||||
print "heap_blks_hit.type DERIVE\n";
|
||||
print "heap_blks_hit.min 0\n";
|
||||
print "heap_blks_hit.info Number of heap block read/hit\n";
|
||||
|
||||
print "idx_blks_read.label Index block read\n";
|
||||
print "idx_blks_read.graph no\n";
|
||||
print "idx_blks_read.draw LINE\n";
|
||||
print "idx_blks_read.type DERIVE\n";
|
||||
print "idx_blks_read.min 0\n";
|
||||
print "idx_blks_read.info Number of index block read\n";
|
||||
|
||||
print "idx_blks_hit.label Index\n";
|
||||
print "idx_blks_hit.negative idx_blks_read\n";
|
||||
print "idx_blks_hit.draw LINE\n";
|
||||
print "idx_blks_hit.type DERIVE\n";
|
||||
print "idx_blks_hit.min 0\n";
|
||||
print "idx_blks_hit.info Number of index block read/hit\n";
|
||||
|
||||
print "toast_blks_read.label Toasted block read\n";
|
||||
print "toast_blks_read.graph no\n";
|
||||
print "toast_blks_read.draw LINE\n";
|
||||
print "toast_blks_read.type DERIVE\n";
|
||||
print "toast_blks_read.min 0\n";
|
||||
print "toast_blks_read.info Number of toasted block read\n";
|
||||
|
||||
print "toast_blks_hit.label Toasted\n";
|
||||
print "toast_blks_hit.negative toast_blks_read\n";
|
||||
print "toast_blks_hit.draw LINE\n";
|
||||
print "toast_blks_hit.type DERIVE\n";
|
||||
print "toast_blks_hit.min 0\n";
|
||||
print "toast_blks_hit.info Number of toasted block read/hit\n";
|
||||
|
||||
print "tidx_blks_read.label Toasted index block read\n";
|
||||
print "tidx_blks_read.graph no\n";
|
||||
print "tidx_blks_read.draw LINE\n";
|
||||
print "tidx_blks_read.type DERIVE\n";
|
||||
print "tidx_blks_read.min 0\n";
|
||||
print "tidx_blks_read.info Number of toasted index block read\n";
|
||||
|
||||
print "tidx_blks_hit.label Toasted index\n";
|
||||
print "tidx_blks_hit.negative tidx_blks_read\n";
|
||||
print "tidx_blks_hit.draw LINE\n";
|
||||
print "tidx_blks_hit.type DERIVE\n";
|
||||
print "tidx_blks_hit.min 0\n";
|
||||
print "tidx_blks_hit.info Number of toasted index block read/hit\n";
|
||||
}
|
||||
else {
|
||||
print "# $dsn\n" if $debug;
|
||||
my $dbh = DBI->connect ($dsn,
|
||||
$dbuser,
|
||||
$dbpass,
|
||||
{RaiseError =>1});
|
||||
die ("no Unable to access Database $dbname on host $dbhost as user $dbuser.\nError returned was: ". $DBI::errstr."\n")
|
||||
unless($dbh);
|
||||
|
||||
my $sql = "select sum(heap_blks_read), sum(heap_blks_hit), ";
|
||||
$sql .= " sum(idx_blks_read), sum(idx_blks_hit), ";
|
||||
$sql .= " sum(toast_blks_read), sum(toast_blks_hit), ";
|
||||
$sql .= " sum(tidx_blks_read), sum(tidx_blks_hit) ";
|
||||
$sql .= "from pg_statio_" . $statscope . "_tables;";
|
||||
print "# $sql\n" if $debug;
|
||||
my $sth = $dbh->prepare($sql);
|
||||
$sth->execute();
|
||||
printf ("# Rows: %d\n", $sth->rows) if $debug;
|
||||
if ($sth->rows > 0) {
|
||||
my ($heap_blks_read, $heap_blks_hit, $idx_blks_read, $idx_blks_hit, $toast_blks_read, $toast_blks_hit, $tidx_blks_read, $tidx_blks_hit) = $sth->fetchrow_array();
|
||||
print "heap_blks_read.value $heap_blks_read\n";
|
||||
print "heap_blks_hit.value $heap_blks_hit\n";
|
||||
print "idx_blks_read.value $idx_blks_read\n";
|
||||
print "idx_blks_hit.value $idx_blks_hit\n";
|
||||
print "toast_blks_read.value $toast_blks_read\n";
|
||||
print "toast_blks_hit.value $toast_blks_hit\n";
|
||||
print "tidx_blks_read.value $tidx_blks_read\n";
|
||||
print "tidx_blks_hit.value $tidx_blks_hit\n";
|
||||
}
|
||||
}
|
||||
|
||||
exit 0;
|
||||
|
28
fabfile.py
vendored
28
fabfile.py
vendored
|
@ -43,7 +43,8 @@ env.roledefs ={
|
|||
'db03.newsblur.com',
|
||||
'db04.newsblur.com',
|
||||
'db05.newsblur.com',
|
||||
'db06.newsblur.com'],
|
||||
'db06.newsblur.com',
|
||||
'db07.newsblur.com'],
|
||||
'task': ['task01.newsblur.com',
|
||||
'task02.newsblur.com',
|
||||
'task03.newsblur.com',
|
||||
|
@ -385,11 +386,20 @@ def config_pgbouncer():
|
|||
put('config/pgbouncer.conf', '/etc/pgbouncer/pgbouncer.ini', use_sudo=True)
|
||||
put('config/pgbouncer_userlist.txt', '/etc/pgbouncer/userlist.txt', use_sudo=True)
|
||||
sudo('echo "START=1" > /etc/default/pgbouncer')
|
||||
sudo('/etc/init.d/pgbouncer stop')
|
||||
sudo('su postgres -c "/etc/init.d/pgbouncer stop"', pty=False)
|
||||
with settings(warn_only=True):
|
||||
sudo('pkill pgbouncer')
|
||||
run('sleep 2')
|
||||
sudo('/etc/init.d/pgbouncer start')
|
||||
sudo('/etc/init.d/pgbouncer start', pty=False)
|
||||
|
||||
def bounce_pgbouncer():
|
||||
sudo('su postgres -c "/etc/init.d/pgbouncer stop"', pty=False)
|
||||
run('sleep 4')
|
||||
with settings(warn_only=True):
|
||||
sudo('pkill pgbouncer')
|
||||
run('sleep 4')
|
||||
run('sudo /etc/init.d/pgbouncer start', pty=False)
|
||||
run('sleep 2')
|
||||
|
||||
def config_monit():
|
||||
put('config/monit.conf', '/etc/monit/conf.d/celery.conf', use_sudo=True)
|
||||
|
@ -440,7 +450,7 @@ def setup_sudoers():
|
|||
sudo('su - root -c "echo \\\\"%s ALL=(ALL) NOPASSWD: ALL\\\\" >> /etc/sudoers"' % env.user)
|
||||
|
||||
def setup_nginx():
|
||||
NGINX_VERSION = '1.2.0'
|
||||
NGINX_VERSION = '1.2.2'
|
||||
with cd(env.VENDOR_PATH):
|
||||
with settings(warn_only=True):
|
||||
sudo("groupadd nginx")
|
||||
|
@ -592,6 +602,15 @@ def setup_postgres(standby=False):
|
|||
sudo('/etc/init.d/postgresql stop')
|
||||
sudo('/etc/init.d/postgresql start')
|
||||
|
||||
def copy_postgres_to_standby():
|
||||
slave = 'db02'
|
||||
# Make sure you can ssh from master to slave and back.
|
||||
# Need to give postgres accounts keys in authroized_keys.
|
||||
|
||||
sudo('su postgres -c "psql -c \\"SELECT pg_start_backup(\'label\', true)\\""', pty=False)
|
||||
sudo('su postgres -c \"rsync -a --stats --progress /var/lib/postgresql/9.1/main postgres@%s:/var/lib/postgresql/9.1/ --exclude postmaster.pid\"' % slave, pty=False)
|
||||
sudo('su postgres -c "psql -c \\"SELECT pg_stop_backup()\\""', pty=False)
|
||||
|
||||
def setup_mongo():
|
||||
sudo('apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10')
|
||||
# sudo('echo "deb http://downloads.mongodb.org/distros/ubuntu 10.10 10gen" >> /etc/apt/sources.list.d/10gen.list')
|
||||
|
@ -619,6 +638,7 @@ def setup_redis():
|
|||
|
||||
def setup_db_munin():
|
||||
sudo('cp -rs %s/config/munin/mongo* /etc/munin/plugins/' % env.NEWSBLUR_PATH)
|
||||
sudo('cp -rs %s/config/munin/pg_* /etc/munin/plugins/' % env.NEWSBLUR_PATH)
|
||||
|
||||
def enable_celerybeat():
|
||||
with cd(env.NEWSBLUR_PATH):
|
||||
|
|
|
@ -9,9 +9,9 @@
|
|||
|
||||
<h1>NewsBlur is upgrading...</h1>
|
||||
|
||||
<p>Upgrading PostgreSQL. It's Friday night (really, Saturday morning) at 12:20am. No more than 30 minutes. As little as 5 minutes.</p>
|
||||
<p>Moving PostgreSQL to a new server. It's Thursday night at 11:40pm. No more than 10 minutes. As little as 5 minutes.</p>
|
||||
|
||||
<p><b>UPDATE 12:57am</b>: OK, I lied. Turns out it took 30 minutes just to get the upgrade *started*. If you've ever upgraded postgresql, you know what a pain in the butt this can be. But it's going and now I'm just writing up maintenance posts for only a few dozen people to see. Go bother <a href="http://twitter.com/samuelclay">@samuelclay</a> for the next 10-15 minutes. :-)</p>
|
||||
<!-- <p><b>UPDATE 12:57am</b>: OK, I lied. Turns out it took 30 minutes just to get the upgrade *started*. If you've ever upgraded postgresql, you know what a pain in the butt this can be. But it's going and now I'm just writing up maintenance posts for only a few dozen people to see. Go bother <a href="http://twitter.com/samuelclay">@samuelclay</a> for the next 10-15 minutes. :-)</p> -->
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Add table
Reference in a new issue