Skip to content
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

Aggregate pgbouncer statistics values by database #101

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
44 changes: 30 additions & 14 deletions check_postgres.pl
Original file line number Diff line number Diff line change
Expand Up @@ -2252,28 +2252,28 @@ sub finishup {
check_pgbouncer_checksum() if $action eq 'pgbouncer_checksum';

## Check the number of active clients in each pgbouncer pool
check_pgb_pool('cl_active') if $action eq 'pgb_pool_cl_active';
check_pgb_pool('cl_active', 'sum') if $action eq 'pgb_pool_cl_active';

## Check the number of waiting clients in each pgbouncer pool
check_pgb_pool('cl_waiting') if $action eq 'pgb_pool_cl_waiting';
check_pgb_pool('cl_waiting', 'sum') if $action eq 'pgb_pool_cl_waiting';

## Check the number of active server connections in each pgbouncer pool
check_pgb_pool('sv_active') if $action eq 'pgb_pool_sv_active';
check_pgb_pool('sv_active', 'sum') if $action eq 'pgb_pool_sv_active';

## Check the number of idle server connections in each pgbouncer pool
check_pgb_pool('sv_idle') if $action eq 'pgb_pool_sv_idle';
check_pgb_pool('sv_idle', 'sum') if $action eq 'pgb_pool_sv_idle';

## Check the number of used server connections in each pgbouncer pool
check_pgb_pool('sv_used') if $action eq 'pgb_pool_sv_used';
check_pgb_pool('sv_used', 'sum') if $action eq 'pgb_pool_sv_used';

## Check the number of tested server connections in each pgbouncer pool
check_pgb_pool('sv_tested') if $action eq 'pgb_pool_sv_tested';
check_pgb_pool('sv_tested', 'sum') if $action eq 'pgb_pool_sv_tested';

## Check the number of login server connections in each pgbouncer pool
check_pgb_pool('sv_login') if $action eq 'pgb_pool_sv_login';
check_pgb_pool('sv_login', 'sum') if $action eq 'pgb_pool_sv_login';

## Check the current maximum wait time for client connections in pgbouncer pools
check_pgb_pool('maxwait') if $action eq 'pgb_pool_maxwait';
check_pgb_pool('maxwait', 'max') if $action eq 'pgb_pool_maxwait';

## Check how many clients are connected to pgbouncer compared to max_client_conn.
check_pgbouncer_backends() if $action eq 'pgbouncer_backends';
Expand Down Expand Up @@ -6089,6 +6089,7 @@ sub check_pgb_pool {

# Check various bits of the pgbouncer SHOW POOLS ouptut
my $stat = shift;
my $type = shift;
my ($warning, $critical) = validate_range({type => 'positive integer'});

$SQL = 'SHOW POOLS';
Expand All @@ -6097,20 +6098,35 @@ sub check_pgb_pool {
$db = $info->{db}[0];
my $output = $db->{slurp};
my $gotone = 0;
my %map;
for my $i (@$output) {
next if skip_item($i->{database});
my $msg = "$i->{database}=$i->{$stat}";
my $db = $i->{database};
next if skip_item($db);

my $val = $i->{$stat};
if (!exists($map{$db})) {
$map{$db} = $val;
} elsif ($type eq "sum") {
$map{$db} += $val;
} elsif ($type eq "max" && $val > $map{$db}) {
$map{$db} = $val;
}
}

for my $db ( keys %map ) {
my $val = $map{$db};
my $msg = "$db=$val";

if ($MRTG) {
$stats{$i->{database}} = $i->{$stat};
$statsmsg{$i->{database}} = msg('pgbouncer-pool', $i->{database}, $stat, $i->{$stat});
$stats{$db} = $val;
$statsmsg{$db} = msg('pgbouncer-pool', $db, $stat, $val);
next;
}

if ($critical and $i->{$stat} >= $critical) {
if ($critical and $val >= $critical) {
add_critical $msg;
}
elsif ($warning and $i->{$stat} >= $warning) {
elsif ($warning and $val >= $warning) {
add_warning $msg;
}
else {
Expand Down