source: trunk/packages/xvm-munin-config/master/usr/share/xvm-munin-master-config/plugins/postgres_connections @ 2665

Last change on this file since 2665 was 1761, checked in by broder, 16 years ago

Initial checkin of xvm-munin-config package

  • Property svn:executable set to *
File size: 1.3 KB
Line 
1#!/usr/bin/perl -w
2# -*- perl -*-
3#
4
5use strict;
6use DBI;
7
8my $dbhost = $ENV{'dbhost'} || '';
9my $dbport = $ENV{'dbport'} || '';
10my $dbname = $ENV{'dbname'} || 'template1';
11my $dbuser = $ENV{'dbuser'} || 'postgres';
12
13my $Con = "DBI:Pg:dbname=$dbname";
14$Con .= ";host=$dbhost" if $dbhost;
15$Con .= ";port=$dbport" if $dbport;
16my $Dbh = DBI->connect ($Con, $dbuser,'',{RaiseError =>1}) || 
17    die "Unable to access Database $dbname on host $dbhost as user $dbuser.\nError returned was: ". $DBI::errstr;
18
19if ($ARGV[0] && $ARGV[0] eq 'config') {
20    my $sql_max = "SHOW max_connections;";
21    my $sth_max = $Dbh->prepare($sql_max);
22    $sth_max->execute();
23    my ($max_conn) = $sth_max->fetchrow();
24    my $warning = int ($max_conn * 0.7);
25    my $critical = int ($max_conn * 0.8);
26    print <<EOF;
27graph_title Postgres active connections
28graph_args -l 0 --base 1000
29graph_vlabel Active connections
30graph_category Postgresql
31graph_info Shows active Postgresql connections
32connections.label Active connections
33connections.info Active connections
34connections.type GAUGE
35connections.warning $warning
36connections.critical $critical
37EOF
38} else {
39    my $sql_curr = "SELECT COUNT (*) FROM pg_stat_activity;";
40    my $sth_curr = $Dbh->prepare($sql_curr);
41    $sth_curr->execute();
42    my ($curr_conn) = $sth_curr->fetchrow();
43    print "connections.value $curr_conn\n";
44}
Note: See TracBrowser for help on using the repository browser.