diff --git a/lib/Munin/Plugin/Pgsql.pm b/lib/Munin/Plugin/Pgsql.pm index 93c18c0c4..276d6564e 100644 --- a/lib/Munin/Plugin/Pgsql.pm +++ b/lib/Munin/Plugin/Pgsql.pm @@ -328,8 +328,8 @@ sub Config { } print "$l.min $self->{graphmin}\n" if (defined $self->{graphmin}); print "$l.max $self->{graphmax}\n" if (defined $self->{graphmax}); - print "$l.warning $self->{warning}\n" if (defined $self->{warning}); - print "$l.critical $self->{critical}\n" if (defined $self->{critical}); + $self->print_warning_critical("warning", $l); + $self->print_warning_critical("critical", $l); $firstrow = 0; } } @@ -629,4 +629,15 @@ sub wildcard_parameter { die "Wildcard base not found in called filename!\n"; } +sub print_warning_critical { + my ($self, $type, $key) = @_; + # enable overriding plugin default warning and critical with key specific env variables in plugin-conf.d + if (defined $ENV{$key."_".$type}) { + print "$key.$type ".$ENV{$key."_".$type}."\n"; + } + elsif (defined $self->{$type}) { + print "$key.$type $self->{$type}\n"; + } +} + 1; diff --git a/plugins/node.d/postgres_connections_ b/plugins/node.d/postgres_connections_ index f20f6b154..51c682cdc 100755 --- a/plugins/node.d/postgres_connections_ +++ b/plugins/node.d/postgres_connections_ @@ -35,6 +35,9 @@ database configuration. Example : [postgres_pg91_*] env.PGPORT 5432 + # warn when total connections reaches 900 and crit when we are at 1000, adjust according to your max connections + env.total_warning :900 + env.total_critical :1000 [postgres_pg92_*] env.PGPORT 5432 @@ -139,16 +142,29 @@ my $pg = Munin::Plugin::Pgsql->new( wildcardfilter => " AND datname=?", paramdatabase => 1, configquery => [ - "VALUES ('active','Active'),('waiting','Waiting for lock'),('idle','Idle'),('idletransaction','Idle in transaction'),('unknown','Unknown')", + "VALUES ('active','Active'),('waiting','Waiting for lock'),('idle','Idle'),('idletransaction','Idle in transaction'),('unknown','Unknown'),('total', 'Total')", [ 8.1, - "SELECT 'active','Active' UNION ALL SELECT 'idle','Idle' UNION ALL SELECT 'idletransaction','Idle in transaction' UNION ALL SELECT 'unknown','Unknown'", + "SELECT 'active','Active' UNION ALL SELECT 'idle','Idle' UNION ALL SELECT 'idletransaction','Idle in transaction' UNION ALL SELECT 'unknown','Unknown' UNION ALL SELECT 'total','Total'" , ], ], suggestquery => "SELECT datname FROM pg_database WHERE datallowconn AND NOT datistemplate AND NOT datname='postgres' UNION ALL SELECT 'ALL' ORDER BY 1", - graphdraw => 'AREA', - stack => 1, + graphdraw => ['AREA', 'STACK', 'STACK','STACK','STACK','LINE1'], + postprocess => \&CountTotal, + ); +sub CountTotal { + my $pgresult = shift; + my $total = 0; + my $result = []; + foreach my $row (@$pgresult) { + $total += $row->[1]; + push(@{$result}, $row); + } + push(@$result, ["total", $total]); + return $result; +} + $pg->Process();