centreon-plugins/database/redis/mode/replication.pm

197 lines
6.5 KiB
Perl
Raw Normal View History

2018-01-29 14:11:11 +01:00
#
2021-02-08 09:55:50 +01:00
# Copyright 2021 Centreon (http://www.centreon.com/)
2018-01-29 14:11:11 +01:00
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
2021-11-03 09:58:28 +01:00
package database::redis::mode::replication;
2018-01-29 14:11:11 +01:00
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
2021-11-03 09:58:28 +01:00
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
sub custom_status_output {
my ($self, %options) = @_;
my $msg = sprintf("Node role is '%s' [cluster: %s]", $self->{result_values}->{role}, $self->{result_values}->{cluster_state});
if ($self->{result_values}->{role} eq 'slave') {
$msg .= sprintf(
" [link status: %s] [sync status: %s]",
$self->{result_values}->{link_status}, $self->{result_values}->{sync_status}
);
}
return $msg;
}
2018-01-29 14:11:11 +01:00
sub set_counters {
my ($self, %options) = @_;
2021-11-03 09:58:28 +01:00
2018-01-29 14:11:11 +01:00
$self->{maps_counters_type} = [
{ name => 'global', type => 0, skipped_code => { -10 => 1 } },
{ name => 'master', type => 0, skipped_code => { -10 => 1 } },
2021-11-03 09:58:28 +01:00
{ name => 'slave', type => 0, skipped_code => { -10 => 1 } }
2018-01-29 14:11:11 +01:00
];
2021-11-03 09:58:28 +01:00
2018-01-29 14:11:11 +01:00
$self->{maps_counters}->{global} = [
2021-11-03 09:58:28 +01:00
{
label => 'status',
type => 2,
warning_default => '%{sync_status} =~ /in progress/i',
critical_default => '%{link_status} =~ /down/i',
set => {
2018-01-29 14:11:11 +01:00
key_values => [ { name => 'link_status' }, { name => 'sync_status' }, { name => 'role' }, { name => 'cluster_state' } ],
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
2021-11-03 09:58:28 +01:00
closure_custom_threshold_check => \&catalog_status_threshold_ng
2018-01-29 14:11:11 +01:00
}
},
2021-11-03 09:58:28 +01:00
{ label => 'connected-slaves', nlabel => 'replication.slaves.connected.count', set => {
2018-01-29 14:11:11 +01:00
key_values => [ { name => 'connected_slaves' } ],
2021-11-03 09:58:28 +01:00
output_template => 'number of connected slaves: %s',
2018-01-29 14:11:11 +01:00
perfdatas => [
2021-11-03 09:58:28 +01:00
{ template => '%s', min => 0 }
]
}
}
2018-01-29 14:11:11 +01:00
];
$self->{maps_counters}->{master} = [
2021-11-03 09:58:28 +01:00
{ label => 'master-repl-offset', nlabel => 'replication.master.offset.count', set => {
2018-01-29 14:11:11 +01:00
key_values => [ { name => 'master_repl_offset' } ],
2021-11-03 09:58:28 +01:00
output_template => 'master replication offset: %s',
2018-01-29 14:11:11 +01:00
perfdatas => [
2021-11-03 09:58:28 +01:00
{ template => '%s', min => 0 }
]
}
}
2018-01-29 14:11:11 +01:00
];
$self->{maps_counters}->{slave} = [
2021-11-03 09:58:28 +01:00
{ label => 'master-last-io', nlabel => 'replication.master.last_interaction.seconds', set => {
2018-01-29 14:11:11 +01:00
key_values => [ { name => 'master_last_io_seconds_ago' } ],
2021-11-03 09:58:28 +01:00
output_template => 'last interaction with master: %s s',
2018-01-29 14:11:11 +01:00
perfdatas => [
2021-11-03 09:58:28 +01:00
{ template => '%s', min => 0, unit => 's' }
]
}
2018-01-29 14:11:11 +01:00
},
2021-11-03 09:58:28 +01:00
{ label => 'slave-repl-offset', nlabel => 'replication.slave.offset.count', set => {
2018-01-29 14:11:11 +01:00
key_values => [ { name => 'slave_repl_offset' } ],
2021-11-03 09:58:28 +01:00
output_template => 'slave replication offset: %s s',
2018-01-29 14:11:11 +01:00
perfdatas => [
2021-11-03 09:58:28 +01:00
{ template => '%s', min => 0 }
]
}
2018-01-29 14:11:11 +01:00
},
2021-11-03 09:58:28 +01:00
{ label => 'slave-priority', nlabel => 'replication.slave.priority.count', set => {
2018-01-29 14:11:11 +01:00
key_values => [ { name => 'slave_priority' } ],
2021-11-03 09:58:28 +01:00
output_template => 'slave replication priority: %s',
2018-01-29 14:11:11 +01:00
perfdatas => [
2021-11-03 09:58:28 +01:00
{ template => '%s' }
]
}
2018-01-29 14:11:11 +01:00
},
2021-11-03 09:58:28 +01:00
{ label => 'slave-read-only', nlabel => 'replication.slave.readonly.count',set => {
2018-01-29 14:11:11 +01:00
key_values => [ { name => 'slave_read_only' } ],
2021-11-03 09:58:28 +01:00
output_template => 'slave readonly: %s',
2018-01-29 14:11:11 +01:00
perfdatas => [
2021-11-03 09:58:28 +01:00
{ template => '%s' }
]
}
}
2018-01-29 14:11:11 +01:00
];
}
sub new {
my ($class, %options) = @_;
2021-11-03 09:58:28 +01:00
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
2018-01-29 14:11:11 +01:00
bless $self, $class;
2021-11-03 09:58:28 +01:00
$options{options}->add_options(arguments => {});
2018-01-29 14:11:11 +01:00
return $self;
}
my %map_sync = (
0 => 'stopped',
2021-11-03 09:58:28 +01:00
1 => 'in progress'
2018-01-29 14:11:11 +01:00
);
my %map_cluster_state = (
0 => 'disabled',
2021-11-03 09:58:28 +01:00
1 => 'enabled'
2018-01-29 14:11:11 +01:00
);
sub manage_selection {
my ($self, %options) = @_;
my $results = $options{custom}->get_info();
$self->{global} = {
connected_slaves => $results->{connected_slaves},
role => $results->{role},
cluster_state => defined($results->{cluster_enabled}) ? $map_cluster_state{$results->{cluster_enabled}} : '-',
link_status => defined($results->{master_link_status}) ? $results->{master_link_status} : '-',
2021-11-03 09:58:28 +01:00
sync_status => defined($results->{master_sync_in_progress}) ? $map_sync{$results->{master_sync_in_progress}} : '-'
2018-01-29 14:11:11 +01:00
};
$self->{master} = { master_repl_offset => $results->{master_repl_offset} };
$self->{slave} = {
2021-11-03 09:58:28 +01:00
master_last_io_seconds_ago => $results->{master_last_io_seconds_ago},
slave_repl_offset => $results->{slave_repl_offset},
slave_priority => $results->{slave_priority},
slave_read_only => $results->{slave_read_only}
2018-01-29 14:11:11 +01:00
};
}
1;
__END__
=head1 MODE
Check replication status.
=over 8
=item B<--warning-status>
Set warning threshold for status (Default: '%{sync_status} =~ /in progress/i').
Can used special variables like: %{sync_status}, %{link_status}, %{cluster_state}
=item B<--critical-status>
Set critical threshold for status (Default: '%{link_status} =~ /down/i').
Can used special variables like: %{sync_status}, %{link_status}, %{cluster_state}
=item B<--warning-*>
Threshold warning.
Can be: 'connected-slaves', 'master-repl-offset',
'master-last-io', 'slave-priority', 'slave-read-only'.
=item B<--critical-*>
Threshold critical.
Can be: 'connected-slaves', 'master-repl-offset',
'master-last-io', 'slave-priority', 'slave-read-only'.
=back
=cut