Skip to content

postgres_connections_: enable warning and critical for total connections #1657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions lib/Munin/Plugin/Pgsql.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
24 changes: 20 additions & 4 deletions plugins/node.d/postgres_connections_
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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();