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

new check: streaming_delay #206

Closed
wants to merge 2 commits into from
Closed
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
74 changes: 74 additions & 0 deletions check_pgactivity
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ my %services = (
'sub' => \&check_streaming_delta,
'desc' => 'Check delta in bytes between a master and its standbys in streaming replication.',
},
'streaming_delay' => {
'sub' => \&check_streaming_delay,
'desc' => 'Check how many seconds the slave is lagging behind the master'
},
'settings' => {
'sub' => \&check_settings,
'desc' => 'Check if the configuration file changed.',
Expand Down Expand Up @@ -6284,6 +6288,76 @@ sub check_stat_snapshot_age {
return ok( $me, \@msg, \@perfdata );
}

=item B<streaming_delay> (9.1+)

On a slave, check the delta time since the last replay transaction
timestamp. It's a bit similar to the streaming_delta, except this one
should be run on the slave and this one checks the time delta rather
than the size delta.

To get a correct reading it's important that the clocks are well
synchronized. The delay may even come out in the negative if the
local clock is out of sync with the clock on the master server. We
check the absolute value to ensure there will be an alarm also if the
clocks are too much out of sync with each other.

Returns UNKNOWN when run from a master or from a stand-alone server.

Perfdata returns the time delta in seconds from the master.

Required privileges: unprivileged role.

=cut

sub check_streaming_delay {
my $rs;
my $c_limit;
my $w_limit;
my @perfdata;
my @hosts;
my %args = %{ $_[0] };
my $me = 'POSTGRES_STREAMING_DELAY';
my %queries = (
$PG_VERSION_91 => q{select abs(EXTRACT(epoch from now() - pg_last_xact_replay_timestamp())) as s},
$PG_VERSION_100 => q{select abs(EXTRACT(epoch from now() - pg_last_wal_replay_timestamp())) as s},
);

# warning and critical are mandatory.
pod2usage(
-message => "FATAL: you must specify critical and warning thresholds.",
-exitval => 127
) unless defined $args{'warning'} and defined $args{'critical'} ;

pod2usage(
-message => "FATAL: critical and warning thresholds only acccepts interval.",
-exitval => 127
) unless ( is_time( $args{'warning'} ) and is_time( $args{'critical'} ) );

$c_limit = get_time( $args{'critical'} );
$w_limit = get_time( $args{'warning'} );

@hosts = @{ parse_hosts %args };

pod2usage(
-message => 'FATAL: you must give only one host with service "backup_label_age".',
-exitval => 127
) if @hosts != 1;

is_compat $hosts[0], 'backup_label_age', $PG_VERSION_91 or exit 1;

$rs = @{ query_ver( $hosts[0], %queries )->[0] }[0];

push @perfdata, [ 'delay', $rs, 's', $w_limit, $c_limit ];

return critical( $me, [ "delay: ".to_interval($rs) ], \@perfdata )
if $rs > $c_limit;

return warning( $me, [ "delay: ".to_interval($rs) ], \@perfdata )
if $rs > $w_limit;

return ok( $me, [ "delay: ".to_interval($rs) ], \@perfdata );
}

=item B<streaming_delta> (9.1+)

Check the data delta between a cluster and its standbys in streaming replication.
Expand Down