#!/usr/bin/perl -w # -*- perl -*- # use strict; use DBI; my $dbhost = $ENV{'dbhost'} || ''; my $dbport = $ENV{'dbport'} || ''; my $dbname = $ENV{'dbname'} || 'template1'; my $dbuser = $ENV{'dbuser'} || 'postgres'; my $Con = "DBI:Pg:dbname=$dbname"; $Con .= ";host=$dbhost" if $dbhost; $Con .= ";port=$dbport" if $dbport; my $Dbh = DBI->connect ($Con, $dbuser,'',{RaiseError =>1}) || die "Unable to access Database $dbname on host $dbhost as user $dbuser.\nError returned was: ". $DBI::errstr; if ($ARGV[0] && $ARGV[0] eq 'config') { my $sql_max = "SHOW max_connections;"; my $sth_max = $Dbh->prepare($sql_max); $sth_max->execute(); my ($max_conn) = $sth_max->fetchrow(); my $warning = int ($max_conn * 0.7); my $critical = int ($max_conn * 0.8); print <prepare($sql_curr); $sth_curr->execute(); my ($curr_conn) = $sth_curr->fetchrow(); print "connections.value $curr_conn\n"; }