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

make work with multiple slots #163

Open
wants to merge 2 commits 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
54 changes: 35 additions & 19 deletions check_postgres.pl
Original file line number Diff line number Diff line change
Expand Up @@ -5706,15 +5706,19 @@ sub check_replication_slots {
$SQL = q{
WITH slots AS (SELECT slot_name,
slot_type,
coalesce(restart_lsn, '0/0'::pg_lsn) AS slot_lsn,
coalesce(
pg_xlog_location_diff(
case when pg_is_in_recovery() then pg_last_xlog_receive_location() else pg_current_xlog_location() end,
restart_lsn),
0) AS delta,
COALESCE(restart_lsn, '0/0'::pg_lsn) AS slot_lsn,
COALESCE(pg_xlog_location_diff(
CASE
WHEN pg_is_in_recovery() THEN
pg_last_xlog_receive_location()
ELSE
pg_current_xlog_location()
END,
restart_lsn
), 0) AS delta,
active
FROM pg_replication_slots)
SELECT *, pg_size_pretty(delta) AS delta_pretty FROM slots;
SELECT *, pg_size_pretty(delta) AS delta_pretty FROM slots
};

if ($opt{perflimit}) {
Expand All @@ -5728,27 +5732,39 @@ sub check_replication_slots {
my $found = 0;

for $db (@{$info->{db}}) {
my $max = -1;
my $max = 0;
my $total = 0;
$found = 1;
my %s;

for my $r (@{$db->{slurp}}) {
if (skip_item($r->{slot_name})) {
$max = -2 if -1 == $max;
next;
}
if ($r->{delta} >= $max) {
$max = $r->{delta};
}
# keep track of how many slots that we found
++$total;

# apply exclusion rules
next if skip_item($r->{slot_name});

# keep track of the largest backlog
$max = $r->{delta} if ($r->{delta} >= $max);

# keep track of all slots
$s{$r->{slot_name}} = [$r->{delta},$r->{delta_pretty},$r->{slot_type},$r->{slot_lsn},$r->{active}];
}

# record how far back our farthest back slot is
if ($MRTG) {
do_mrtg({one => $max, msg => "SLOT: $db->{slot_name}"});
do_mrtg({one => $max, msg => "DB: $db->{dbname}"});
}
if ($max < 0) {

if (!scalar(keys(%s))) {
$stats{$db->{dbname}} = 0;
add_ok msg('no-match-slotok') if -1 == $max;
add_unknown msg('no-match-slot') if -2 == $max;
if ($total > 0) {
# found slots but they didn't match
add_ok msg('no-match-slot');
} else {
# found no slots
add_ok msg('no-match-slotok');
}
next;
}

Expand Down