Skip to content

Commit 47a7f8d

Browse files
committed
Aggregate pgbouncer statistics values
1 parent 712fa84 commit 47a7f8d

File tree

1 file changed

+30
-14
lines changed

1 file changed

+30
-14
lines changed

check_postgres.pl

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2252,28 +2252,28 @@ sub finishup {
22522252
check_pgbouncer_checksum() if $action eq 'pgbouncer_checksum';
22532253

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

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

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

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

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

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

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

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

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

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

60946095
$SQL = 'SHOW POOLS';
@@ -6097,20 +6098,35 @@ sub check_pgb_pool {
60976098
$db = $info->{db}[0];
60986099
my $output = $db->{slurp};
60996100
my $gotone = 0;
6101+
my %map;
61006102
for my $i (@$output) {
6101-
next if skip_item($i->{database});
6102-
my $msg = "$i->{database}=$i->{$stat}";
6103+
my $db = $i->{database};
6104+
next if skip_item($db);
6105+
6106+
my $val = $i->{$stat};
6107+
if (!exists($map{$db})) {
6108+
$map{$db} = $val;
6109+
} elsif ($type eq "sum") {
6110+
$map{$db} += $val;
6111+
} elsif ($type eq "max" && $val > $map{$db}) {
6112+
$map{$db} = $val;
6113+
}
6114+
}
6115+
6116+
for my $db ( keys %map ) {
6117+
my $val = $map{$db};
6118+
my $msg = "$db=$val";
61036119

61046120
if ($MRTG) {
6105-
$stats{$i->{database}} = $i->{$stat};
6106-
$statsmsg{$i->{database}} = msg('pgbouncer-pool', $i->{database}, $stat, $i->{$stat});
6121+
$stats{$db} = $val;
6122+
$statsmsg{$db} = msg('pgbouncer-pool', $db, $stat, $val);
61076123
next;
61086124
}
61096125

6110-
if ($critical and $i->{$stat} >= $critical) {
6126+
if ($critical and $val >= $critical) {
61116127
add_critical $msg;
61126128
}
6113-
elsif ($warning and $i->{$stat} >= $warning) {
6129+
elsif ($warning and $val >= $warning) {
61146130
add_warning $msg;
61156131
}
61166132
else {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy