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

Add check replication_active_slots. #138

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
56 changes: 56 additions & 0 deletions check_postgres.pl
Original file line number Diff line number Diff line change
Expand Up @@ -1720,6 +1720,7 @@ package check_postgres;
query_time => [1, 'Checks the maximum running time of current queries.'],
replicate_row => [0, 'Verify a simple update gets replicated to another server.'],
replication_slots => [1, 'Check the replication delay for replication slots'],
replication_active_slots => [1, 'Check the replication active slots'],
same_schema => [0, 'Verify that two databases have the exact same tables, columns, etc.'],
sequence => [0, 'Checks remaining calls left in sequences.'],
settings_checksum => [0, 'Check that no settings have changed since the last check.'],
Expand Down Expand Up @@ -2495,6 +2496,9 @@ sub finishup {
## Check the delay on replication slots. warning and critical are sizes
check_replication_slots() if $action eq 'replication_slots';

## Check the replication active slots
check_replication_active_slots() if $action eq 'replication_active_slots';

## Check the maximum transaction age of all connections
check_txn_time() if $action eq 'txn_time';

Expand Down Expand Up @@ -5565,6 +5569,48 @@ sub check_replication_slots {
} ## end of check_replication_slot_delay



sub check_replication_active_slots {
# Check that all replication slots are active.
# A warning is raised if an unused slot is found.
# A critical is raised if a used replication slot is not active.
$SQL = qq{
SELECT * FROM pg_replication_slots;
};

my $info = run_command($SQL);
my $warn = 0;
my $crit = 0;
my $msg = '';

for $db (@{$info->{db}}) {
for my $r (@{$db->{slurp}}) {
if (skip_item($r->{slot_name})) {
next;
}
if ($r->{active} eq "f") {
if ($r->{restart_lsn}) {
$crit += 1;
} else {
$warn += 1;
}
$msg .= $r->{slot_name} . ' ';
}
}
}

if ($crit > 0) {
add_critical('Not active slots: ' . $msg);
} elsif ($warn > 0) {
add_warning('Not active (unused) slots: ' . $msg);
} else {
add_ok('No unactive slot found');
}

return;
} ## end of check_replication_active_slots


sub check_last_analyze {
my $auto = shift || '';
return check_last_vacuum_analyze('analyze', $auto);
Expand Down Expand Up @@ -10128,6 +10174,16 @@ =head2 B<replication_slots>

Specific named slots can be monitored using --include/--exclude

=head2 B<replication_active_slots>

(C<symlink: check_postgres_replication_active_slots>) Check all replication
slots and raise a warning is a slot is not active and hasn't been used or a
critical alert if the slot has been used.

check_postgres_replication_active_slots --port=5432 --host=yellow

Specific named slots can be monitored using --include/--exclude

=head2 B<same_schema>

(C<symlink: check_postgres_same_schema>) Verifies that two or more databases are identical as far as their
Expand Down