break(redis): refactoring (#3228)

This commit is contained in:
qgarnier 2021-11-03 09:58:28 +01:00 committed by GitHub
parent b27c357358
commit 6276394c76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 1335 additions and 1021 deletions

View File

@ -1,142 +0,0 @@
#
# Copyright 2021 Centreon (http://www.centreon.com/)
#
# 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.
#
package apps::redis::cli::custom::rediscli;
use strict;
use warnings;
use Redis;
sub new {
my ($class, %options) = @_;
my $self = {};
bless $self, $class;
if (!defined($options{output})) {
print "Class Custom: Need to specify 'output' argument.\n";
exit 3;
}
if (!defined($options{options})) {
$options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument.");
$options{output}->option_exit();
}
if (!defined($options{noptions})) {
$options{options}->add_options(arguments => {
'hostname:s' => { name => 'hostname' },
'port:s' => { name => 'port' },
'password:s' => { name => 'password' }
});
}
$options{options}->add_help(package => __PACKAGE__, sections => 'REDIS CLI OPTIONS', once => 1);
$self->{output} = $options{output};
return $self;
}
sub set_options {
my ($self, %options) = @_;
$self->{option_results} = $options{option_results};
}
sub set_defaults {}
sub check_options {
my ($self, %options) = @_;
$self->{hostname} = $self->{option_results}->{hostname};
$self->{port} = $self->{option_results}->{port};
$self->{password} = $self->{option_results}->{password};
if (!defined($self->{hostname})) {
$self->{output}->add_option_msg(short_msg => "Need to specify hostname argument.");
$self->{output}->option_exit();
}
if (!defined($self->{port})) {
$self->{output}->add_option_msg(short_msg => "Need to specify port argument.");
$self->{output}->option_exit();
}
return 0;
}
sub get_connection_info {
my ($self, %options) = @_;
return $self->{hostname} . ":" . $self->{port};
}
sub get_info {
my ($self, %options) = @_;
$self->{redis} = Redis->new(server => $self->{hostname} . ":" . $self->{port});
if (defined($self->{password})) {
$self->{redis}->auth($self->{password});
}
my $response = $self->{redis}->info;
my $items;
foreach my $attributes (keys %{$response}) {
$items->{$attributes} = $response->{$attributes};
}
$self->{redis}->quit();
return $items;
}
1;
__END__
=head1 NAME
REDIS CLI
=head1 SYNOPSIS
Redis Cli custom mode
=head1 REDIS CLI OPTIONS
=over 8
=item B<--hostname>
Redis hostname.
=item B<--port>
Redis port.
=item B<--password>
Redis password
=back
=head1 DESCRIPTION
B<custom>.
=cut

View File

@ -18,7 +18,7 @@
# limitations under the License.
#
package apps::redis::restapi::custom::api;
package apps::redis::rlec::restapi::custom::api;
use strict;
use warnings;
@ -76,17 +76,16 @@ sub check_options {
$self->{password} = (defined($self->{option_results}->{password})) ? shift(@{$self->{option_results}->{password}}) : '';
$self->{timeout} = (defined($self->{option_results}->{timeout})) ? shift(@{$self->{option_results}->{timeout}}) : 10;
$self->{interval} = (defined($self->{option_results}->{interval})) ? shift(@{$self->{option_results}->{interval}}) : '15min';
if (!defined($self->{hostname})) {
$self->{output}->add_option_msg(short_msg => "Need to specify hostname option.");
$self->{output}->option_exit();
}
if (!defined($self->{hostname}) ||
scalar(@{$self->{option_results}->{hostname}}) == 0) {
return 0;
}
return 1;
}
@ -114,13 +113,13 @@ sub settings {
sub get_connection_info {
my ($self, %options) = @_;
return $self->{hostname} . ":" . $self->{port};
}
sub get_interval {
my ($self, %options) = @_;
return $self->{interval};
}
@ -130,8 +129,7 @@ sub get {
$self->settings();
my $response = $self->{http}->request(url_path => $options{path});
my $content;
my $content;
eval {
$content = JSON::XS->new->utf8->decode($response);
};
@ -156,7 +154,7 @@ sub get {
}
$return = $content;
}
return $return;
}

View File

@ -18,22 +18,23 @@
# limitations under the License.
#
package apps::redis::restapi::mode::clusterstats;
package apps::redis::rlec::restapi::mode::clusterstats;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
sub custom_usage_perfdata {
my ($self, %options) = @_;
$self->{output}->perfdata_add(label => $self->{result_values}->{perf}, unit => 'B',
value => $self->{result_values}->{used},
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{result_values}->{label}, total => $self->{result_values}->{total}, cast_int => 1),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{result_values}->{label}, total => $self->{result_values}->{total}, cast_int => 1),
min => 0, max => $self->{result_values}->{total});
$self->{output}->perfdata_add(
label => $self->{result_values}->{perf}, unit => 'B',
value => $self->{result_values}->{used},
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{result_values}->{label}, total => $self->{result_values}->{total}, cast_int => 1),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{result_values}->{label}, total => $self->{result_values}->{total}, cast_int => 1),
min => 0, max => $self->{result_values}->{total}
);
}
sub custom_usage_threshold {
@ -52,16 +53,17 @@ sub custom_usage_threshold {
sub custom_usage_output {
my ($self, %options) = @_;
my ($used_value, $used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
my ($free_value, $free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
my ($total_value, $total_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total});
my $msg = sprintf("%s usage: Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", $self->{result_values}->{display},
$total_value . " " . $total_unit,
$used_value . " " . $used_unit, $self->{result_values}->{prct_used},
$free_value . " " . $free_unit, $self->{result_values}->{prct_free});
return $msg;
return sprintf(
"%s usage: Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", $self->{result_values}->{display},
$total_value . " " . $total_unit,
$used_value . " " . $used_unit, $self->{result_values}->{prct_used},
$free_value . " " . $free_unit, $self->{result_values}->{prct_free}
);
}
sub custom_usage_calc {
@ -94,77 +96,82 @@ sub prefix_output {
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'cluster', type => 1, cb_prefix_output => 'prefix_output', message_multiple => 'All cluster counters are ok' },
{ name => 'cluster', type => 1, cb_prefix_output => 'prefix_output', message_multiple => 'All cluster counters are ok' }
];
$self->{maps_counters}->{cluster} = [
{ label => 'cpu-system', set => {
key_values => [ { name => 'cpu_system' } ],
output_template => 'Cpu system: %.2f %%',
perfdatas => [
{ label => 'cpu_system', value => 'cpu_system', template => '%.2f',
min => 0, max => 100, unit => '%' },
],
{ label => 'cpu_system', template => '%.2f', min => 0, max => 100, unit => '%' }
]
}
},
{ label => 'cpu-user', set => {
key_values => [ { name => 'cpu_user' } ],
output_template => 'Cpu user: %.2f %%',
perfdatas => [
{ label => 'cpu_user', value => 'cpu_user', template => '%.2f',
min => 0, max => 100, unit => '%' },
],
{ label => 'cpu_user', template => '%.2f', min => 0, max => 100, unit => '%' }
]
}
},
{ label => 'memory', set => {
key_values => [ { name => 'free_memory' }, { name => 'total_memory' } ],
closure_custom_calc => $self->can('custom_usage_calc'),
closure_custom_calc_extra_options => { display => 'Ram', label => 'memory', perf => 'memory',
free => 'free_memory', total => 'total_memory' },
closure_custom_calc_extra_options => {
display => 'Ram', label => 'memory', perf => 'memory',
free => 'free_memory', total => 'total_memory'
},
closure_custom_output => $self->can('custom_usage_output'),
closure_custom_perfdata => $self->can('custom_usage_perfdata'),
closure_custom_threshold_check => $self->can('custom_usage_threshold'),
closure_custom_threshold_check => $self->can('custom_usage_threshold')
}
},
{ label => 'persistent-storage', set => {
key_values => [ { name => 'persistent_storage_free' }, { name => 'persistent_storage_size' } ],
closure_custom_calc => $self->can('custom_usage_calc'),
closure_custom_calc_extra_options => { display => 'Persistent storage', label => 'persistent-storage', perf => 'persistent_storage',
free => 'persistent_storage_free', total => 'persistent_storage_size' },
closure_custom_calc_extra_options => {
display => 'Persistent storage', label => 'persistent-storage', perf => 'persistent_storage',
free => 'persistent_storage_free', total => 'persistent_storage_size'
},
closure_custom_output => $self->can('custom_usage_output'),
closure_custom_perfdata => $self->can('custom_usage_perfdata'),
closure_custom_threshold_check => $self->can('custom_usage_threshold'),
closure_custom_threshold_check => $self->can('custom_usage_threshold')
}
},
{ label => 'ephemeral-storage', set => {
key_values => [ { name => 'ephemeral_storage_free' }, { name => 'ephemeral_storage_size' } ],
closure_custom_calc => $self->can('custom_usage_calc'),
closure_custom_calc_extra_options => { display => 'Ephemeral storage', label => 'ephemeral-storage', perf => 'ephemeral_storage',
free => 'ephemeral_storage_free', total => 'ephemeral_storage_size' },
closure_custom_calc_extra_options => {
display => 'Ephemeral storage', label => 'ephemeral-storage', perf => 'ephemeral_storage',
free => 'ephemeral_storage_free', total => 'ephemeral_storage_size'
},
closure_custom_output => $self->can('custom_usage_output'),
closure_custom_perfdata => $self->can('custom_usage_perfdata'),
closure_custom_threshold_check => $self->can('custom_usage_threshold'),
closure_custom_threshold_check => $self->can('custom_usage_threshold')
}
},
{ label => 'flash-storage', set => {
key_values => [ { name => 'bigstore_free' }, { name => 'bigstore_size' } ],
closure_custom_calc => $self->can('custom_usage_calc'),
closure_custom_calc_extra_options => { display => 'Flash storage', label => 'flash-storage', perf => 'flash_storage',
free => 'bigstore_free', total => 'bigstore_size' },
closure_custom_calc_extra_options => {
display => 'Flash storage', label => 'flash-storage', perf => 'flash_storage',
free => 'bigstore_free', total => 'bigstore_size'
},
closure_custom_output => $self->can('custom_usage_output'),
closure_custom_perfdata => $self->can('custom_usage_perfdata'),
closure_custom_threshold_check => $self->can('custom_usage_threshold'),
closure_custom_threshold_check => $self->can('custom_usage_threshold')
}
},
{ label => 'flash-iops', set => {
key_values => [ { name => 'bigstore_iops' } ],
output_template => 'Flash IOPS: %s ops/s',
perfdatas => [
{ label => 'flash_iops', value => 'bigstore_iops', template => '%s',
min => 0, unit => 'ops/s' },
],
{ label => 'flash_iops', template => '%s', min => 0, unit => 'ops/s' }
]
}
},
{ label => 'flash-throughput', set => {
@ -172,27 +179,24 @@ sub set_counters {
output_template => 'Flash throughput: %s %s/s',
output_change_bytes => 1,
perfdatas => [
{ label => 'flash_throughput', value => 'bigstore_throughput', template => '%s',
min => 0, unit => 'B/s' },
],
{ label => 'flash_throughput', template => '%s', min => 0, unit => 'B/s' }
]
}
},
{ label => 'connections', set => {
key_values => [ { name => 'conns' } ],
output_template => 'Connections: %s',
perfdatas => [
{ label => 'connections', value => 'conns', template => '%s',
min => 0 },
],
{ label => 'connections', template => '%s', min => 0 }
]
}
},
{ label => 'requests', set => {
key_values => [ { name => 'total_req' } ],
output_template => 'Requests rate: %s ops/s',
perfdatas => [
{ label => 'requests', value => 'total_req', template => '%s',
min => 0, unit => 'ops/s' },
],
{ label => 'requests', template => '%s', min => 0, unit => 'ops/s' }
]
}
},
{ label => 'traffic-in', set => {
@ -200,19 +204,19 @@ sub set_counters {
output_template => 'Traffic In: %s %s/s',
output_change_bytes => 2,
perfdatas => [
{ label => 'traffic_in', value => 'ingress', template => '%d', min => 0, unit => 'b/s' },
],
},
{ label => 'traffic_in', template => '%d', min => 0, unit => 'b/s' }
]
}
},
{ label => 'traffic-out', set => {
key_values => [ { name => 'egress' } ],
output_template => 'Traffic Out: %s %s/s',
output_change_bytes => 2,
perfdatas => [
{ label => 'traffic_out', value => 'egress', template => '%d', min => 0, unit => 'b/s' },
],
},
},
{ label => 'traffic_out', template => '%d', min => 0, unit => 'b/s' }
]
}
}
];
}
@ -222,8 +226,8 @@ sub new {
bless $self, $class;
$options{options}->add_options(arguments => {
"units:s" => { name => 'units', default => '%' },
"free" => { name => 'free' },
'units:s' => { name => 'units', default => '%' },
'free' => { name => 'free' }
});
return $self;
@ -273,7 +277,7 @@ sub manage_selection {
conns => $result->{conns},
total_req => $result->{total_req},
ingress => $result->{ingress_bytes} * 8,
egress => $result->{egress_bytes} * 8,
egress => $result->{egress_bytes} * 8
};
}

View File

