migrate disk-usage standard snmp to new metrics
This commit is contained in:
parent
346b5101e0
commit
1b8951e761
|
@ -634,6 +634,24 @@ sub manage_selection {
|
||||||
# (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
|
# (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub compat_threshold_counter {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
foreach ('warning', 'critical') {
|
||||||
|
foreach my $th (@{$options{compat}->{th}}) {
|
||||||
|
next if (!defined($options{option_results}->{$_ . '-' . $th->[0]}) || $options{option_results}->{$_ . '-' . $th->[0]} eq '');
|
||||||
|
|
||||||
|
if (defined($options{compat}->{free})) {
|
||||||
|
$options{option_results}->{$_ . '-' . $th->[1]->{free}} = $options{option_results}->{$_ . '-' . $th->[0]};
|
||||||
|
$options{option_results}->{$_ . '-' . $th->[0]} = undef;
|
||||||
|
} elsif (defined($options{compat}->{units}) && $options{compat}->{units} eq '%') {
|
||||||
|
$options{option_results}->{$_ . '-' . $th->[1]->{prct}} = $options{option_results}->{$_ . '-' . $th->[0]};
|
||||||
|
$options{option_results}->{$_ . '-' . $th->[0]} = undef;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sub change_macros {
|
sub change_macros {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
|
|
@ -27,84 +27,19 @@ use warnings;
|
||||||
use centreon::plugins::statefile;
|
use centreon::plugins::statefile;
|
||||||
use Digest::MD5 qw(md5_hex);
|
use Digest::MD5 qw(md5_hex);
|
||||||
|
|
||||||
sub custom_usage_perfdata {
|
|
||||||
my ($self, %options) = @_;
|
|
||||||
|
|
||||||
my $label = 'used';
|
|
||||||
my $value_perf = $self->{result_values}->{used};
|
|
||||||
if (defined($self->{instance_mode}->{option_results}->{free})) {
|
|
||||||
$label = 'free';
|
|
||||||
$value_perf = $self->{result_values}->{free};
|
|
||||||
}
|
|
||||||
|
|
||||||
my %total_options = ();
|
|
||||||
if ($self->{instance_mode}->{option_results}->{units} eq '%') {
|
|
||||||
$total_options{total} = $self->{result_values}->{total};
|
|
||||||
$total_options{cast_int} = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
$self->{output}->perfdata_add(
|
|
||||||
label => $label, unit => 'B',
|
|
||||||
instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef,
|
|
||||||
value => $value_perf,
|
|
||||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, %total_options),
|
|
||||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}, %total_options),
|
|
||||||
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}));
|
|
||||||
if ($self->{instance_mode}->{option_results}->{units} eq '%') {
|
|
||||||
$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->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{thlabel}, exit_litteral => 'warning' } ]);
|
|
||||||
return $exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub custom_usage_output {
|
sub custom_usage_output {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total});
|
my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total_absolute});
|
||||||
my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
|
my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used_absolute});
|
||||||
my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
|
my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_absolute});
|
||||||
my $msg = sprintf("Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
|
my $msg = sprintf("Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
|
||||||
$total_size_value . " " . $total_size_unit,
|
$total_size_value . " " . $total_size_unit,
|
||||||
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
|
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used_absolute},
|
||||||
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free});
|
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free_absolute});
|
||||||
return $msg;
|
return $msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub custom_usage_calc {
|
|
||||||
my ($self, %options) = @_;
|
|
||||||
|
|
||||||
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
|
|
||||||
$self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_size'};
|
|
||||||
my $reserved_value = 0;
|
|
||||||
if (defined($self->{instance_mode}->{option_results}->{space_reservation})) {
|
|
||||||
$reserved_value = $self->{instance_mode}->{option_results}->{space_reservation} * $self->{result_values}->{total} / 100;
|
|
||||||
}
|
|
||||||
|
|
||||||
$self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_used'};
|
|
||||||
$self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used} - $reserved_value;
|
|
||||||
$self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / ($self->{result_values}->{total} - $reserved_value);
|
|
||||||
$self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used};
|
|
||||||
|
|
||||||
# limit to 100. Better output.
|
|
||||||
if ($self->{result_values}->{prct_used} > 100) {
|
|
||||||
$self->{result_values}->{free} = 0;
|
|
||||||
$self->{result_values}->{prct_used} = 100;
|
|
||||||
$self->{result_values}->{prct_free} = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub set_counters {
|
sub set_counters {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
@ -114,7 +49,7 @@ sub set_counters {
|
||||||
];
|
];
|
||||||
|
|
||||||
$self->{maps_counters}->{global} = [
|
$self->{maps_counters}->{global} = [
|
||||||
{ label => 'count', set => {
|
{ label => 'count', nlabel => 'storages.partitions.count', display_ok => 0, set => {
|
||||||
key_values => [ { name => 'count' } ],
|
key_values => [ { name => 'count' } ],
|
||||||
output_template => 'Partitions count : %d',
|
output_template => 'Partitions count : %d',
|
||||||
perfdatas => [
|
perfdatas => [
|
||||||
|
@ -123,16 +58,36 @@ sub set_counters {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
$self->{maps_counters}->{diskpath} = [
|
$self->{maps_counters}->{diskpath} = [
|
||||||
{ label => 'usage', set => {
|
{ label => 'usage', nlabel => 'storage.space.usage.bytes', set => {
|
||||||
key_values => [ { name => 'display' }, { name => 'used' }, { name => 'size' } ],
|
key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' }, { name => 'display' } ],
|
||||||
closure_custom_calc => $self->can('custom_usage_calc'),
|
|
||||||
closure_custom_output => $self->can('custom_usage_output'),
|
closure_custom_output => $self->can('custom_usage_output'),
|
||||||
closure_custom_perfdata => $self->can('custom_usage_perfdata'),
|
perfdatas => [
|
||||||
closure_custom_threshold_check => $self->can('custom_usage_threshold'),
|
{ label => 'used', value => 'used_absolute', template => '%d', min => 0, max => 'total_absolute',
|
||||||
|
unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display_absolute' },
|
||||||
|
],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ label => 'inodes', set => {
|
{ label => 'usage-free', display_ok => 0, nlabel => 'storage.space.free.bytes', set => {
|
||||||
|
key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' }, { name => 'display' } ],
|
||||||
|
closure_custom_output => $self->can('custom_usage_output'),
|
||||||
|
perfdatas => [
|
||||||
|
{ label => 'free', value => 'free_absolute', template => '%d', min => 0, max => 'total_absolute',
|
||||||
|
unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display_absolute' },
|
||||||
|
],
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ label => 'usage-prct', display_ok => 0, nlabel => 'storage.space.usage.percentage', set => {
|
||||||
|
key_values => [ { name => 'prct_used' }, { name => 'display' } ],
|
||||||
|
output_template => 'Used : %.2f %%',
|
||||||
|
perfdatas => [
|
||||||
|
{ label => 'used_prct', value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100,
|
||||||
|
unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' },
|
||||||
|
],
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ label => 'inodes', nlabel => 'storage.inodes.usage.percentage', set => {
|
||||||
key_values => [ { name => 'inodes' }, { name => 'display' } ],
|
key_values => [ { name => 'inodes' }, { name => 'display' } ],
|
||||||
output_template => 'Inodes Used: %s %%',
|
output_template => 'Inodes Used: %s %%',
|
||||||
perfdatas => [
|
perfdatas => [
|
||||||
|
@ -162,17 +117,17 @@ sub new {
|
||||||
bless $self, $class;
|
bless $self, $class;
|
||||||
|
|
||||||
$options{options}->add_options(arguments => {
|
$options{options}->add_options(arguments => {
|
||||||
"units:s" => { name => 'units', default => '%' },
|
'units:s' => { name => 'units', default => '%' },
|
||||||
"free" => { name => 'free' },
|
'free' => { name => 'free' },
|
||||||
"reload-cache-time:s" => { name => 'reload_cache_time', default => 180 },
|
'reload-cache-time:s' => { name => 'reload_cache_time', default => 180 },
|
||||||
"name" => { name => 'use_name' },
|
'name' => { name => 'use_name' },
|
||||||
"diskpath:s" => { name => 'diskpath' },
|
'diskpath:s' => { name => 'diskpath' },
|
||||||
"regexp" => { name => 'use_regexp' },
|
'regexp' => { name => 'use_regexp' },
|
||||||
"regexp-isensitive" => { name => 'use_regexpi' },
|
'regexp-isensitive' => { name => 'use_regexpi' },
|
||||||
"display-transform-src:s" => { name => 'display_transform_src' },
|
'display-transform-src:s' => { name => 'display_transform_src' },
|
||||||
"display-transform-dst:s" => { name => 'display_transform_dst' },
|
'display-transform-dst:s' => { name => 'display_transform_dst' },
|
||||||
"show-cache" => { name => 'show_cache' },
|
'show-cache' => { name => 'show_cache' },
|
||||||
"space-reservation:s" => { name => 'space_reservation' },
|
'space-reservation:s' => { name => 'space_reservation' },
|
||||||
});
|
});
|
||||||
|
|
||||||
$self->{diskpath_id_selected} = [];
|
$self->{diskpath_id_selected} = [];
|
||||||
|
@ -183,12 +138,17 @@ sub new {
|
||||||
|
|
||||||
sub check_options {
|
sub check_options {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
# Compatibility
|
||||||
|
$self->compat_threshold_counter(%options,
|
||||||
|
compat => {
|
||||||
|
th => [ ['usage', { free => 'usage-free', prct => 'usage-prct'} ], [ 'storage.space.usage.bytes', { free => 'storage.space.free.bytes', prct => 'storage.space.usage.percentage' } ] ],
|
||||||
|
units => $options{option_results}->{units}, free => $options{option_results}->{free}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
$self->SUPER::check_options(%options);
|
$self->SUPER::check_options(%options);
|
||||||
|
|
||||||
# compatibility
|
|
||||||
if (!defined($self->{option_results}->{filter_counters})) {
|
|
||||||
$self->{option_results}->{filter_counters} = 'usage';
|
|
||||||
}
|
|
||||||
if (defined($self->{option_results}->{space_reservation}) &&
|
if (defined($self->{option_results}->{space_reservation}) &&
|
||||||
($self->{option_results}->{space_reservation} < 0 || $self->{option_results}->{space_reservation} > 100)) {
|
($self->{option_results}->{space_reservation} < 0 || $self->{option_results}->{space_reservation} > 100)) {
|
||||||
$self->{output}->add_option_msg(short_msg => "Space reservation argument must be between 0 and 100 percent.");
|
$self->{output}->add_option_msg(short_msg => "Space reservation argument must be between 0 and 100 percent.");
|
||||||
|
@ -225,8 +185,10 @@ sub manage_selection {
|
||||||
my $name_diskpath = $self->get_display_value(id => $_);
|
my $name_diskpath = $self->get_display_value(id => $_);
|
||||||
|
|
||||||
if (!defined($result->{$oid_dskTotalHigh . "." . $_})) {
|
if (!defined($result->{$oid_dskTotalHigh . "." . $_})) {
|
||||||
$self->{output}->add_option_msg(long_msg => sprintf("skipping partition '%s': not found (need to reload the cache)",
|
$self->{output}->add_option_msg(long_msg => sprintf(
|
||||||
$name_diskpath));
|
"skipping partition '%s': not found (need to reload the cache)",
|
||||||
|
$name_diskpath)
|
||||||
|
);
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,10 +199,28 @@ sub manage_selection {
|
||||||
}
|
}
|
||||||
my $total_used = (($result->{$oid_dskUsedHigh . "." . $_} << 32) + $result->{$oid_dskUsedLow . "." . $_}) * 1024;
|
my $total_used = (($result->{$oid_dskUsedHigh . "." . $_} << 32) + $result->{$oid_dskUsedLow . "." . $_}) * 1024;
|
||||||
|
|
||||||
|
my $reserved_value = 0;
|
||||||
|
if (defined($self->{option_results}->{space_reservation})) {
|
||||||
|
$reserved_value = $self->{option_results}->{space_reservation} * $total_size / 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
my $prct_used = $total_used * 100 / ($total_size - $reserved_value);
|
||||||
|
my $prct_free = 100 - $prct_used;
|
||||||
|
my $free = $total_size - $total_used - $reserved_value;
|
||||||
|
# limit to 100. Better output.
|
||||||
|
if ($prct_used > 100) {
|
||||||
|
$free = 0;
|
||||||
|
$prct_used = 100;
|
||||||
|
$prct_free = 0;
|
||||||
|
}
|
||||||
|
|
||||||
$self->{diskpath}->{$_} = {
|
$self->{diskpath}->{$_} = {
|
||||||
display => $name_diskpath,
|
display => $name_diskpath,
|
||||||
size => $total_size,
|
total => $total_size,
|
||||||
used => $total_used,
|
used => $total_used,
|
||||||
|
free => $free,
|
||||||
|
prct_free => $prct_free,
|
||||||
|
prct_used => $prct_used,
|
||||||
inodes => defined($result->{$oid_dskPercentNode . "." . $_}) ? $result->{$oid_dskPercentNode . "." . $_} : undef,
|
inodes => defined($result->{$oid_dskPercentNode . "." . $_}) ? $result->{$oid_dskPercentNode . "." . $_} : undef,
|
||||||
};
|
};
|
||||||
$self->{global}->{count}++;
|
$self->{global}->{count}++;
|
||||||
|
@ -351,21 +331,9 @@ Need to enable "includeAllDisks 10%" on snmpd.conf.
|
||||||
|
|
||||||
Filter counters to be displayed (Default: 'usage', Can be: 'usage', 'count', 'inodes').
|
Filter counters to be displayed (Default: 'usage', Can be: 'usage', 'count', 'inodes').
|
||||||
|
|
||||||
=item B<--warning-*>
|
=item B<--warning-*> B<--critical-*>
|
||||||
|
|
||||||
Threshold warning (Can be: 'usage', 'inodes', 'count').
|
Thresholds (Can be: 'usage', 'usage-free', 'usage-prct', 'inodes', 'count').
|
||||||
|
|
||||||
=item B<--critical-*>
|
|
||||||
|
|
||||||
Threshold warning (Can be: 'usage', 'inodes', 'count').
|
|
||||||
|
|
||||||
=item B<--units>
|
|
||||||
|
|
||||||
Units of thresholds (Default: '%') ('%', 'B').
|
|
||||||
|
|
||||||
=item B<--free>
|
|
||||||
|
|
||||||
Thresholds are on free space left.
|
|
||||||
|
|
||||||
=item B<--diskpath>
|
=item B<--diskpath>
|
||||||
|
|
||||||
|
|
|
@ -163,24 +163,6 @@ sub new {
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub compat_threshold_counter {
|
|
||||||
my ($self, %options) = @_;
|
|
||||||
|
|
||||||
foreach ('warning', 'critical') {
|
|
||||||
foreach my $th (@{$options{compat}->{th}}) {
|
|
||||||
next if (!defined($options{option_results}->{$_ . '-' . $th->[0]}) || $options{option_results}->{$_ . '-' . $th->[0]} eq '');
|
|
||||||
|
|
||||||
if (defined($options{compat}->{free})) {
|
|
||||||
$options{option_results}->{$_ . '-' . $th->[1]->{free}} = $options{option_results}->{$_ . '-' . $th->[0]};
|
|
||||||
$options{option_results}->{$_ . '-' . $th->[0]} = undef;
|
|
||||||
} elsif (defined($options{compat}->{units}) && $options{compat}->{units} eq '%') {
|
|
||||||
$options{option_results}->{$_ . '-' . $th->[1]->{prct}} = $options{option_results}->{$_ . '-' . $th->[0]};
|
|
||||||
$options{option_results}->{$_ . '-' . $th->[0]} = undef;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sub check_options {
|
sub check_options {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue