From 47a7f8dbce1c1a735c84ebb36c6077b6f468063d Mon Sep 17 00:00:00 2001 From: Vincas Dargis Date: Mon, 22 Feb 2016 11:45:42 +0200 Subject: [PATCH] Aggregate pgbouncer statistics values --- check_postgres.pl | 44 ++++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/check_postgres.pl b/check_postgres.pl index 8f63b85e..fd3bc465 100755 --- a/check_postgres.pl +++ b/check_postgres.pl @@ -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'; @@ -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'; @@ -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 {