@ -18,23 +18,24 @@
# limitations under the License.
#
package apps::redis::restapi::mode::databasesstats;
package apps::redis::rlec::restapi::mode::databasesstats;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
sub custom_usage_perfdata {
my ($self, %options) = @_;
$self->{output}->perfdata_add(label => $self->{result_values}->{perf}, unit => 'B',
value => $self->{result_values}->{used},
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{result_values}->{label}, total => $self->{result_values}->{total}, cast_int => 1),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{result_values}->{label}, total => $self->{result_values}->{total}, cast_int => 1),
min => 0, max => $self->{result_values}->{total});
$self->{output}->perfdata_add(
label => $self->{result_values}->{perf}, unit => 'B',
value => $self->{result_values}->{used},
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{result_values}->{label}, total => $self->{result_values}->{total}, cast_int => 1),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{result_values}->{label}, total => $self->{result_values}->{total}, cast_int => 1),
min => 0, max => $self->{result_values}->{total}
);
}
sub custom_usage_threshold {
@ -58,11 +59,12 @@ sub custom_usage_output {
my ($free_value, $free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
my ($total_value, $total_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total});
my $msg = sprintf("%s usage: Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", $self->{result_values}->{display},
$total_value . " " . $total_unit,
$used_value . " " . $used_unit, $self->{result_values}->{prct_used},
$free_value . " " . $free_unit, $self->{result_values}->{prct_free});
return $msg;
return sprintf(
"%s usage: Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", $self->{result_values}->{display},
$total_value . " " . $total_unit,
$used_value . " " . $used_unit, $self->{result_values}->{prct_used},
$free_value . " " . $free_unit, $self->{result_values}->{prct_free}
);
}
sub custom_usage_calc {
@ -79,9 +81,9 @@ sub custom_usage_calc {
$self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total};
$self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used};
} else {
$self->{result_values}->{used} = '0';
$self->{result_values}->{prct_used} = '0';
$self->{result_values}->{prct_free} = '0';
$self->{result_values}->{used} = 0;
$self->{result_values}->{prct_used} = 0;
$self->{result_values}->{prct_free} = 0;
}
return 0;
@ -90,37 +92,26 @@ sub custom_usage_calc {
sub custom_status_output {
my ($self, %options) = @_;
my $msg = sprintf("Status is '%s' [type: %s] [shard list: %s] [backup status: %s] [export status: %s] [import status: %s]",
return sprintf(
"Status is '%s' [type: %s] [shard list: %s] [backup status: %s] [export status: %s] [import status: %s]",
$self->{result_values}->{status},
$self->{result_values}->{type},
$self->{result_values}->{shard_list},
$self->{result_values}->{backup_status},
$self->{result_values}->{export_status},
$self->{result_values}->{import_status});
return $msg;
}
sub custom_status_calc {
my ($self, %options) = @_;
$self->{result_values}->{type} = $options{new_datas}->{$self->{instance} . '_type'};
$self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'};
$self->{result_values}->{backup_status} = $options{new_datas}->{$self->{instance} . '_backup_status'};
$self->{result_values}->{export_status} = $options{new_datas}->{$self->{instance} . '_export_status'};
$self->{result_values}->{import_status} = $options{new_datas}->{$self->{instance} . '_import_status'};
$self->{result_values}->{shard_list} = $options{new_datas}->{$self->{instance} . '_shard_list'};
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
return 0;
$self->{result_values}->{import_status}
);
}
sub custom_cpu_output {
my ($self, %options) = @_;
my $msg = sprintf("%s CPU usage (user/system): %s/%s %%",
return sprintf(
"%s CPU usage (user/system): %s/%s %%",
$self->{result_values}->{cpu},
$self->{result_values}->{user},
$self->{result_values}->{system});
return $msg;
$self->{result_values}->{system}
);
}
sub custom_cpu_calc {
@ -136,13 +127,14 @@ sub custom_cpu_calc {
sub custom_operations_output {
my ($self, %options) = @_;
my $msg = sprintf("%s operations rates (hits/misses/requests/responses): %s/%s/%s/%s ops/s",
return sprintf(
"%s operations rates (hits/misses/requests/responses): %s/%s/%s/%s ops/s",
$self->{result_values}->{operation},
$self->{result_values}->{hits},
$self->{result_values}->{misses},
$self->{result_values}->{req},
$self->{result_values}->{res});
return $msg;
$self->{result_values}->{res}
);
}
sub custom_operations_calc {
@ -165,61 +157,72 @@ sub prefix_output {
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'databases', type => 1, cb_prefix_output => 'prefix_output', message_multiple => 'All databases counters are ok' },
{ name => 'databases', type => 1, cb_prefix_output => 'prefix_output', message_multiple => 'All databases counters are ok' }
];
$self->{maps_counters}->{databases} = [
{ label => 'status', threshold => 0, set => {
key_values => [ { name => 'status' }, { name => 'type' }, { name => 'backup_status' },
{ name => 'export_status' }, { name => 'import_status' }, { name => 'shard_list' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_status_calc'),
{
label => 'status',
type => 2,
critical_default => '%{status} =~ /creation-failed/i || %{backup_status} =~ /failed/i || %{export_status} =~ /failed/i || %{import_status} =~ /failed/i',
set => {
key_values => [
{ name => 'status' }, { name => 'type' }, { name => 'backup_status' },
{ name => 'export_status' }, { name => 'import_status' }, { name => 'shard_list' }, { name => 'display' }
],
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold,
closure_custom_threshold_check => \&catalog_status_threshold_ng
}
},
{ label => 'total-cpu', set => {
key_values => [ { name => 'shard_cpu_user' }, { name => 'shard_cpu_system' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_cpu_calc'),
closure_custom_calc_extra_options => { cpu => 'Total', user => 'shard_cpu_user',
system => 'shard_cpu_system', display => 'display' },
closure_custom_calc_extra_options => {
cpu => 'Total', user => 'shard_cpu_user',
system => 'shard_cpu_system', display => 'display'
},
closure_custom_output => $self->can('custom_cpu_output'),
perfdatas => [
{ label => 'total_cpu_user', value => 'user', template => '%s',
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display' },
{ label => 'total_cpu_system', value => 'system', template => '%s',
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display' },
],
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'fork-cpu', set => {
key_values => [ { name => 'fork_cpu_user' }, { name => 'fork_cpu_system' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_cpu_calc'),
closure_custom_calc_extra_options => { cpu => 'Fork', user => 'fork_cpu_user',
system => 'fork_cpu_system', display => 'display' },
closure_custom_calc_extra_options => {
cpu => 'Fork', user => 'fork_cpu_user',
system => 'fork_cpu_system', display => 'display'
},
closure_custom_output => $self->can('custom_cpu_output'),
perfdatas => [
{ label => 'fork_cpu_user', value => 'user', template => '%s',
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display' },
{ label => 'fork_cpu_system', value => 'system', template => '%s',
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display' },
],
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'main-thread-cpu', set => {
key_values => [ { name => 'main_thread_cpu_user' }, { name => 'main_thread_cpu_system' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_cpu_calc'),
closure_custom_calc_extra_options => { cpu => 'Main thread', user => 'main_thread_cpu_user',
system => 'main_thread_cpu_system', display => 'display' },
closure_custom_calc_extra_options => {
cpu => 'Main thread', user => 'main_thread_cpu_user',
system => 'main_thread_cpu_system', display => 'display'
},
closure_custom_output => $self->can('custom_cpu_output'),
perfdatas => [
{ label => 'main_thread_cpu_user', value => 'user', template => '%s',
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display' },
{ label => 'main_thread_cpu_system', value => 'system', template => '%s',
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display' },
],
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'memory', set => {
@ -229,33 +232,37 @@ sub set_counters {
used => 'used_memory', total => 'memory_size' },
closure_custom_output => $self->can('custom_usage_output'),
closure_custom_perfdata => $self->can('custom_usage_perfdata'),
closure_custom_threshold_check => $self->can('custom_usage_threshold'),
closure_custom_threshold_check => $self->can('custom_usage_threshold')
}
},
{ label => 'mem-frag-ratio', set => {
key_values => [ { name => 'mem_frag_ratio' }, { name => 'display' } ],
output_template => 'Memory fragmentation ratio: %s',
perfdatas => [
{ label => 'mem_frag_ratio', value => 'mem_frag_ratio', template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display' },
],
{ label => 'mem_frag_ratio', template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'connections', set => {
key_values => [ { name => 'conns' }, { name => 'display' } ],
output_template => 'Connections: %s',
perfdatas => [
{ label => 'connections', value => 'conns', template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display' },
],
{ label => 'connections', template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'total-rates', set => {
key_values => [ { name => 'total_hits' }, { name => 'total_misses' },
{ name => 'total_req' }, { name => 'total_res' }, { name => 'display' } ],
key_values => [
{ name => 'total_hits' }, { name => 'total_misses' },
{ name => 'total_req' }, { name => 'total_res' }, { name => 'display' }
],
closure_custom_calc => $self->can('custom_operations_calc'),
closure_custom_calc_extra_options => { operation => 'Total', hits => 'total_hits', misses => 'total_misses',
req => 'total_req', res => 'total_res', display => 'display' },
closure_custom_calc_extra_options => {
operation => 'Total', hits => 'total_hits', misses => 'total_misses',
req => 'total_req', res => 'total_res', display => 'display'
},
closure_custom_output => $self->can('custom_operations_output'),
perfdatas => [
{ label => 'total_hits', value => 'hits', template => '%s',
@ -265,76 +272,84 @@ sub set_counters {
{ label => 'total_req', value => 'req', template => '%s',
min => 0, unit => 'ops/s', label_extra_instance => 1, instance_use => 'display' },
{ label => 'total_res', value => 'res', template => '%s',
min => 0, unit => 'ops/s', label_extra_instance => 1, instance_use => 'display' },
],
min => 0, unit => 'ops/s', label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'latency', set => {
key_values => [ { name => 'avg_latency' }, { name => 'display' } ],
output_template => 'Average latency: %.2f ms',
perfdatas => [
{ label => 'latency', value => 'avg_latency', template => '%.2f',
min => 0, unit => 'ms', label_extra_instance => 1, instance_use => 'display' },
],
{ label => 'latency', template => '%.2f',
min => 0, unit => 'ms', label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'other-rates', set => {
key_values => [ { name => 'other_hits' }, { name => 'other_misses' },
{ name => 'other_req' }, { name => 'other_res' }, { name => 'display' } ],
key_values => [
{ name => 'other_hits' }, { name => 'other_misses' },
{ name => 'other_req' }, { name => 'other_res' }, { name => 'display' }
],
closure_custom_calc => $self->can('custom_operations_calc'),
closure_custom_calc_extra_options => { operation => 'Other', hits => 'other_hits', misses => 'other_misses',
req => 'other_req', res => 'other_res', display => 'display' },
closure_custom_calc_extra_options => {
operation => 'Other', hits => 'other_hits', misses => 'other_misses',
req => 'other_req', res => 'other_res', display => 'display'
},
closure_custom_output => $self->can('custom_operations_output'),
perfdatas => [
{ label => 'other_req', value => 'req', template => '%s',
min => 0, unit => 'ops/s', label_extra_instance => 1, instance_use => 'display' },
{ label => 'other_res', value => 'res', template => '%s',
min => 0, unit => 'ops/s', label_extra_instance => 1, instance_use => 'display' },
],
min => 0, unit => 'ops/s', label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'other-latency', set => {
key_values => [ { name => 'avg_other_latency' }, { name => 'display' } ],
output_template => 'Other latency: %.2f ms',
perfdatas => [
{ label => 'other_latency', value => 'avg_other_latency', template => '%.2f',
min => 0, unit => 'ms', label_extra_instance => 1, instance_use => 'display' },
],
{ label => 'other_latency', template => '%.2f',
min => 0, unit => 'ms', label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'keys', set => {
key_values => [ { name => 'no_of_keys' }, { name => 'display' } ],
output_template => 'Total keys: %s',
perfdatas => [
{ label => 'keys', value => 'no_of_keys', template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display' },
],
{ label => 'keys', template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'evicted-objects', set => {
key_values => [ { name => 'evicted_objects' }, { name => 'display' } ],
output_template => 'Evicted objects rate: %s evictions/sec',
perfdatas => [
{ label => 'evicted_objects', value => 'evicted_objects', template => '%s',
min => 0, unit => 'evictions/sec', label_extra_instance => 1, instance_use => 'display' },
],
{ label => 'evicted_objects', template => '%s',
min => 0, unit => 'evictions/sec', label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'expired-objects', set => {
key_values => [ { name => 'expired_objects' }, { name => 'display' } ],
output_template => 'Expired objects rate: %s expirations/sec',
perfdatas => [
{ label => 'expired_objects', value => 'expired_objects', template => '%s',
min => 0, unit => 'expirations/sec', label_extra_instance => 1, instance_use => 'display' },
],
{ label => 'expired_objects', template => '%s',
min => 0, unit => 'expirations/sec', label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'read-rates', set => {
key_values => [ { name => 'read_hits' }, { name => 'read_misses' },
{ name => 'read_req' }, { name => 'read_res' }, { name => 'display' } ],
key_values => [
{ name => 'read_hits' }, { name => 'read_misses' },
{ name => 'read_req' }, { name => 'read_res' }, { name => 'display' }
],
closure_custom_calc => $self->can('custom_operations_calc'),
closure_custom_calc_extra_options => { operation => 'Read', hits => 'read_hits', misses => 'read_misses',
req => 'read_req', res => 'read_res', display => 'display' },
closure_custom_calc_extra_options => {
operation => 'Read', hits => 'read_hits', misses => 'read_misses',
req => 'read_req', res => 'read_res', display => 'display'
},
closure_custom_output => $self->can('custom_operations_output'),
perfdatas => [
{ label => 'read_hits', value => 'hits', template => '%s',
@ -344,25 +359,29 @@ sub set_counters {
{ label => 'read_req', value => 'req', template => '%s',
min => 0, unit => 'ops/s', label_extra_instance => 1, instance_use => 'display' },
{ label => 'read_res', value => 'res', template => '%s',
min => 0, unit => 'ops/s', label_extra_instance => 1, instance_use => 'display' },
],
min => 0, unit => 'ops/s', label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'read-latency', set => {
key_values => [ { name => 'avg_read_latency' }, { name => 'display' } ],
output_template => 'Read latency: %.2f ms',
perfdatas => [
{ label => 'read_latency', value => 'avg_read_latency', template => '%.2f',
min => 0, unit => 'ms', label_extra_instance => 1, instance_use => 'display' },
],
{ label => 'read_latency', template => '%.2f',
min => 0, unit => 'ms', label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'write-rates', set => {
key_values => [ { name => 'write_hits' }, { name => 'write_misses' },
{ name => 'write_req' }, { name => 'write_res' }, { name => 'display' } ],
key_values => [
{ name => 'write_hits' }, { name => 'write_misses' },
{ name => 'write_req' }, { name => 'write_res' }, { name => 'display' }
],
closure_custom_calc => $self->can('custom_operations_calc'),
closure_custom_calc_extra_options => { operation => 'Write', hits => 'write_hits', misses => 'write_misses',
req => 'write_req', res => 'write_res', display => 'display' },
closure_custom_calc_extra_options => {
operation => 'Write', hits => 'write_hits', misses => 'write_misses',
req => 'write_req', res => 'write_res', display => 'display'
},
closure_custom_output => $self->can('custom_operations_output'),
perfdatas => [
{ label => 'write_hits', value => 'hits', template => '%s',
@ -372,17 +391,17 @@ sub set_counters {
{ label => 'write_req', value => 'req', template => '%s',
min => 0, unit => 'ops/s', label_extra_instance => 1, instance_use => 'display' },
{ label => 'write_res', value => 'res', template => '%s',
min => 0, unit => 'ops/s', label_extra_instance => 1, instance_use => 'display' },
],
min => 0, unit => 'ops/s', label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'write-latency', set => {
key_values => [ { name => 'avg_write_latency' }, { name => 'display' } ],
output_template => 'Write latency: %.2f ms',
perfdatas => [
{ label => 'write_latency', value => 'avg_write_latency', template => '%.2f',
min => 0, unit => 'ms', label_extra_instance => 1, instance_use => 'display' },
],
{ label => 'write_latency', template => '%.2f',
min => 0, unit => 'ms', label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'traffic-in', set => {
@ -390,21 +409,21 @@ sub set_counters {
output_template => 'Traffic In: %s %s/s',
output_change_bytes => 2,
perfdatas => [
{ label => 'traffic_in', value => 'ingress', template => '%d',
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' },
],
},
{ label => 'traffic_in', template => '%d',
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'traffic-out', set => {
key_values => [ { name => 'egress' }, { name => 'display' } ],
output_template => 'Traffic Out: %s %s/s',
output_change_bytes => 2,
perfdatas => [
{ label => 'traffic_out', value => 'egress', template => '%d',
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' },
],
},
},
{ label => 'traffic_out', template => '%d',
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' }
]
}
}
];
}
@ -413,26 +432,15 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$options{options}->add_options(arguments =>
{
"filter-database:s" => { name => 'filter_database' },
"units:s" => { name => 'units', default => '%' },
"free" => { name => 'free' },
"warning-status:s" => { name => 'warning_status', default => '' },
"critical-status:s" => { name => 'critical_status', default => '%{status} =~ /creation-failed/i | %{backup_status} =~ /failed/i |
%{export_status} =~ /failed/i | %{import_status} =~ /failed/i' },
});
$options{options}->add_options(arguments => {
'filter-database:s' => { name => 'filter_database' },
'units:s' => { name => 'units', default => '%' },
'free' => { name => 'free' }
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->change_macros(macros => ['warning_status', 'critical_status']);
}
sub manage_selection {
my ($self, %options) = @_;
@ -493,7 +501,7 @@ sub manage_selection {
avg_read_latency => defined($result2->{$database}->{avg_read_latency}) ? $result->{$database}->{avg_read_latency} * 1000 : '0',
avg_write_latency => defined($result2->{$database}->{avg_write_latency}) ? $result->{$database}->{avg_write_latency} * 1000 : '0',
ingress => $result->{$database}->{ingress_bytes} * 8,
egress => $result->{$database}->{egress_bytes} * 8,
egress => $result->{$database}->{egress_bytes} * 8
};
if (scalar(keys %{$self->{databases}}) <= 0) {

View File

@ -18,7 +18,7 @@
# limitations under the License.
#
package apps::redis::restapi::mode::listdatabases;
package apps::redis::rlec::restapi::mode::listdatabases;
use base qw(centreon::plugins::mode);
@ -30,9 +30,8 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$options{options}->add_options(arguments =>
{
});
$options{options}->add_options(arguments => {});
return $self;
}
@ -52,14 +51,17 @@ sub run {
$self->manage_selection(%options);
foreach my $database_uid (sort keys %{$self->{databases}}) {
$self->{output}->output_add(long_msg => '[uid = ' . $database_uid . "] [name = '" . $self->{databases}->{$database_uid}->{name} . "']" .
$self->{output}->output_add(
long_msg => '[uid = ' . $database_uid . "] [name = '" . $self->{databases}->{$database_uid}->{name} . "']" .
" [type = '" . $self->{databases}->{$database_uid}->{type} . "']" .
" [status = '" . $self->{databases}->{$database_uid}->{status} . "']"
);
}
$self->{output}->output_add(severity => 'OK',
short_msg => 'List databases:');
$self->{output}->output_add(
severity => 'OK',
short_msg => 'List databases:'
);
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit();
}
@ -75,10 +77,11 @@ sub disco_show {
$self->manage_selection(%options);
foreach my $database_uid (sort keys %{$self->{databases}}) {
$self->{output}->add_disco_entry(name => $self->{databases}->{$database_uid}->{name},
$self->{output}->add_disco_entry(
name => $self->{databases}->{$database_uid}->{name},
type => $self->{databases}->{$database_uid}->{type},
status => $self->{databases}->{$database_uid}->{status},
uid => $database_uid,
uid => $database_uid
);
}
}

View File

@ -18,7 +18,7 @@
# limitations under the License.
#
package apps::redis::restapi::mode::listnodes;
package apps::redis::rlec::restapi::mode::listnodes;
use base qw(centreon::plugins::mode);
@ -30,9 +30,8 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$options{options}->add_options(arguments =>
{
});
$options{options}->add_options(arguments => {});
return $self;
}
@ -55,8 +54,10 @@ sub run {
$self->{output}->output_add(long_msg => '[uid = ' . $node_uid . "] [status = '" . $self->{nodes}->{$node_uid}->{status} . "']");
}
$self->{output}->output_add(severity => 'OK',
short_msg => 'List nodes:');
$self->{output}->output_add(
severity => 'OK',
short_msg => 'List nodes:'
);
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit();
}
@ -72,8 +73,9 @@ sub disco_show {
$self->manage_selection(%options);
foreach my $node_uid (sort keys %{$self->{nodes}}) {
$self->{output}->add_disco_entry(status => $self->{nodes}->{$node_uid}->{status},
uid => $node_uid,
$self->{output}->add_disco_entry(
status => $self->{nodes}->{$node_uid}->{status},
uid => $node_uid
);
}
}

View File

@ -18,7 +18,7 @@
# limitations under the License.
#
package apps::redis::restapi::mode::listshards;
package apps::redis::rlec::restapi::mode::listshards;
use base qw(centreon::plugins::mode);
@ -30,9 +30,8 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$options{options}->add_options(arguments =>
{
});
$options{options}->add_options(arguments => {});
return $self;
}
@ -52,14 +51,17 @@ sub run {
$self->manage_selection(%options);
foreach my $shard_uid (sort keys %{$self->{shards}}) {
$self->{output}->output_add(long_msg => '[uid = ' . $shard_uid . "] [role = '" . $self->{shards}->{$shard_uid}->{role} . "']" .
$self->{output}->output_add(
long_msg => '[uid = ' . $shard_uid . "] [role = '" . $self->{shards}->{$shard_uid}->{role} . "']" .
" [detailed_status = '" . $self->{shards}->{$shard_uid}->{detailed_status} . "']" .
" [status = '" . $self->{shards}->{$shard_uid}->{status} . "']"
);
}
$self->{output}->output_add(severity => 'OK',
short_msg => 'List shards:');
$self->{output}->output_add(
severity => 'OK',
short_msg => 'List shards:'
);
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit();
}
@ -75,10 +77,11 @@ sub disco_show {
$self->manage_selection(%options);
foreach my $shard_uid (sort keys %{$self->{shards}}) {
$self->{output}->add_disco_entry(role => $self->{shards}->{$shard_uid}->{role},
$self->{output}->add_disco_entry(
role => $self->{shards}->{$shard_uid}->{role},
detailed_status => $self->{shards}->{$shard_uid}->{detailed_status},
status => $self->{shards}->{$shard_uid}->{status},
uid => $shard_uid,
uid => $shard_uid
);
}
}

View File

@ -18,23 +18,24 @@
# limitations under the License.
#
package apps::redis::restapi::mode::nodesstats;
package apps::redis::rlec::restapi::mode::nodesstats;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
sub custom_usage_perfdata {
my ($self, %options) = @_;
$self->{output}->perfdata_add(label => $self->{result_values}->{perf}, unit => 'B',
value => $self->{result_values}->{used},
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{result_values}->{label}, total => $self->{result_values}->{total}, cast_int => 1),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{result_values}->{label}, total => $self->{result_values}->{total}, cast_int => 1),
min => 0, max => $self->{result_values}->{total});
$self->{output}->perfdata_add(
label => $self->{result_values}->{perf}, unit => 'B',
value => $self->{result_values}->{used},
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{result_values}->{label}, total => $self->{result_values}->{total}, cast_int => 1),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{result_values}->{label}, total => $self->{result_values}->{total}, cast_int => 1),
min => 0, max => $self->{result_values}->{total}
);
}
sub custom_usage_threshold {
@ -53,16 +54,17 @@ sub custom_usage_threshold {
sub custom_usage_output {
my ($self, %options) = @_;
my ($used_value, $used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
my ($free_value, $free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
my ($total_value, $total_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total});
my $msg = sprintf("%s usage: Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", $self->{result_values}->{display},
$total_value . " " . $total_unit,
$used_value . " " . $used_unit, $self->{result_values}->{prct_used},
$free_value . " " . $free_unit, $self->{result_values}->{prct_free});
return $msg;
return sprintf(
"%s usage: Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", $self->{result_values}->{display},
$total_value . " " . $total_unit,
$used_value . " " . $used_unit, $self->{result_values}->{prct_used},
$free_value . " " . $free_unit, $self->{result_values}->{prct_free}
);
}
sub custom_usage_calc {
@ -79,9 +81,9 @@ sub custom_usage_calc {
$self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total};
$self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used};
} else {
$self->{result_values}->{used} = '0';
$self->{result_values}->{prct_used} = '0';
$self->{result_values}->{prct_free} = '0';
$self->{result_values}->{used} = 0;
$self->{result_values}->{prct_used} = 0;
$self->{result_values}->{prct_free} = 0;
}
return 0;
@ -90,22 +92,13 @@ sub custom_usage_calc {
sub custom_status_output {
my ($self, %options) = @_;
my $msg = sprintf("Status is '%s' [shard list: %s] [int addr: %s] [ext addr: %s]",
return sprintf(
"Status is '%s' [shard list: %s] [int addr: %s] [ext addr: %s]",
$self->{result_values}->{status},
$self->{result_values}->{shard_list},
$self->{result_values}->{int_addr},
$self->{result_values}->{ext_addr});
return $msg;
}
sub custom_status_calc {
my ($self, %options) = @_;
$self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'};
$self->{result_values}->{shard_list} = $options{new_datas}->{$self->{instance} . '_shard_list'};
$self->{result_values}->{int_addr} = $options{new_datas}->{$self->{instance} . '_int_addr'};
$self->{result_values}->{ext_addr} = $options{new_datas}->{$self->{instance} . '_ext_addr'};
return 0;
$self->{result_values}->{ext_addr}
);
}
sub prefix_output {
@ -118,101 +111,108 @@ sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'nodes', type => 1, cb_prefix_output => 'prefix_output', message_separator => ', ', message_multiple => 'All nodes counters are ok' },
{ name => 'nodes', type => 1, cb_prefix_output => 'prefix_output', message_separator => ', ', message_multiple => 'All nodes counters are ok' }
];
$self->{maps_counters}->{nodes} = [
{ label => 'status', threshold => 0, set => {
{ label => 'status', type => 2, critical_default => '%{status} =~ /down/i', set => {
key_values => [ { name => 'status' }, { name => 'shard_list' }, { name => 'int_addr' }, { name => 'ext_addr' } ],
closure_custom_calc => $self->can('custom_status_calc'),
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold,
closure_custom_threshold_check => \&catalog_status_threshold_ng
}
},
{ label => 'shard-count', set => {
key_values => [ { name => 'shard_count' }, { name => 'display' } ],
output_template => 'Shard count: %d',
perfdatas => [
{ label => 'shard_count', value => 'shard_count', template => '%d',
min => 0, label_extra_instance => 1, instance_use => 'display' },
],
},
{ label => 'shard_count', template => '%d',
min => 0, label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'uptime', set => {
key_values => [ { name => 'uptime' }, { name => 'uptime_sec' }, { name => 'display' } ],
output_template => 'Uptime: %s',
perfdatas => [
{ label => 'uptime', value => 'uptime_sec', template => '%d',
min => 0, unit => 's', label_extra_instance => 1, instance_use => 'display' },
],
},
{ label => 'uptime', template => '%d',
min => 0, unit => 's', label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'cpu-system', set => {
key_values => [ { name => 'cpu_system' }, { name => 'display' } ],
output_template => 'Cpu system: %.2f %%',
perfdatas => [
{ label => 'cpu_system', value => 'cpu_system', template => '%.2f',
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display' },
],
{ label => 'cpu_system', template => '%.2f',
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'cpu-user', set => {
key_values => [ { name => 'cpu_user' }, { name => 'display' } ],
output_template => 'Cpu user: %.2f %%',
perfdatas => [
{ label => 'cpu_user', value => 'cpu_user', template => '%.2f',
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display' },
],
{ label => 'cpu_user', template => '%.2f',
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'memory', set => {
key_values => [ { name => 'free_memory' }, { name => 'total_memory' } ],
closure_custom_calc => $self->can('custom_usage_calc'),
closure_custom_calc_extra_options => { display => 'Ram', label => 'memory', perf => 'memory',
free => 'free_memory', total => 'total_memory' },
closure_custom_calc_extra_options => {
display => 'Ram', label => 'memory', perf => 'memory',
free => 'free_memory', total => 'total_memory'
},
closure_custom_output => $self->can('custom_usage_output'),
closure_custom_perfdata => $self->can('custom_usage_perfdata'),
closure_custom_threshold_check => $self->can('custom_usage_threshold'),
closure_custom_threshold_check => $self->can('custom_usage_threshold')
}
},
{ label => 'persistent-storage', set => {
key_values => [ { name => 'persistent_storage_free' }, { name => 'persistent_storage_size' } ],
closure_custom_calc => $self->can('custom_usage_calc'),
closure_custom_calc_extra_options => { display => 'Persistent storage', label => 'persistent-storage', perf => 'persistent_storage',
free => 'persistent_storage_free', total => 'persistent_storage_size' },
closure_custom_calc_extra_options => {
display => 'Persistent storage', label => 'persistent-storage', perf => 'persistent_storage',
free => 'persistent_storage_free', total => 'persistent_storage_size'
},
closure_custom_output => $self->can('custom_usage_output'),
closure_custom_perfdata => $self->can('custom_usage_perfdata'),
closure_custom_threshold_check => $self->can('custom_usage_threshold'),
closure_custom_threshold_check => $self->can('custom_usage_threshold')
}
},
{ label => 'ephemeral-storage', set => {
key_values => [ { name => 'ephemeral_storage_free' }, { name => 'ephemeral_storage_size' } ],
closure_custom_calc => $self->can('custom_usage_calc'),
closure_custom_calc_extra_options => { display => 'Ephemeral storage', label => 'ephemeral-storage', perf => 'ephemeral_storage',
free => 'ephemeral_storage_free', total => 'ephemeral_storage_size' },
closure_custom_calc_extra_options => {
display => 'Ephemeral storage', label => 'ephemeral-storage', perf => 'ephemeral_storage',
free => 'ephemeral_storage_free', total => 'ephemeral_storage_size'
},
closure_custom_output => $self->can('custom_usage_output'),
closure_custom_perfdata => $self->can('custom_usage_perfdata'),
closure_custom_threshold_check => $self->can('custom_usage_threshold'),
closure_custom_threshold_check => $self->can('custom_usage_threshold')
}
},
{ label => 'flash-storage', set => {
key_values => [ { name => 'bigstore_free' }, { name => 'bigstore_size' } ],
closure_custom_calc => $self->can('custom_usage_calc'),
closure_custom_calc_extra_options => { display => 'Flash storage', label => 'flash-storage', perf => 'flash_storage',
free => 'bigstore_free', total => 'bigstore_size' },
closure_custom_calc_extra_options => {
display => 'Flash storage', label => 'flash-storage', perf => 'flash_storage',
free => 'bigstore_free', total => 'bigstore_size'
},
closure_custom_output => $self->can('custom_usage_output'),
closure_custom_perfdata => $self->can('custom_usage_perfdata'),
closure_custom_threshold_check => $self->can('custom_usage_threshold'),
closure_custom_threshold_check => $self->can('custom_usage_threshold')
}
},
{ label => 'flash-iops', set => {
key_values => [ { name => 'bigstore_iops' }, { name => 'display' } ],
output_template => 'Flash IOPS: %s ops/s',
perfdatas => [
{ label => 'flash_iops', value => 'bigstore_iops', template => '%s',
min => 0, unit => 'ops/s', label_extra_instance => 1, instance_use => 'display' },
],
{ label => 'flash_iops', template => '%s',
min => 0, unit => 'ops/s', label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'flash-throughput', set => {
@ -220,8 +220,8 @@ sub set_counters {
output_template => 'Flash throughput: %s %s/s',
output_change_bytes => 1,
perfdatas => [
{ label => 'flash_throughput', value => 'bigstore_throughput', template => '%s',
min => 0, unit => 'B/s', label_extra_instance => 1, instance_use => 'display' },
{ label => 'flash_throughput', template => '%s',
min => 0, unit => 'B/s', label_extra_instance => 1, instance_use => 'display' }
],
}
},
@ -229,18 +229,17 @@ sub set_counters {
key_values => [ { name => 'conns' }, { name => 'display' } ],
output_template => 'Connections: %s',
perfdatas => [
{ label => 'connections', value => 'conns', template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display' },
],
{ label => 'connections', template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'requests', set => {
key_values => [ { name => 'total_req' } ],
output_template => 'Requests rate: %s ops/s',
perfdatas => [
{ label => 'requests', value => 'total_req', template => '%s',
min => 0, unit => 'ops/s' },
],
{ label => 'requests', template => '%s', min => 0, unit => 'ops/s' }
]
}
},
{ label => 'traffic-in', set => {
@ -248,21 +247,21 @@ sub set_counters {
output_template => 'Traffic In: %s %s/s',
output_change_bytes => 2,
perfdatas => [
{ label => 'traffic_in', value => 'ingress', template => '%d',
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' },
],
},
{ label => 'traffic_in', template => '%d',
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'traffic-out', set => {
key_values => [ { name => 'egress' }, { name => 'display' } ],
output_template => 'Traffic Out: %s %s/s',
output_change_bytes => 2,
perfdatas => [
{ label => 'traffic_out', value => 'egress', template => '%d',
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' },
],
},
},
{ label => 'traffic_out', template => '%d',
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' }
]
}
}
];
}
@ -270,26 +269,16 @@ sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$options{options}->add_options(arguments =>
{
"filter-node:s" => { name => 'filter_node' },
"units:s" => { name => 'units', default => '%' },
"free" => { name => 'free' },
"warning-status:s" => { name => 'warning_status', default => '' },
"critical-status:s" => { name => 'critical_status', default => '%{status} =~ /down/i' },
});
$options{options}->add_options(arguments => {
'filter-node:s' => { name => 'filter_node' },
'units:s' => { name => 'units', default => '%' },
'free' => { name => 'free' }
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->change_macros(macros => ['warning_status', 'critical_status']);
}
sub manage_selection {
my ($self, %options) = @_;

View File

@ -18,51 +18,40 @@
# limitations under the License.
#
package apps::redis::restapi::mode::shardsstats;
package apps::redis::rlec::restapi::mode::shardsstats;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
sub custom_status_output {
my ($self, %options) = @_;
my $msg = sprintf("Status is '%s' (%s) [role: %s] [loading status: %s] [backup status: %s]",
my $msg = sprintf(
"Status is '%s' (%s) [role: %s] [loading status: %s] [backup status: %s]",
$self->{result_values}->{status},
$self->{result_values}->{detailed_status},
$self->{result_values}->{role},
$self->{result_values}->{loading},
$self->{result_values}->{backup});
$self->{result_values}->{backup}
);
if ($self->{result_values}->{role} eq 'slave') {
$msg .= sprintf(" [sync status: %s]",
$self->{result_values}->{sync});
$msg .= sprintf(" [sync status: %s]", $self->{result_values}->{sync});
}
return $msg;
}
sub custom_status_calc {
my ($self, %options) = @_;
$self->{result_values}->{role} = $options{new_datas}->{$self->{instance} . '_role'};
$self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'};
$self->{result_values}->{detailed_status} = $options{new_datas}->{$self->{instance} . '_detailed_status'};
$self->{result_values}->{loading} = $options{new_datas}->{$self->{instance} . '_loading'};
$self->{result_values}->{sync} = $options{new_datas}->{$self->{instance} . '_sync'};
$self->{result_values}->{backup} = $options{new_datas}->{$self->{instance} . '_backup'};
return 0;
}
sub custom_operations_output {
my ($self, %options) = @_;
my $msg = sprintf("%s operations rates (hits/misses): %s/%s ops/s",
return sprintf(
"%s operations rates (hits/misses): %s/%s ops/s",
$self->{result_values}->{operation},
$self->{result_values}->{hits},
$self->{result_values}->{misses});
return $msg;
$self->{result_values}->{misses}
);
}
sub custom_operations_calc {
@ -78,11 +67,12 @@ sub custom_operations_calc {
sub custom_cpu_output {
my ($self, %options) = @_;
my $msg = sprintf("%s CPU usage (user/system): %s/%s %%",
return sprintf(
"%s CPU usage (user/system): %s/%s %%",
$self->{result_values}->{cpu},
$self->{result_values}->{user},
$self->{result_values}->{system});
return $msg;
$self->{result_values}->{system}
);
}
sub custom_cpu_calc {
@ -105,59 +95,66 @@ sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'shards', type => 1, cb_prefix_output => 'prefix_output', message_multiple => 'All shards counters are ok' },
{ name => 'shards', type => 1, cb_prefix_output => 'prefix_output', message_multiple => 'All shards counters are ok' }
];
$self->{maps_counters}->{shards} = [
{ label => 'status', threshold => 0, set => {
key_values => [ { name => 'status' }, { name => 'detailed_status' }, { name => 'role' },
{ name => 'loading' }, { name => 'sync' }, { name => 'backup' } ],
closure_custom_calc => $self->can('custom_status_calc'),
{ label => 'status', type => 2, critical_default => '%{status} =~ /inactive/i || %{backup} =~ /failed/i || %{sync} =~ /link_down/i', set => {
key_values => [
{ name => 'status' }, { name => 'detailed_status' }, { name => 'role' },
{ name => 'loading' }, { name => 'sync' }, { name => 'backup' }
],
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold,
closure_custom_threshold_check => \&catalog_status_threshold_ng
}
},
{ label => 'total-cpu', set => {
key_values => [ { name => 'shard_cpu_user' }, { name => 'shard_cpu_system' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_cpu_calc'),
closure_custom_calc_extra_options => { cpu => 'Total', user => 'shard_cpu_user',
system => 'shard_cpu_system', display => 'display' },
closure_custom_calc_extra_options => {
cpu => 'Total', user => 'shard_cpu_user',
system => 'shard_cpu_system', display => 'display'
},
closure_custom_output => $self->can('custom_cpu_output'),
perfdatas => [
{ label => 'total_cpu_user', value => 'user', template => '%s',
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display' },
{ label => 'total_cpu_system', value => 'system', template => '%s',
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display' },
],
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'fork-cpu', set => {
key_values => [ { name => 'fork_cpu_user' }, { name => 'fork_cpu_system' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_cpu_calc'),
closure_custom_calc_extra_options => { cpu => 'Fork', user => 'fork_cpu_user',
system => 'fork_cpu_system', display => 'display' },
closure_custom_calc_extra_options => {
cpu => 'Fork', user => 'fork_cpu_user',
system => 'fork_cpu_system', display => 'display'
},
closure_custom_output => $self->can('custom_cpu_output'),
perfdatas => [
{ label => 'fork_cpu_user', value => 'user', template => '%s',
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display' },
{ label => 'fork_cpu_system', value => 'system', template => '%s',
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display' },
],
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'main-thread-cpu', set => {
key_values => [ { name => 'main_thread_cpu_user' }, { name => 'main_thread_cpu_system' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_cpu_calc'),
closure_custom_calc_extra_options => { cpu => 'Main thread', user => 'main_thread_cpu_user',
system => 'main_thread_cpu_system', display => 'display' },
closure_custom_calc_extra_options => {
cpu => 'Main thread', user => 'main_thread_cpu_user',
system => 'main_thread_cpu_system', display => 'display'
},
closure_custom_output => $self->can('custom_cpu_output'),
perfdatas => [
{ label => 'main_thread_cpu_user', value => 'user', template => '%s',
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display' },
{ label => 'main_thread_cpu_system', value => 'system', template => '%s',
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display' },
],
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'memory', set => {
@ -165,129 +162,133 @@ sub set_counters {
output_template => 'Memory used: %s %s',
output_change_bytes => 1,
perfdatas => [
{ label => 'memory', value => 'used_memory', template => '%s',
min => 0, unit => 'B', label_extra_instance => 1, instance_use => 'display' },
],
{ label => 'memory', template => '%s',
min => 0, unit => 'B', label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'mem-frag-ratio', set => {
key_values => [ { name => 'mem_frag_ratio' }, { name => 'display' } ],
output_template => 'Memory fragmentation ratio: %s',
perfdatas => [
{ label => 'mem_frag_ratio', value => 'mem_frag_ratio', template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display' },
],
{ label => 'mem_frag_ratio', template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'connected-clients', set => {
key_values => [ { name => 'connected_clients' }, { name => 'display' } ],
output_template => 'Connected clients: %s',
perfdatas => [
{ label => 'connected_clients', value => 'connected_clients', template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display' },
],
{ label => 'connected_clients', template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'blocked-clients', set => {
key_values => [ { name => 'blocked_clients' }, { name => 'display' } ],
output_template => 'Blocked clients: %s',
perfdatas => [
{ label => 'blocked_clients', value => 'blocked_clients', template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display' },
],
{ label => 'blocked_clients', template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'requests', set => {
key_values => [ { name => 'total_req'}, { name => 'display' }],
output_template => 'Requests rate: %s ops/s',
perfdatas => [
{ label => 'requests', value => 'total_req', template => '%s',
min => 0, unit => 'ops/s', label_extra_instance => 1, instance_use => 'display' },
],
{ label => 'requests', template => '%s',
min => 0, unit => 'ops/s', label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'keys', set => {
key_values => [ { name => 'no_of_keys' }, { name => 'display' } ],
output_template => 'Total keys: %s',
perfdatas => [
{ label => 'keys', value => 'no_of_keys', template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display' },
],
{ label => 'keys', template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'volatile-keys', set => {
key_values => [ { name => 'no_of_expires' }, { name => 'display' } ],
output_template => 'Volatile keys: %s',
perfdatas => [
{ label => 'volatile_keys', value => 'no_of_expires', template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display' },
],
{ label => 'volatile_keys', template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'evicted-objects', set => {
key_values => [ { name => 'evicted_objects' }, { name => 'display' } ],
output_template => 'Evicted objects rate: %s evictions/sec',
perfdatas => [
{ label => 'evicted_objects', value => 'evicted_objects', template => '%s',
min => 0, unit => 'evictions/sec', label_extra_instance => 1, instance_use => 'display' },
],
{ label => 'evicted_objects', template => '%s',
min => 0, unit => 'evictions/sec', label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'expired-objects', set => {
key_values => [ { name => 'expired_objects' }, { name => 'display' } ],
output_template => 'Expired objects rate: %s expirations/sec',
perfdatas => [
{ label => 'expired_objects', value => 'expired_objects', template => '%s',
min => 0, unit => 'expirations/sec', label_extra_instance => 1, instance_use => 'display' },
],
{ label => 'expired_objects', template => '%s',
min => 0, unit => 'expirations/sec', label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'read-rates', set => {
key_values => [ { name => 'read_hits' }, { name => 'read_misses' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_operations_calc'),
closure_custom_calc_extra_options => { operation => 'Read', hits => 'read_hits',
misses => 'read_misses', display => 'display' },
closure_custom_calc_extra_options => {
operation => 'Read', hits => 'read_hits',
misses => 'read_misses', display => 'display'
},
closure_custom_output => $self->can('custom_operations_output'),
perfdatas => [
{ label => 'read_hits', value => 'hits', template => '%s',
min => 0, unit => 'ops/s', label_extra_instance => 1, instance_use => 'display' },
{ label => 'read_misses', value => 'misses', template => '%s',
min => 0, unit => 'ops/s', label_extra_instance => 1, instance_use => 'display' },
],
min => 0, unit => 'ops/s', label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'write-rates', set => {
key_values => [ { name => 'write_hits' }, { name => 'write_misses' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_operations_calc'),
closure_custom_calc_extra_options => { operation => 'Write', hits => 'write_hits',
misses => 'write_misses', display => 'display' },
closure_custom_calc_extra_options => {
operation => 'Write', hits => 'write_hits',
misses => 'write_misses', display => 'display'
},
closure_custom_output => $self->can('custom_operations_output'),
perfdatas => [
{ label => 'write_hits', value => 'hits', template => '%s',
min => 0, unit => 'ops/s', label_extra_instance => 1, instance_use => 'display' },
{ label => 'write_misses', value => 'misses', template => '%s',
min => 0, unit => 'ops/s', label_extra_instance => 1, instance_use => 'display' },
],
min => 0, unit => 'ops/s', label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'rdb-changes-since-last-save', set => {
key_values => [ { name => 'rdb_changes_since_last_save' }, { name => 'display' } ],
output_template => 'Rdb changes since last save: %s',
perfdatas => [
{ label => 'rdb_changes_since_last_save', value => 'rdb_changes_since_last_save', template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display' },
],
{ label => 'rdb_changes_since_last_save', template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'last-save-time', set => {
key_values => [ { name => 'last_save_time' }, { name => 'last_save_time_sec' }, { name => 'display' } ],
output_template => 'Last same time: %s',
perfdatas => [
{ label => 'last_save_time', value => 'last_save_time_sec', template => '%s',
min => 0, unit => 's', label_extra_instance => 1, instance_use => 'display' },
],
{ label => 'last_save_time', template => '%s',
min => 0, unit => 's', label_extra_instance => 1, instance_use => 'display' }
]
}
},
}
];
}
@ -295,25 +296,14 @@ sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$options{options}->add_options(arguments =>
{
"filter-shard:s" => { name => 'filter_shard' },
"warning-status:s" => { name => 'warning_status', default => '' },
"critical-status:s" => { name => 'critical_status', default => '%{status} =~ /inactive/i | %{backup} =~ /failed/i |
%{sync} =~ /link_down/i' },
});
$options{options}->add_options(arguments => {
'filter-shard:s' => { name => 'filter_shard' }
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->change_macros(macros => ['warning_status', 'critical_status']);
}
sub manage_selection {
my ($self, %options) = @_;
@ -356,7 +346,7 @@ sub manage_selection {
write_misses => $result->{$shard}->{write_misses},
rdb_changes_since_last_save => $result->{$shard}->{rdb_changes_since_last_save},
last_save_time => centreon::plugins::misc::change_seconds(value => time() - $result->{$shard}->{last_save_time}),
last_save_time_sec => time() - $result->{$shard}->{last_save_time},
last_save_time_sec => time() - $result->{$shard}->{last_save_time}
};
if (scalar(keys %{$self->{shards}}) <= 0) {
@ -396,8 +386,8 @@ Can used special variables like: %{status}, %{detailed_status},
=item B<--critical-status>
Set critical threshold for status (Default: '%{status} =~ /inactive/i |
%{backup} =~ /failed/i | %{sync} =~ /link_down/i').
Set critical threshold for status (Default: '%{status} =~ /inactive/i ||
%{backup} =~ /failed/i || %{sync} =~ /link_down/i').
Can used special variables like: %{status}, %{detailed_status},
%{role}, %{loading}, %{sync}, %{backup}.
'status' can be: 'active', 'inactive', 'trimming'.

View File

@ -18,7 +18,7 @@
# limitations under the License.
#
package apps::redis::restapi::plugin;
package apps::redis::rlec::restapi::plugin;
use strict;
use warnings;
@ -30,17 +30,17 @@ sub new {
bless $self, $class;
$self->{version} = '0.1';
%{$self->{modes}} = (
'databases-stats' => 'apps::redis::restapi::mode::databasesstats',
'cluster-stats' => 'apps::redis::restapi::mode::clusterstats',
'list-databases' => 'apps::redis::restapi::mode::listdatabases',
'list-nodes' => 'apps::redis::restapi::mode::listnodes',
'list-shards' => 'apps::redis::restapi::mode::listshards',
'nodes-stats' => 'apps::redis::restapi::mode::nodesstats',
'shards-stats' => 'apps::redis::restapi::mode::shardsstats',
);
$self->{modes} = {
'databases-stats' => 'apps::redis::rlec::restapi::mode::databasesstats',
'cluster-stats' => 'apps::redis::rlec::restapi::mode::clusterstats',
'list-databases' => 'apps::redis::rlec::restapi::mode::listdatabases',
'list-nodes' => 'apps::redis::rlec::restapi::mode::listnodes',
'list-shards' => 'apps::redis::rlec::restapi::mode::listshards',
'nodes-stats' => 'apps::redis::rlec::restapi::mode::nodesstats',
'shards-stats' => 'apps::redis::rlec::restapi::mode::shardsstats'
};
$self->{custom_modes}{api} = 'apps::redis::restapi::custom::api';
$self->{custom_modes}->{api} = 'apps::redis::rlec::restapi::custom::api';
return $self;
}

View File

@ -0,0 +1,304 @@
#
# Copyright 2021 Centreon (http://www.centreon.com/)
#
# 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.
#
package database::redis::custom::cli;
use strict;
use warnings;
use centreon::plugins::ssh;
use centreon::plugins::misc;
use Digest::MD5 qw(md5_hex);
sub new {
my ($class, %options) = @_;
my $self = {};
bless $self, $class;
if (!defined($options{output})) {
print "Class Custom: Need to specify 'output' argument.\n";
exit 3;
}
if (!defined($options{options})) {
$options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument.");
$options{output}->option_exit();
}
if (!defined($options{noptions})) {
$options{options}->add_options(arguments => {
'ssh-hostname:s' => { name => 'ssh_hostname' },
'server:s' => { name => 'server' },
'port:s' => { name => 'port' },
'username:s' => { name => 'username' },
'password:s' => { name => 'password' },
'sentinel:s@' => { name => 'sentinel' },
'sentinel-port:s' => { name => 'sentinel_port' },
'service:s' => { name => 'service' },
'tls' => { name => 'tls' },
'cacert:s' => { name => 'cacert' },
'insecure' => { name => 'insecure' },
'timeout:s' => { name => 'timeout' }
});
}
$options{options}->add_help(package => __PACKAGE__, sections => 'REDIS OPTIONS', once => 1);
$self->{output} = $options{output};
$self->{ssh} = centreon::plugins::ssh->new(%options);
return $self;
}
sub set_options {
my ($self, %options) = @_;
$self->{option_results} = $options{option_results};
}
sub set_defaults {}
sub check_options {
my ($self, %options) = @_;
$self->{ssh_hostname} = defined($self->{option_results}->{ssh_hostname}) && $self->{option_results}->{ssh_hostname} ne '' ? $self->{option_results}->{ssh_hostname} : '';
$self->{server} = defined($self->{option_results}->{server}) && $self->{option_results}->{server} ne '' ? $self->{option_results}->{server} : '';
$self->{port} = defined($self->{option_results}->{port}) && $self->{option_results}->{port} ne '' ? $self->{option_results}->{port} : 6379;
$self->{sentinel_port} = defined($self->{option_results}->{sentinel_port}) && $self->{option_results}->{sentinel_port} =~ /(\d+)/ ? $1 : 26379;
$self->{username} = defined($self->{option_results}->{password}) && $self->{option_results}->{username} ne '' ? $self->{option_results}->{username} : '';
$self->{password} = defined($self->{option_results}->{password}) && $self->{option_results}->{password} ne '' ? $self->{option_results}->{password} : '';
$self->{timeout} = defined($self->{option_results}->{timeout}) && $self->{option_results}->{timeout} =~ /(\d+)/ ? $1 : 10;
$self->{tls} = defined($self->{option_results}->{tls}) ? 1 : 0;
$self->{insecure} = defined($self->{option_results}->{insecure}) ? 1 : 0;
$self->{cacert} = defined($self->{option_results}->{cacert}) && $self->{option_results}->{cacert} ne '' ? $self->{option_results}->{cacert} : '';
$self->{sentinel} = [];
if (defined($self->{option_results}->{sentinel})) {
foreach my $addr (@{$self->{option_results}->{sentinel}}) {
next if ($addr eq '');
push @{$self->{sentinel}}, $addr . ($self->{sentinel_port} ne '' ? ':' . $self->{sentinel_port} : '')
}
}
$self->{service} = defined($self->{option_results}->{service}) && $self->{option_results}->{service} ne '' ? $self->{option_results}->{service} : '';
if ($self->{server} eq '' && scalar(@{$self->{sentinel}}) <= 0) {
$self->{output}->add_option_msg(short_msg => 'Need to specify --server or --sentinel option.');
$self->{output}->option_exit();
}
if (scalar(@{$self->{sentinel}}) > 0 && $self->{service} eq '') {
$self->{output}->add_option_msg(short_msg => 'Need to specify --service option.');
$self->{output}->option_exit();
}
if ($self->{ssh_hostname} ne '') {
$self->{option_results}->{hostname} = $self->{ssh_hostname};
$self->{ssh}->check_options(option_results => $self->{option_results});
}
if ($self->{username} ne '' && $self->{option_results}->{password} eq '') {
$self->{output}->add_option_msg(short_msg => 'Need to specify --password option.');
$self->{output}->option_exit();
}
return 0;
}
sub get_connection_info {
my ($self, %options) = @_;
my $id = '';
if ($self->{server} ne '') {
$id = $self->{server} . ':' . $self->{port};
} else {
foreach (@{$self->{sentinel}}) {
$id .= $_ . '-';
}
}
return md5_hex($id);
}
sub execute_command {
my ($self, %options) = @_;
my $timeout = $self->{timeout};
if (!defined($timeout)) {
$timeout = defined($options{timeout}) ? $options{timeout} : 10;
}
my ($stdout, $exit_code);
if ($self->{ssh_hostname} ne '') {
($stdout, $exit_code) = $self->{ssh}->execute(
hostname => $self->{ssh_hostname},
sudo => $self->{option_results}->{sudo},
command => $options{command},
command_path => $options{command_path},
command_options => $options{command_options},
timeout => $timeout,
no_quit => $options{no_quit}
);
} else {
($stdout, $exit_code) = centreon::plugins::misc::execute(
output => $self->{output},
sudo => $self->{option_results}->{sudo},
options => { timeout => $timeout },
command => $options{command},
command_path => $options{command_path},
command_options => $options{command_options},
no_quit => $options{no_quit}
);
}
$self->{output}->output_add(long_msg => "command response: $stdout", debug => 1);
return ($stdout, $exit_code);
}
sub get_extra_options {
my ($self, %options) = @_;
my $options = '';
$options .= ' --tls' if ($self->{tls} == 1);
$options .= " --cacert '" . $self->{cacert} . "'" if ($self->{cacert} ne '');
$options .= ' --insecure' if ($self->{insecure} == 1);
$options .= " --user '" . $self->{username} . "'" if ($self->{username} ne '');
$options .= " -a '" . $self->{password} . "'" if ($self->{password} ne '');
return $options;
}
sub sentinels_get_master {
my ($self, %options) = @_;
my ($host, $port);
foreach my $addr (@{$self->{sentinel}}) {
my ($sentinel_host, $sentinel_port) = split(/:/, $addr);
my $command_options = "-h '" . $sentinel_host . "' -p " . (defined($sentinel_port) ? $sentinel_port : 26379);
$command_options .= ' sentinel get-master-addr-by-name ' . $self->{service};
my ($stdout, $exit_code) = $self->execute_command(
command => 'redis-cli',
command_options => $command_options,
no_quit => 1
);
next if ($exit_code != 0);
$host = $1 if ($stdout =~ /1\) "(.*?)"/m);
$port = $2 if ($stdout =~ /2\) "(\d+)"/m);
last if (defined($port));
}
if (!defined($port)) {
$self->{output}->add_option_msg(short_msg => 'Cannot find redis master (sentinels)');
$self->{output}->option_exit();
}
return ($host, $port);
}
sub get_info {
my ($self, %options) = @_;
my $command_options;
if (scalar(@{$self->{sentinel}}) > 0) {
my ($host, $port) = $self->sentinels_get_master();
$command_options = "-h '" . $host . "' -p " . $port;
} else {
$command_options = "-h '" . $self->{server} . "' -p " . $self->{port};
}
$command_options .= $self->get_extra_options();
$command_options .= ' info';
my ($stdout) = $self->execute_command(
command => 'redis-cli',
command_options => $command_options
);
my $items = {};
foreach my $line (split /\n/, $stdout) {
if ($line =~ /^(.*?):(.*)$/) {
$items->{$1} = $2;
}
}
return $items;
}
1;
__END__
=head1 NAME
redis-cli.
=head1 SYNOPSIS
redis-cli.
=head1 REDIS OPTIONS
=over 8
=item B<--server>
Redis server.
=item B<--port>
Redis port (Default: 6379).
=item B<--tls>
Establish a secure TLS connection (redis-cli >= 6.x mandatory).
=item B<--cacert>
CA Certificate file to verify with (redis-cli >= 6.x mandatory).
=item B<--insecure>
Allow insecure TLS connection by skipping cert validation (Since redis-cli 6.2.0).
=item B<--username>
Redis username (redis-cli >= 6.x mandatory).
=item B<--password>
Redis password.
=item B<--sentinel>
Sentinel server. Alternative of server option. service option is required.
=item B<--sentinel-port>
Sentinel port (Default: 26379).
=item B<--service>
Service parameter.
=item B<--ssh-hostname>
Remote ssh redis-cli execution.
=item B<--timeout>
Timeout in seconds for the command (Default: 10).
=back
=head1 DESCRIPTION
B<custom>.
=cut

View File

@ -0,0 +1,187 @@
#
# Copyright 2021 Centreon (http://www.centreon.com/)
#
# 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.
#
package database::redis::custom::perlmod;
use strict;
use warnings;
use Redis;
use Digest::MD5 qw(md5_hex);
sub new {
my ($class, %options) = @_;
my $self = {};
bless $self, $class;
if (!defined($options{output})) {
print "Class Custom: Need to specify 'output' argument.\n";
exit 3;
}
if (!defined($options{options})) {
$options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument.");
$options{output}->option_exit();
}
if (!defined($options{noptions})) {
$options{options}->add_options(arguments => {
'server:s' => { name => 'server' },
'port:s' => { name => 'port' },
'username:s' => { name => 'username' },
'password:s' => { name => 'password' },
'sentinel:s@' => { name => 'sentinel' },
'sentinel-port:s' => { name => 'sentinel_port' },
'service:s' => { name => 'service' }
});
}
$options{options}->add_help(package => __PACKAGE__, sections => 'REDIS OPTIONS', once => 1);
$self->{output} = $options{output};
return $self;
}
sub set_options {
my ($self, %options) = @_;
$self->{option_results} = $options{option_results};
}
sub set_defaults {}
sub check_options {
my ($self, %options) = @_;
$self->{server} = defined($self->{option_results}->{server}) && $self->{option_results}->{server} ne '' ? $self->{option_results}->{server} : '';
$self->{port} = defined($self->{option_results}->{port}) && $self->{option_results}->{port} =~ /(\d+)/ ? $1 : 6379;
$self->{sentinel_port} = defined($self->{option_results}->{sentinel_port}) && $self->{option_results}->{sentinel_port} =~ /(\d+)/ ? $1 : 26379;
$self->{username} = defined($self->{option_results}->{username}) && $self->{option_results}->{username} ne '' ? $self->{option_results}->{username} : '';
$self->{password} = defined($self->{option_results}->{password}) && $self->{option_results}->{password} ne '' ? $self->{option_results}->{password} : '';
$self->{sentinel} = [];
if (defined($self->{option_results}->{sentinel})) {
foreach my $addr (@{$self->{option_results}->{sentinel}}) {
next if ($addr eq '');
push @{$self->{sentinel}}, $addr . ($self->{sentinel_port} ne '' ? ':' . $self->{sentinel_port} : '')
}
}
$self->{service} = defined($self->{option_results}->{service}) && $self->{option_results}->{service} ne '' ? $self->{option_results}->{service} : '';
if ($self->{server} eq '' && scalar(@{$self->{sentinel}}) <= 0) {
$self->{output}->add_option_msg(short_msg => 'Need to specify --server or --sentinel option.');
$self->{output}->option_exit();
}
if (scalar(@{$self->{sentinel}}) > 0 && $self->{service} eq '') {
$self->{output}->add_option_msg(short_msg => 'Need to specify --service option.');
$self->{output}->option_exit();
}
if ($self->{username} ne '') {
$self->{output}->add_option_msg(short_msg => 'Unsupported --username option.');
$self->{output}->option_exit();
}
return 0;
}
sub get_connection_info {
my ($self, %options) = @_;
my $id = '';
if ($self->{server} ne '') {
$id = $self->{server} . ':' . $self->{port};
} else {
foreach (@{$self->{sentinel}}) {
$id .= $_ . '-';
}
}
return md5_hex($id);
}
sub get_info {
my ($self, %options) = @_;
my $redis;
if (scalar(@{$self->{sentinel}}) > 0) {
$redis = Redis->new(sentinels => $self->{sentinel}, service => $self->{service});
} else {
$redis = Redis->new(server => $self->{server} . ':' . $self->{port});
}
if ($self->{password} ne '') {
$redis->auth($self->{password});
}
my $response = $redis->info();
my $items;
foreach my $attributes (keys %$response) {
$items->{$attributes} = $response->{$attributes};
}
$redis->quit();
return $items;
}
1;
__END__
=head1 NAME
REDIS perlmod
=head1 SYNOPSIS
Redis perlmod
=head1 REDIS OPTIONS
=over 8
=item B<--server>
Redis server.
=item B<--port>
Redis port (Default: 6379).
=item B<--password>
Redis password.
=item B<--sentinel>
Sentinel server. Alternative of server option. service option is required.
=item B<--sentinel-port>
Sentinel port (Default: 26379).
=item B<--service>
Service parameter.
=back
=head1 DESCRIPTION
B<custom>.
=cut

View File

@ -18,65 +18,68 @@
# limitations under the License.
#
package apps::redis::cli::mode::clients;
package database::redis::mode::clients;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
sub prefix_output {
my ($self, %options) = @_;
return 'Clients ';
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0 },
{ name => 'global', type => 0, cb_prefix_output => 'prefix_output', skipped_code => { -10 => 1 } }
];
$self->{maps_counters}->{global} = [
{ label => 'connected-clients', set => {
{ label => 'connected-clients', nlabel => 'clients.connected.count', set => {
key_values => [ { name => 'connected_clients' } ],
output_template => 'Connected clients: %s',
output_template => 'connected: %s',
perfdatas => [
{ label => 'connected_clients', value => 'connected_clients', template => '%s', min => 0 },
],
},
{ template => '%s', min => 0 }
]
}
},
{ label => 'blocked-clients', set => {
{ label => 'blocked-clients', nlabel => 'clients.blocked.count', set => {
key_values => [ { name => 'blocked_clients' } ],
output_template => 'Blocked clients: %s',
output_template => 'blocked: %s',
perfdatas => [
{ label => 'blocked_clients', value => 'blocked_clients', template => '%s', min => 0 },
],
},
{ template => '%s', min => 0 }
]
}
},
{ label => 'client-longest-output-list', set => {
{ label => 'client-longest-output-list', nlabel => 'clients.longest_output_list.count', set => {
key_values => [ { name => 'client_longest_output_list' } ],
output_template => 'Client longest output list: %s',
output_template => 'longest output list: %s',
perfdatas => [
{ label => 'client_longest_output_list', value => 'client_longest_output_list', template => '%s', min => 0 },
],
},
{ label => 'client_longest_output_list', template => '%s', min => 0 }
]
}
},
{ label => 'client-biggest-input-buf', set => {
{ label => 'client-biggest-input-buf', nlabel => 'clients.biggest_input_buffer.count', set => {
key_values => [ { name => 'client_biggest_input_buf' } ],
output_template => 'Client biggest input buffer: %s',
output_template => 'client biggest input buffer: %s',
perfdatas => [
{ label => 'client_biggest_input_buf', value => 'client_biggest_input_buf', template => '%s', min => 0 },
],
},
{ template => '%s', min => 0 }
]
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments =>
{
});
$options{options}->add_options(arguments => {});
return $self;
}
@ -86,10 +89,10 @@ sub manage_selection {
my $results = $options{custom}->get_info();
$self->{global} = {
connected_clients => $results->{connected_clients},
blocked_clients => $results->{blocked_clients},
client_longest_output_list => $results->{client_longest_output_list},
client_biggest_input_buf => $results->{client_biggest_input_buf},
connected_clients => $results->{connected_clients},
blocked_clients => $results->{blocked_clients},
client_longest_output_list => $results->{client_longest_output_list},
client_biggest_input_buf => $results->{client_biggest_input_buf}
};
}

View File

@ -18,7 +18,7 @@
# limitations under the License.
#
package apps::redis::cli::mode::commands;
package database::redis::mode::commands;
use base qw(centreon::plugins::templates::counter);
@ -26,48 +26,45 @@ use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
sub prefix_output {
my ($self, %options) = @_;
return 'Number of commands processed: ';
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0, cb_prefix_output => 'prefix_output' },
{ name => 'global', type => 0, message_separator => ' ', cb_prefix_output => 'prefix_output' }
];
$self->{maps_counters}->{global} = [
{ label => 'processed-commands', set => {
{ label => 'processed-commands', nlabel => 'commands.processed.count', set => {
key_values => [ { name => 'total_commands_processed', diff => 1 } ],
output_template => 'Processed: %s',
output_template => '%s',
perfdatas => [
{ label => 'processed_commands', value => 'total_commands_processed', template => '%s', min => 0 },
],
},
{ template => '%s', min => 0 }
]
}
},
{ label => 'ops-per-sec', set => {
{ label => 'ops-per-sec', nlabel => 'commands.processed.persecond', set => {
key_values => [ { name => 'instantaneous_ops_per_sec' } ],
output_template => 'Processed per sec: %s',
output_template => '%.2f/s',
perfdatas => [
{ label => 'ops_per_sec', value => 'instantaneous_ops_per_sec', template => '%s', min => 0, unit => 'ops/s' },
],
},
},
{ template => '%.2f', min => 0 }
]
}
}
];
}
sub prefix_output {
my ($self, %options) = @_;
return "Number of commands: ";
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments =>
{
});
$options{options}->add_options(arguments => {});
return $self;
}
@ -75,13 +72,13 @@ sub new {
sub manage_selection {
my ($self, %options) = @_;
$self->{cache_name} = "redis_" . $self->{mode} . '_' . $options{custom}->get_connection_info() . '_' .
$self->{cache_name} = 'redis_database_' . $self->{mode} . '_' . $options{custom}->get_connection_info() . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
my $results = $options{custom}->get_info();
$self->{global} = {
total_commands_processed => $results->{total_commands_processed},
instantaneous_ops_per_sec => $results->{instantaneous_ops_per_sec},
instantaneous_ops_per_sec => $results->{instantaneous_ops_per_sec}
};
}

View File

@ -18,7 +18,7 @@
# limitations under the License.
#
package apps::redis::cli::mode::connections;
package database::redis::mode::connections;
use base qw(centreon::plugins::templates::counter);
@ -26,74 +26,73 @@ use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'connections', type => 0, cb_prefix_output => 'prefix_connections_output' },
{ name => 'traffic', type => 0, cb_prefix_output => 'prefix_traffic_output' },
];
$self->{maps_counters}->{connections} = [
{ label => 'received-connections', set => {
key_values => [ { name => 'total_connections_received', diff => 1 } ],
output_template => 'Received: %s',
perfdatas => [
{ label => 'received_connections', template => '%s', min => 0 },
],
},
},
{ label => 'rejected-connections', set => {
key_values => [ { name => 'rejected_connections', diff => 1 } ],
output_template => 'Rejected: %s',
perfdatas => [
{ label => 'rejected_connections', template => '%s', min => 0 },
],
},
},
];
$self->{maps_counters}->{traffic} = [
{ label => 'traffic-in', set => {
key_values => [ { name => 'total_net_input_bytes', per_second => 1 } ],
output_template => 'Traffic In: %s %s/s',
output_change_bytes => 2,
perfdatas => [
{ label => 'traffic_in', template => '%d', min => 0, unit => 'b/s' },
],
},
},
{ label => 'traffic-out', set => {
key_values => [ { name => 'total_net_output_bytes', per_second => 1 } ],
output_template => 'Traffic Out: %s %s/s',
output_change_bytes => 2,
perfdatas => [
{ label => 'traffic_out', template => '%d', min => 0, unit => 'b/s' },
],
},
},
];
}
sub prefix_connections_output {
my ($self, %options) = @_;
return "Number of connections: ";
return 'Number of connections ';
}
sub prefix_traffic_output {
my ($self, %options) = @_;
return "Network usage: ";
return 'Network usage ';
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'connections', type => 0, cb_prefix_output => 'prefix_connections_output' },
{ name => 'traffic', type => 0, cb_prefix_output => 'prefix_traffic_output' }
];
$self->{maps_counters}->{connections} = [
{ label => 'received-connections', nlabel => 'connections.received.count', set => {
key_values => [ { name => 'total_connections_received', diff => 1 } ],
output_template => 'received: %s',
perfdatas => [
{ template => '%s', min => 0 }
]
}
},
{ label => 'rejected-connections', nlabel => 'connections.rejected.count', set => {
key_values => [ { name => 'rejected_connections', diff => 1 } ],
output_template => 'rejected: %s',
perfdatas => [
{ template => '%s', min => 0 }
]
}
}
];
$self->{maps_counters}->{traffic} = [
{ label => 'traffic-in', nlabel => 'network.traffic.in.bitspersecond', set => {
key_values => [ { name => 'total_net_input_bytes', per_second => 1 } ],
output_template => 'traffic in: %s %s/s',
output_change_bytes => 2,
perfdatas => [
{ template => '%d', min => 0, unit => 'b/s' }
]
}
},
{ label => 'traffic-out', nlabel => 'network.traffic.out.bitspersecond', set => {
key_values => [ { name => 'total_net_output_bytes', per_second => 1 } ],
output_template => 'traffic out: %s %s/s',
output_change_bytes => 2,
perfdatas => [
{ template => '%d', min => 0, unit => 'b/s' }
]
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
});
$options{options}->add_options(arguments => {});
return $self;
}
@ -101,19 +100,17 @@ sub new {
sub manage_selection {
my ($self, %options) = @_;
$self->{cache_name} = "redis_" . $self->{mode} . '_' . $options{custom}->get_connection_info() . '_' .
$self->{cache_name} = 'redis_database_' . $self->{mode} . '_' . $options{custom}->get_connection_info() . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
my $results = $options{custom}->get_info();
$self->{connections} = {
total_connections_received => $results->{total_connections_received},
rejected_connections => $results->{rejected_connections},
total_connections_received => $results->{total_connections_received},
rejected_connections => $results->{rejected_connections}
};
$self->{traffic} = {
total_net_input_bytes => $results->{total_net_input_bytes} * 8,
total_net_output_bytes => $results->{total_net_output_bytes} * 8,
total_net_input_bytes => $results->{total_net_input_bytes} * 8,
total_net_output_bytes => $results->{total_net_output_bytes} * 8
};
}

View File

@ -18,7 +18,7 @@
# limitations under the License.
#
package apps::redis::cli::mode::cpu;
package database::redis::mode::cpu;
use base qw(centreon::plugins::templates::counter);
@ -26,6 +26,21 @@ use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
sub prefix_output {
my ($self, %options) = @_;
return 'CPU usage ';
}
sub custom_usage_calc {
my ($self, %options) = @_;
my $delta_total = $options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref}} - $options{old_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref}};
$self->{result_values}->{used_delta} = 100 * $delta_total / $options{delta_time};
return 0;
}
sub set_counters {
my ($self, %options) = @_;
@ -34,67 +49,51 @@ sub set_counters {
];
$self->{maps_counters}->{global} = [
{ label => 'sys', set => {
{ label => 'sys', nlabel => 'cpu.system.usage.percentage', set => {
key_values => [ { name => 'used_cpu_sys', diff => 1 } ],
closure_custom_calc => $self->can('custom_usage_calc'), closure_custom_calc_extra_options => { label_ref => 'used_cpu_sys' },
output_template => 'System: %.2f %%', output_use => 'used_delta', threshold_use => 'used_delta',
output_template => 'system: %.2f %%', output_use => 'used_delta', threshold_use => 'used_delta',
perfdatas => [
{ label => 'sys', value => 'used_delta', template => '%.2f', min => 0, max => 100, unit => '%' },
],
{ value => 'used_delta', template => '%.2f', min => 0, max => 100, unit => '%' }
]
}
},
{ label => 'user', set => {
{ label => 'user', nlabel => 'cpu.user.usage.percentage', set => {
key_values => [ { name => 'used_cpu_user', diff => 1 } ],
closure_custom_calc => $self->can('custom_usage_calc'), closure_custom_calc_extra_options => { label_ref => 'used_cpu_user' },
output_template => 'User: %.2f %%', output_use => 'used_delta', threshold_use => 'used_delta',
output_template => 'user: %.2f %%', output_use => 'used_delta', threshold_use => 'used_delta',
perfdatas => [
{ label => 'user', value => 'used_delta', template => '%.2f', min => 0, max => 100, unit => '%' },
],
{ value => 'used_delta', template => '%.2f', min => 0, max => 100, unit => '%' }
]
}
},
{ label => 'sys-children', set => {
{ label => 'sys-children', nlabel => 'cpu.system.children.usage.percentage', set => {
key_values => [ { name => 'used_cpu_sys_children', diff => 1 } ],
closure_custom_calc => $self->can('custom_usage_calc'), closure_custom_calc_extra_options => { label_ref => 'used_cpu_sys_children' },
output_template => 'System children: %.2f %%', output_use => 'used_delta', threshold_use => 'used_delta',
output_template => 'system children: %.2f %%', output_use => 'used_delta', threshold_use => 'used_delta',
perfdatas => [
{ label => 'sys_children', value => 'used_delta', template => '%.2f', min => 0, max => 100, unit => '%' },
],
{ value => 'used_delta', template => '%.2f', min => 0, max => 100, unit => '%' }
]
}
},
{ label => 'user-children', set => {
{ label => 'user-children', nlabel => 'cpu.user.children.usage.percentage', set => {
key_values => [ { name => 'used_cpu_user_children', diff => 1 } ],
closure_custom_calc => $self->can('custom_usage_calc'), closure_custom_calc_extra_options => { label_ref => 'used_cpu_user_children' },
output_template => 'User children: %.2f %%', output_use => 'used_delta', threshold_use => 'used_delta',
output_template => 'user children: %.2f %%', output_use => 'used_delta', threshold_use => 'used_delta',
perfdatas => [
{ label => 'user_children', value => 'used_delta', template => '%.2f', min => 0, max => 100, unit => '%' },
],
{ value => 'used_delta', template => '%.2f', min => 0, max => 100, unit => '%' }
]
}
}
];
}
sub prefix_output {
my ($self, %options) = @_;
return "CPU usage: ";
}
sub custom_usage_calc {
my ($self, %options) = @_;
my $delta_total = $options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref}} - $options{old_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref}};
$self->{result_values}->{used_delta} = 100 * $delta_total / $options{delta_time};
return 0;
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
});
$options{options}->add_options(arguments => {});
return $self;
}
@ -102,16 +101,15 @@ sub new {
sub manage_selection {
my ($self, %options) = @_;
$self->{cache_name} = "redis_" . $self->{mode} . '_' . $options{custom}->get_connection_info() . '_' .
$self->{cache_name} = 'redis_database_' . $self->{mode} . '_' . $options{custom}->get_connection_info() . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
my $results = $options{custom}->get_info();
$self->{global} = {
used_cpu_sys => $results->{used_cpu_sys},
used_cpu_user => $results->{used_cpu_user},
used_cpu_sys_children => $results->{used_cpu_sys_children},
used_cpu_user_children => $results->{used_cpu_user_children},
used_cpu_sys => $results->{used_cpu_sys},
used_cpu_user => $results->{used_cpu_user},
used_cpu_sys_children => $results->{used_cpu_sys_children},
used_cpu_user_children => $results->{used_cpu_user_children}
};
}

View File

@ -18,7 +18,7 @@
# limitations under the License.
#
package apps::redis::cli::mode::memory;
package database::redis::mode::memory;
use base qw(centreon::plugins::templates::counter);
@ -27,17 +27,20 @@ use warnings;
sub custom_usage_perfdata {
my ($self, %options) = @_;
$self->{output}->perfdata_add(label => $self->{result_values}->{label}, unit => 'B',
value => $self->{result_values}->{used},
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{result_values}->{label}, total => $self->{result_values}->{total}, cast_int => 1),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{result_values}->{label}, total => $self->{result_values}->{total}, cast_int => 1),
min => 0, max => $self->{result_values}->{total});
$self->{output}->perfdata_add(
nlabel => $self->{nlabel},
unit => 'B',
value => $self->{result_values}->{used},
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, total => $self->{result_values}->{total}, cast_int => 1),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}, total => $self->{result_values}->{total}, cast_int => 1),
min => 0, max => $self->{result_values}->{total}
);
}
sub custom_usage_threshold {
my ($self, %options) = @_;
my ($exit, $threshold_value);
$threshold_value = $self->{result_values}->{used};
$threshold_value = $self->{result_values}->{free} if (defined($self->{instance_mode}->{option_results}->{free}));
@ -45,18 +48,26 @@ sub custom_usage_threshold {
$threshold_value = $self->{result_values}->{prct_used};
$threshold_value = $self->{result_values}->{prct_free} if (defined($self->{instance_mode}->{option_results}->{free}));
}
$exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{result_values}->{label}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{result_values}->{label}, exit_litteral => 'warning' } ]);
$exit = $self->{perfdata}->threshold_check(
value => $threshold_value,
threshold => [
{ label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' },
{ label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' }
]
);
return $exit;
}
sub custom_usage_output {
my ($self, %options) = @_;
my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
my $msg = sprintf($self->{result_values}->{display}.": %s (%.2f%%)",
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used});
return $msg;
return sprintf(
"%s: %s (%.2f%%)",
$self->{result_values}->{display},
$total_used_value . " " . $total_used_unit,
$self->{result_values}->{prct_used}
);
}
sub custom_usage_calc {
@ -84,160 +95,155 @@ sub set_counters {
{ name => 'startup', type => 0, skipped_code => { -10 => 1 } },
{ name => 'dataset', type => 0, skipped_code => { -10 => 1 } },
{ name => 'lua', type => 0, skipped_code => { -10 => 1 } },
{ name => 'stats', type => 0, cb_prefix_output => 'prefix_stats_output', skipped_code => { -10 => 1 } },
{ name => 'stats', type => 0, skipped_code => { -10 => 1 } }
];
$self->{maps_counters}->{used} = [
{ label => 'used', set => {
{ label => 'used', nlabel => 'memory.usage.bytes', set => {
key_values => [ { name => 'display' }, { name => 'label' }, { name => 'used' }, { name => 'total' } ],
closure_custom_calc => $self->can('custom_usage_calc'),
closure_custom_output => $self->can('custom_usage_output'),
closure_custom_perfdata => $self->can('custom_usage_perfdata'),
closure_custom_threshold_check => $self->can('custom_usage_threshold'),
closure_custom_threshold_check => $self->can('custom_usage_threshold')
}
},
}
];
$self->{maps_counters}->{rss} = [
{ label => 'rss', set => {
{ label => 'rss', nlabel => 'memory.rss.usage.bytes', set => {
key_values => [ { name => 'display' }, { name => 'label' }, { name => 'used' }, { name => 'total' } ],
closure_custom_calc => $self->can('custom_usage_calc'),
closure_custom_output => $self->can('custom_usage_output'),
closure_custom_perfdata => $self->can('custom_usage_perfdata'),
closure_custom_threshold_check => $self->can('custom_usage_threshold'),
closure_custom_threshold_check => $self->can('custom_usage_threshold')
}
},
}
];
$self->{maps_counters}->{peak} = [
{ label => 'peak', set => {
{ label => 'peak', nlabel => 'memory.peak.usage.bytes', set => {
key_values => [ { name => 'display' }, { name => 'label' }, { name => 'used' }, { name => 'total' } ],
closure_custom_calc => $self->can('custom_usage_calc'),
closure_custom_output => $self->can('custom_usage_output'),
closure_custom_perfdata => $self->can('custom_usage_perfdata'),
closure_custom_threshold_check => $self->can('custom_usage_threshold'),
closure_custom_threshold_check => $self->can('custom_usage_threshold')
}
},
}
];
$self->{maps_counters}->{overhead} = [
{ label => 'overhead', set => {
{ label => 'overhead', nlabel => 'memory.overhead.usage.bytes', set => {
key_values => [ { name => 'display' }, { name => 'label' }, { name => 'used' }, { name => 'total' } ],
closure_custom_calc => $self->can('custom_usage_calc'),
closure_custom_output => $self->can('custom_usage_output'),
closure_custom_perfdata => $self->can('custom_usage_perfdata'),
closure_custom_threshold_check => $self->can('custom_usage_threshold'),
closure_custom_threshold_check => $self->can('custom_usage_threshold')
}
},
}
];
$self->{maps_counters}->{startup} = [
{ label => 'startup', set => {
{ label => 'startup', nlabel => 'memory.startup.usage.bytes', set => {
key_values => [ { name => 'display' }, { name => 'label' }, { name => 'used' }, { name => 'total' } ],
closure_custom_calc => $self->can('custom_usage_calc'),
closure_custom_output => $self->can('custom_usage_output'),
closure_custom_perfdata => $self->can('custom_usage_perfdata'),
closure_custom_threshold_check => $self->can('custom_usage_threshold'),
closure_custom_threshold_check => $self->can('custom_usage_threshold')
}
},
}
];
$self->{maps_counters}->{dataset} = [
{ label => 'dataset', set => {
{ label => 'dataset', nlabel => 'memory.dataset.usage.bytes', set => {
key_values => [ { name => 'display' }, { name => 'label' }, { name => 'used' }, { name => 'total' } ],
closure_custom_calc => $self->can('custom_usage_calc'),
closure_custom_output => $self->can('custom_usage_output'),
closure_custom_perfdata => $self->can('custom_usage_perfdata'),
closure_custom_threshold_check => $self->can('custom_usage_threshold'),
closure_custom_threshold_check => $self->can('custom_usage_threshold')
}
},
}
];
$self->{maps_counters}->{lua} = [
{ label => 'lua', set => {
{ label => 'lua', nlabel => 'memory.lua.usage.bytes', set => {
key_values => [ { name => 'display' }, { name => 'label' }, { name => 'used' }, { name => 'total' } ],
closure_custom_calc => $self->can('custom_usage_calc'),
closure_custom_output => $self->can('custom_usage_output'),
closure_custom_perfdata => $self->can('custom_usage_perfdata'),
closure_custom_threshold_check => $self->can('custom_usage_threshold'),
closure_custom_threshold_check => $self->can('custom_usage_threshold')
}
},
}
];
$self->{maps_counters}->{stats} = [
{ label => 'fragmentation-ratio', set => {
{ label => 'fragmentation-ratio', nlabel => 'memory.fragmentation.ratio.count', set => {
key_values => [ { name => 'mem_fragmentation_ratio' } ],
output_template => 'Fragmentation ratio: %s',
output_template => 'fragmentation ratio: %s',
perfdatas => [
{ label => 'fragmentation_ratio', value => 'mem_fragmentation_ratio', template => '%s', min => 0 },
],
},
{ template => '%s', min => 0 }
]
}
},
{ label => 'defrag-running', set => {
{ label => 'defrag-running', nlabel => 'memory.defragmentation.running.count', set => {
key_values => [ { name => 'active_defrag_running' } ],
output_template => 'Defragmentation running: %s',
output_template => 'defragmentation running: %s',
perfdatas => [
{ label => 'defrag_running', value => 'active_defrag_running', template => '%s', min => 0 },
],
},
{ label => 'defrag_running', template => '%s', min => 0 }
]
}
},
{ label => 'lazyfree-pending-objects', set => {
{ label => 'lazyfree-pending-objects', nlabel => 'memory.lazy_pending_objects.count', set => {
key_values => [ { name => 'lazyfree_pending_objects' } ],
output_template => 'Lazyfree pending objects: %s',
output_template => 'lazyfree pending objects: %s',
perfdatas => [
{ label => 'lazyfree_pending_objects', value => 'lazyfree_pending_objects', template => '%s', min => 0 },
],
},
},
{ label => 'lazyfree_pending_objects', template => '%s', min => 0 }
]
}
}
];
}
sub prefix_stats_output {
my ($self, %options) = @_;
return "Statistics: ";
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
"units:s" => { name => 'units', default => '%' },
"free" => { name => 'free' },
'units:s' => { name => 'units', default => '%' },
'free' => { name => 'free' }
});
return $self;
}
my $metrics = {
used_memory => { label => 'used', display => 'Used' },
used_memory_rss => { label => 'rss', display => 'Rss' },
used_memory_peak => { label => 'peak', display => 'Peak' },
used_memory_overhead => { label => 'overhead', display => 'Overhead' },
used_memory_startup => { label => 'startup', display => 'Startup' },
used_memory_dataset => { label => 'dataset', display => 'Dataset' },
used_memory_lua => { label => 'lua', display => 'Lua' },
used_memory => { label => 'used', display => 'used' },
used_memory_rss => { label => 'rss', display => 'rss' },
used_memory_peak => { label => 'peak', display => 'peak' },
used_memory_overhead => { label => 'overhead', display => 'overhead' },
used_memory_startup => { label => 'startup', display => 'startup' },
used_memory_dataset => { label => 'dataset', display => 'dataset' },
used_memory_lua => { label => 'lua', display => 'lua' }
};
sub manage_selection {
my ($self, %options) = @_;
my $results = $options{custom}->get_info();
foreach my $type (keys %$metrics) {
next if (!defined($results->{$type}));
$self->{$metrics->{$type}->{label}} = { display => $metrics->{$type}->{display},
label => $metrics->{$type}->{label},
used => $results->{$type},
total => $results->{total_system_memory} };
$self->{$metrics->{$type}->{label}} = {
display => $metrics->{$type}->{display},
label => $metrics->{$type}->{label},
used => $results->{$type},
total => $results->{total_system_memory}
};
}
$self->{stats} = {
mem_fragmentation_ratio => $results->{mem_fragmentation_ratio},
active_defrag_running => $results->{active_defrag_running},
lazyfree_pending_objects => $results->{lazyfree_pending_objects},
lazyfree_pending_objects => $results->{lazyfree_pending_objects}
};
}

View File

@ -18,114 +18,97 @@
# limitations under the License.
#
package apps::redis::cli::mode::persistence;
package database::redis::mode::persistence;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0, skipped_code => { -10 => 1 } },
];
$self->{maps_counters}->{global} = [
{ label => 'status', threshold => 0, set => {
key_values => [ { name => 'status' }, { name => 'progress_status' } ],
closure_custom_calc => $self->can('custom_status_calc'),
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold,
}
},
{ label => 'changes', set => {
key_values => [ { name => 'rdb_changes_since_last_save' } ],
output_template => 'Number of changes since the last dump: %s',
perfdatas => [
{ label => 'changes', value => 'rdb_changes_since_last_save', template => '%s', min => 0 },
],
},
},
{ label => 'last-save', set => {
key_values => [ { name => 'rdb_last_save_time' }, { name => 'rdb_last_save_time_sec' } ],
output_template => 'Time since last successful save: %s',
perfdatas => [
{ label => 'last_save', value => 'rdb_last_save_time_sec', template => '%s', min => 0, unit => 's' },
],
},
},
{ label => 'save-size', set => {
key_values => [ { name => 'rdb_last_cow_size' } ],
output_template => 'Size of last save: %s %s',
output_change_bytes => 1,
perfdatas => [
{ label => 'save_size', value => 'rdb_last_cow_size', template => '%s', min => 0, unit => 'B' },
],
},
},
{ label => 'last-save-duration', set => {
key_values => [ { name => 'rdb_last_bgsave_time' } ],
output_template => 'Duration of last save: %s s',
perfdatas => [
{ label => 'last_save_duration', value => 'rdb_last_bgsave_time', template => '%s', min => 0, unit => 's' },
],
},
},
{ label => 'current-save-duration', set => {
key_values => [ { name => 'rdb_current_bgsave_time' } ],
output_template => 'Duration of current save: %s s',
perfdatas => [
{ label => 'current_save_duration', value => 'rdb_current_bgsave_time', template => '%s', min => 0, unit => 's' },
],
},
},
];
}
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
sub custom_status_output {
my ($self, %options) = @_;
my $msg = sprintf("RDB save status is '%s' [progress status: %s]", $self->{result_values}->{status}, $self->{result_values}->{progress_status});
return $msg;
return sprintf("RDB save status is '%s' [progress status: %s]", $self->{result_values}->{status}, $self->{result_values}->{progress_status});
}
sub custom_status_calc {
sub set_counters {
my ($self, %options) = @_;
$self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'};
$self->{result_values}->{progress_status} = $options{new_datas}->{$self->{instance} . '_progress_status'};
return 0;
$self->{maps_counters_type} = [
{ name => 'global', type => 0, skipped_code => { -10 => 1 } }
];
$self->{maps_counters}->{global} = [
{
label => 'status',
type => 2,
warning_default => '%{sync_status} =~ /in progress/i',
critical_default => '%{link_status} =~ /down/i',
set => {
key_values => [ { name => 'status' }, { name => 'progress_status' } ],
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold_ng
}
},
{ label => 'changes', nlabel => 'rdb.changes.since_last_save.count', set => {
key_values => [ { name => 'rdb_changes_since_last_save' } ],
output_template => 'number of changes since the last dump: %s',
perfdatas => [
{ template => '%s', min => 0 }
]
}
},
{ label => 'last-save', nlabel => 'rdb.last_successful_save.seconds',set => {
key_values => [ { name => 'rdb_last_save_time' }, { name => 'rdb_last_save_time_sec' } ],
output_template => 'time since last successful save: %s',
perfdatas => [
{ value => 'rdb_last_save_time_sec', template => '%s', min => 0, unit => 's' }
]
}
},
{ label => 'save-size', nlabel => 'rdb.last_save.size.bytes', set => {
key_values => [ { name => 'rdb_last_cow_size' } ],
output_template => 'size of last save: %s %s',
output_change_bytes => 1,
perfdatas => [
{ template => '%s', min => 0, unit => 'B' }
]
}
},
{ label => 'last-save-duration', nlabel => 'rdb.last_save.duration.seconds', set => {
key_values => [ { name => 'rdb_last_bgsave_time' } ],
output_template => 'duration of last save: %s s',
perfdatas => [
{ template => '%s', min => 0, unit => 's' }
]
}
},
{ label => 'current-save-duration', nlabel => 'rdb.current_save.duration.seconds', set => {
key_values => [ { name => 'rdb_current_bgsave_time' } ],
output_template => 'duration of current save: %s s',
perfdatas => [
{ template => '%s', min => 0, unit => 's' }
]
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments =>
{
"warning-status:s" => { name => 'warning_status', default => '%{sync_status} =~ /in progress/i' },
"critical-status:s" => { name => 'critical_status', default => '%{link_status} =~ /down/i' },
});
$options{options}->add_options(arguments => {});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->change_macros(macros => ['warning_status', 'critical_status']);
}
my %map_status = (
0 => 'stopped',
1 => 'in progress',
1 => 'in progress'
);
sub manage_selection {

View File

@ -18,161 +18,144 @@
# limitations under the License.
#
package apps::redis::cli::mode::replication;
package database::redis::mode::replication;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0, skipped_code => { -10 => 1 } },
{ name => 'master', type => 0, skipped_code => { -10 => 1 } },
{ name => 'slave', type => 0, skipped_code => { -10 => 1 } },
];
$self->{maps_counters}->{global} = [
{ label => 'status', threshold => 0, set => {
key_values => [ { name => 'link_status' }, { name => 'sync_status' }, { name => 'role' }, { name => 'cluster_state' } ],
closure_custom_calc => $self->can('custom_status_calc'),
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold,
}
},
{ label => 'connected-slaves', set => {
key_values => [ { name => 'connected_slaves' } ],
output_template => 'Number of connected slaves: %s',
perfdatas => [
{ label => 'connected_slaves', value => 'connected_slaves', template => '%s', min => 0 },
],
},
},
];
$self->{maps_counters}->{master} = [
{ label => 'master-repl-offset', set => {
key_values => [ { name => 'master_repl_offset' } ],
output_template => 'Master replication offset: %s s',
perfdatas => [
{ label => 'master_repl_offset', value => 'master_repl_offset', template => '%s', min => 0, unit => 's' },
],
},
},
];
$self->{maps_counters}->{slave} = [
{ label => 'master-last-io', set => {
key_values => [ { name => 'master_last_io_seconds_ago' } ],
output_template => 'Last interaction with master: %s s',
perfdatas => [
{ label => 'master_last_io', value => 'master_last_io_seconds_ago', template => '%s', min => 0, unit => 's' },
],
},
},
{ label => 'slave-repl-offset', set => {
key_values => [ { name => 'slave_repl_offset' } ],
output_template => 'Slave replication offset: %s s',
perfdatas => [
{ label => 'slave_repl_offset', value => 'slave_repl_offset', template => '%s', min => 0, unit => 's' },
],
},
},
{ label => 'slave-priority', set => {
key_values => [ { name => 'slave_priority' } ],
output_template => 'Slave replication offset: %s s',
perfdatas => [
{ label => 'slave_priority', value => 'slave_priority', template => '%s' },
],
},
},
{ label => 'slave-read-only', set => {
key_values => [ { name => 'slave_read_only' } ],
output_template => 'Slave replication offset: %s s',
perfdatas => [
{ label => 'slave_read_only', value => 'slave_read_only', template => '%s' },
],
},
},
];
}
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});
$msg .= sprintf(
" [link status: %s] [sync status: %s]",
$self->{result_values}->{link_status}, $self->{result_values}->{sync_status}
);
}
return $msg;
}
sub custom_status_calc {
sub set_counters {
my ($self, %options) = @_;
$self->{result_values}->{role} = $options{new_datas}->{$self->{instance} . '_role'};
$self->{result_values}->{sync_status} = $options{new_datas}->{$self->{instance} . '_sync_status'};
$self->{result_values}->{link_status} = $options{new_datas}->{$self->{instance} . '_link_status'};
$self->{result_values}->{cluster_state} = $options{new_datas}->{$self->{instance} . '_cluster_state'};
return 0;
$self->{maps_counters_type} = [
{ name => 'global', type => 0, skipped_code => { -10 => 1 } },
{ name => 'master', type => 0, skipped_code => { -10 => 1 } },
{ name => 'slave', type => 0, skipped_code => { -10 => 1 } }
];
$self->{maps_counters}->{global} = [
{
label => 'status',
type => 2,
warning_default => '%{sync_status} =~ /in progress/i',
critical_default => '%{link_status} =~ /down/i',
set => {
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; },
closure_custom_threshold_check => \&catalog_status_threshold_ng
}
},
{ label => 'connected-slaves', nlabel => 'replication.slaves.connected.count', set => {
key_values => [ { name => 'connected_slaves' } ],
output_template => 'number of connected slaves: %s',
perfdatas => [
{ template => '%s', min => 0 }
]
}
}
];
$self->{maps_counters}->{master} = [
{ label => 'master-repl-offset', nlabel => 'replication.master.offset.count', set => {
key_values => [ { name => 'master_repl_offset' } ],
output_template => 'master replication offset: %s',
perfdatas => [
{ template => '%s', min => 0 }
]
}
}
];
$self->{maps_counters}->{slave} = [
{ label => 'master-last-io', nlabel => 'replication.master.last_interaction.seconds', set => {
key_values => [ { name => 'master_last_io_seconds_ago' } ],
output_template => 'last interaction with master: %s s',
perfdatas => [
{ template => '%s', min => 0, unit => 's' }
]
}
},
{ label => 'slave-repl-offset', nlabel => 'replication.slave.offset.count', set => {
key_values => [ { name => 'slave_repl_offset' } ],
output_template => 'slave replication offset: %s s',
perfdatas => [
{ template => '%s', min => 0 }
]
}
},
{ label => 'slave-priority', nlabel => 'replication.slave.priority.count', set => {
key_values => [ { name => 'slave_priority' } ],
output_template => 'slave replication priority: %s',
perfdatas => [
{ template => '%s' }
]
}
},
{ label => 'slave-read-only', nlabel => 'replication.slave.readonly.count',set => {
key_values => [ { name => 'slave_read_only' } ],
output_template => 'slave readonly: %s',
perfdatas => [
{ template => '%s' }
]
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments =>
{
"warning-status:s" => { name => 'warning_status', default => '%{sync_status} =~ /in progress/i' },
"critical-status:s" => { name => 'critical_status', default => '%{link_status} =~ /down/i' },
});
$options{options}->add_options(arguments => {});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->change_macros(macros => ['warning_status', 'critical_status']);
}
my %map_sync = (
0 => 'stopped',
1 => 'in progress',
1 => 'in progress'
);
my %map_cluster_state = (
0 => 'disabled',
1 => 'enabled',
1 => 'enabled'
);
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} : '-',
sync_status => defined($results->{master_sync_in_progress}) ? $map_sync{$results->{master_sync_in_progress}} : '-',
sync_status => defined($results->{master_sync_in_progress}) ? $map_sync{$results->{master_sync_in_progress}} : '-'
};
$self->{master} = { master_repl_offset => $results->{master_repl_offset} };
$self->{slave} = {
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},
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}
};
}

View File

@ -18,7 +18,7 @@
# limitations under the License.
#
package apps::redis::cli::plugin;
package database::redis::plugin;
use strict;
use warnings;
@ -30,17 +30,18 @@ sub new {
bless $self, $class;
$self->{version} = '1.0';
%{$self->{modes}} = (
'clients' => 'apps::redis::cli::mode::clients',
'commands' => 'apps::redis::cli::mode::commands',
'connections' => 'apps::redis::cli::mode::connections',
'cpu' => 'apps::redis::cli::mode::cpu',
'memory' => 'apps::redis::cli::mode::memory',
'persistence' => 'apps::redis::cli::mode::persistence',
'replication' => 'apps::redis::cli::mode::replication',
);
$self->{modes} = {
'clients' => 'database::redis::mode::clients',
'commands' => 'database::redis::mode::commands',
'connections' => 'database::redis::mode::connections',
'cpu' => 'database::redis::mode::cpu',
'memory' => 'database::redis::mode::memory',
'persistence' => 'database::redis::mode::persistence',
'replication' => 'database::redis::mode::replication'
};
$self->{custom_modes}{rediscli} = 'apps::redis::cli::custom::rediscli';
$self->{custom_modes}->{perlmod} = 'database::redis::custom::perlmod';
$self->{custom_modes}->{cli} = 'database::redis::custom::cli';
return $self;
}
@ -50,4 +51,4 @@ __END__
=head1 PLUGIN DESCRIPTION
Check Redis server through Perl Cli binding library.
Check Redis database.