@@ -2252,28 +2252,28 @@ sub finishup {
2252
2252
check_pgbouncer_checksum() if $action eq ' pgbouncer_checksum' ;
2253
2253
2254
2254
# # 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' ;
2256
2256
2257
2257
# # 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' ;
2259
2259
2260
2260
# # 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' ;
2262
2262
2263
2263
# # 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' ;
2265
2265
2266
2266
# # 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' ;
2268
2268
2269
2269
# # 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' ;
2271
2271
2272
2272
# # 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' ;
2274
2274
2275
2275
# # 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' ;
2277
2277
2278
2278
# # Check how many clients are connected to pgbouncer compared to max_client_conn.
2279
2279
check_pgbouncer_backends() if $action eq ' pgbouncer_backends' ;
@@ -6089,6 +6089,7 @@ sub check_pgb_pool {
6089
6089
6090
6090
# Check various bits of the pgbouncer SHOW POOLS ouptut
6091
6091
my $stat = shift ;
6092
+ my $type = shift ;
6092
6093
my ($warning , $critical ) = validate_range({type => ' positive integer' });
6093
6094
6094
6095
$SQL = ' SHOW POOLS' ;
@@ -6097,20 +6098,35 @@ sub check_pgb_pool {
6097
6098
$db = $info -> {db }[0];
6098
6099
my $output = $db -> {slurp };
6099
6100
my $gotone = 0;
6101
+ my %map ;
6100
6102
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 " ;
6103
6119
6104
6120
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 );
6107
6123
next ;
6108
6124
}
6109
6125
6110
- if ($critical and $i -> { $stat } >= $critical ) {
6126
+ if ($critical and $val >= $critical ) {
6111
6127
add_critical $msg ;
6112
6128
}
6113
- elsif ($warning and $i -> { $stat } >= $warning ) {
6129
+ elsif ($warning and $val >= $warning ) {
6114
6130
add_warning $msg ;
6115
6131
}
6116
6132
else {
0 commit comments