mirror of
https://github.com/centreon/centreon-plugins.git
synced 2025-07-27 07:34:35 +02:00
Fix #1987
This commit is contained in:
parent
49f2811bc4
commit
eb0b5c6c7f
@ -33,49 +33,49 @@ sub set_counters {
|
|||||||
];
|
];
|
||||||
|
|
||||||
$self->{maps_counters}->{cpu} = [
|
$self->{maps_counters}->{cpu} = [
|
||||||
{ label => 'total', set => {
|
{ label => '1m', nlabel => 'cpu.utilization.1m.percentage', set => {
|
||||||
key_values => [ { name => 'total' }, { name => 'num' } ],
|
|
||||||
output_template => 'Total CPU Usage : %.2f %%',
|
|
||||||
perfdatas => [
|
|
||||||
{ label => 'cpu_total', value => 'total_absolute', template => '%.2f', min => 0, max => 100, unit => '%',
|
|
||||||
label_extra_instance => 1, instance_use => 'num_absolute' },
|
|
||||||
],
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{ label => '1m', set => {
|
|
||||||
key_values => [ { name => '1m' }, { name => 'num' } ],
|
key_values => [ { name => '1m' }, { name => 'num' } ],
|
||||||
output_template => '1 minute : %.2f %%',
|
output_template => '%.2f %% (1min)',
|
||||||
perfdatas => [
|
perfdatas => [
|
||||||
{ label => 'cpu_1min', value => '1m_absolute', template => '%.2f',
|
{ label => 'cpu_1min', value => '1m_absolute', template => '%.2f',
|
||||||
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'num_absolute' },
|
min => 0, max => 100, unit => '%', label_extra_instance => 1 }
|
||||||
],
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ label => '10m', set => {
|
{ label => '5m', nlabel => 'cpu.utilization.5m.percentage', set => {
|
||||||
|
key_values => [ { name => '5m' }, { name => 'num' } ],
|
||||||
|
output_template => '%.2f %% (5min)',
|
||||||
|
perfdatas => [
|
||||||
|
{ label => 'cpu_5min', value => '5m_absolute', template => '%.2f',
|
||||||
|
min => 0, max => 100, unit => '%', label_extra_instance => 1 }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ label => '10m', nlabel => 'cpu.utilization.10m.percentage', set => {
|
||||||
key_values => [ { name => '10m' }, { name => 'num' } ],
|
key_values => [ { name => '10m' }, { name => 'num' } ],
|
||||||
output_template => '10 minutes : %.2f %%',
|
output_template => '%.2f %% (10min)',
|
||||||
perfdatas => [
|
perfdatas => [
|
||||||
{ label => 'cpu_10min', value => '10m_absolute', template => '%.2f',
|
{ label => 'cpu_10min', value => '10m_absolute', template => '%.2f',
|
||||||
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'num_absolute' },
|
min => 0, max => 100, unit => '%', label_extra_instance => 1 }
|
||||||
],
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ label => '1h', set => {
|
{ label => '1h', nlabel => 'cpu.utilization.1h.percentage', set => {
|
||||||
key_values => [ { name => '1h' }, { name => 'num' } ],
|
key_values => [ { name => '1h' }, { name => 'num' } ],
|
||||||
output_template => '1 hour : %.2f %%',
|
output_template => '%.2f %% (1h)',
|
||||||
perfdatas => [
|
perfdatas => [
|
||||||
{ label => 'cpu_1h', value => '1h_absolute', template => '%.2f',
|
{ label => 'cpu_1h', value => '1h_absolute', template => '%.2f',
|
||||||
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'num_absolute' },
|
min => 0, max => 100, unit => '%', label_extra_instance => 1 }
|
||||||
],
|
]
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
sub prefix_cpu_output {
|
sub prefix_cpu_output {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
return "CPU '" . $options{instance_value}->{num} . "' ";
|
return "CPU '" . $options{instance_value}->{num} . "' usage ";
|
||||||
}
|
}
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
@ -83,44 +83,74 @@ sub new {
|
|||||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||||
bless $self, $class;
|
bless $self, $class;
|
||||||
|
|
||||||
$options{options}->add_options(arguments =>
|
$options{options}->add_options(arguments => {
|
||||||
{
|
});
|
||||||
});
|
|
||||||
|
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $mapping = {
|
my $mapping = {
|
||||||
s5ChasUtilTotalCPUUsage => { oid => '.1.3.6.1.4.1.45.1.6.3.8.1.1.4' },
|
|
||||||
s5ChasUtilCPUUsageLast1Minute => { oid => '.1.3.6.1.4.1.45.1.6.3.8.1.1.5' },
|
s5ChasUtilCPUUsageLast1Minute => { oid => '.1.3.6.1.4.1.45.1.6.3.8.1.1.5' },
|
||||||
s5ChasUtilCPUUsageLast10Minutes => { oid => '.1.3.6.1.4.1.45.1.6.3.8.1.1.6' },
|
s5ChasUtilCPUUsageLast10Minutes => { oid => '.1.3.6.1.4.1.45.1.6.3.8.1.1.6' },
|
||||||
s5ChasUtilCPUUsageLast1Hour => { oid => '.1.3.6.1.4.1.45.1.6.3.8.1.1.7' },
|
s5ChasUtilCPUUsageLast1Hour => { oid => '.1.3.6.1.4.1.45.1.6.3.8.1.1.7' }
|
||||||
};
|
};
|
||||||
|
|
||||||
my $oid_rcSysCpuUtil = '.1.3.6.1.4.1.2272.1.1.20'; # without .0
|
my $oid_rcSysCpuUtil = '.1.3.6.1.4.1.2272.1.1.20'; # without .0
|
||||||
my $oid_s5ChasUtilEntry = '.1.3.6.1.4.1.45.1.6.3.8.1.1';
|
my $oid_s5ChasUtilEntry = '.1.3.6.1.4.1.45.1.6.3.8.1.1';
|
||||||
|
|
||||||
|
sub check_khi {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
my $oid_rcKhiSlotCpu5MinAve = '.1.3.6.1.4.1.2272.1.85.10.1.1.3';
|
||||||
|
my $snmp_result = $options{snmp}->get_table(
|
||||||
|
oid => $oid_rcKhiSlotCpu5MinAve,
|
||||||
|
nothing_quit => 1
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach (keys %$snmp_result) {
|
||||||
|
/.(\d+)$/;
|
||||||
|
|
||||||
|
$self->{cpu}->{'slot_' . $1} = {
|
||||||
|
num => 'slot_' . $1,
|
||||||
|
'5m' => $snmp_result->{$_}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sub manage_selection {
|
sub manage_selection {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
$self->{results} = $options{snmp}->get_multiple_table(oids => [
|
my $snmp_result = $options{snmp}->get_multiple_table(
|
||||||
{ oid => $oid_rcSysCpuUtil },
|
oids => [
|
||||||
{ oid => $oid_s5ChasUtilEntry },
|
{ oid => $oid_rcSysCpuUtil },
|
||||||
], nothing_quit => 1);
|
{
|
||||||
|
oid => $oid_s5ChasUtilEntry,
|
||||||
|
start => $mapping->{s5ChasUtilCPUUsageLast1Minute}->{oid},
|
||||||
|
end => $mapping->{s5ChasUtilCPUUsageLast1Hour}->{oid}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
$self->{cpu} = {};
|
$self->{cpu} = {};
|
||||||
foreach my $oid (keys %{$self->{results}->{$oid_s5ChasUtilEntry}}) {
|
foreach my $oid (keys %{$snmp_result->{$oid_s5ChasUtilEntry}}) {
|
||||||
next if ($oid !~ /^$mapping->{s5ChasUtilTotalCPUUsage}->{oid}\.(.*)$/);
|
next if ($oid !~ /^$mapping->{s5ChasUtilCPUUsageLast1Minute}->{oid}\.(.*)$/);
|
||||||
my $instance = $1;
|
my $instance = $1;
|
||||||
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_s5ChasUtilEntry}, instance => $instance);
|
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result->{$oid_s5ChasUtilEntry}, instance => $instance);
|
||||||
|
|
||||||
$self->{cpu}->{$instance} = { num => $instance, total => $result->{s5ChasUtilTotalCPUUsage},
|
$self->{cpu}->{$instance} = {
|
||||||
'1m' => $result->{s5ChasUtilCPUUsageLast1Minute}, '10m' => $result->{s5ChasUtilCPUUsageLast10Minutes},
|
num => $instance,
|
||||||
'1h' => $result->{s5ChasUtilCPUUsageLast1Hour} };
|
'1m' => $result->{s5ChasUtilCPUUsageLast1Minute},
|
||||||
|
'10m' => $result->{s5ChasUtilCPUUsageLast10Minutes},
|
||||||
|
'1h' => $result->{s5ChasUtilCPUUsageLast1Hour}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scalar(keys %{$self->{results}->{$oid_rcSysCpuUtil}}) > 0) {
|
if (scalar(keys %{$snmp_result->{$oid_rcSysCpuUtil}}) > 0) {
|
||||||
$self->{cpu}->{0} = { num => 0, total => $self->{results}->{$oid_rcSysCpuUtil}->{$oid_rcSysCpuUtil . '.0'} };
|
$self->{cpu}->{0} = { num => 0, total => $snmp_result->{$oid_rcSysCpuUtil}->{$oid_rcSysCpuUtil . '.0'} };
|
||||||
|
}
|
||||||
|
|
||||||
|
if (scalar(keys %{$self->{cpu}}) <= 0) {
|
||||||
|
$self->check_khi(snmp => $options{snmp});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,17 +167,12 @@ Check CPU usages.
|
|||||||
=item B<--filter-counters>
|
=item B<--filter-counters>
|
||||||
|
|
||||||
Only display some counters (regexp can be used).
|
Only display some counters (regexp can be used).
|
||||||
Example: --filter-counters='^(1m|10m)$'
|
Example: --filter-counters='1m|10m'
|
||||||
|
|
||||||
=item B<--warning-*>
|
=item B<--warning-*> B<--critical-*>
|
||||||
|
|
||||||
Threshold warning.
|
Thresholds.
|
||||||
Can be: 'total', '1m', '5m', '10m', '1h'.
|
Can be: '1m', '5m', '10m', '1h'.
|
||||||
|
|
||||||
=item B<--critical-*>
|
|
||||||
|
|
||||||
Threshold critical.
|
|
||||||
Can be: 'total', '1m', '5m', '10m', '1h'.
|
|
||||||
|
|
||||||
=back
|
=back
|
||||||
|
|
||||||
|
@ -25,23 +25,54 @@ use base qw(centreon::plugins::templates::counter);
|
|||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
|
||||||
|
sub custom_usage_output {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
return sprintf(
|
||||||
|
'total: %s %s used: %s %s (%.2f%%) free: %s %s (%.2f%%)',
|
||||||
|
$self->{perfdata}->change_bytes(value => $self->{result_values}->{total_absolute}),
|
||||||
|
$self->{perfdata}->change_bytes(value => $self->{result_values}->{used_absolute}),
|
||||||
|
$self->{result_values}->{prct_used_absolute},
|
||||||
|
$self->{perfdata}->change_bytes(value => $self->{result_values}->{free_absolute}),
|
||||||
|
$self->{result_values}->{prct_free_absolute}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
sub set_counters {
|
sub set_counters {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
$self->{maps_counters_type} = [
|
$self->{maps_counters_type} = [
|
||||||
{ name => 'memory', type => 1, cb_prefix_output => 'prefix_memory_output', message_multiple => 'All memory usages are ok' }
|
{ name => 'memory', type => 1, cb_prefix_output => 'prefix_memory_output', message_multiple => 'All memory usages are ok', skipped_code => { -10 => 1 } }
|
||||||
];
|
];
|
||||||
|
|
||||||
$self->{maps_counters}->{memory} = [
|
$self->{maps_counters}->{memory} = [
|
||||||
{ label => 'usage', set => {
|
{ label => 'usage', display_ok => 0, nlabel => 'memory.usage.bytes', set => {
|
||||||
key_values => [ { name => 'used' }, { name => 'display' } ],
|
key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' }, { name => 'display' } ],
|
||||||
output_template => 'Used : %.2f %%',
|
closure_custom_output => $self->can('custom_usage_output'),
|
||||||
perfdatas => [
|
perfdatas => [
|
||||||
{ label => 'used', value => 'used_absolute', template => '%.2f', min => 0, max => 100, unit => '%',
|
{ value => 'used_absolute', template => '%d', min => 0, max => 'total_absolute',
|
||||||
label_extra_instance => 1, instance_use => 'display_absolute' },
|
unit => 'B', cast_int => 1, label_extra_instance => 1 }
|
||||||
],
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{ label => 'usage-free', display_ok => 0, nlabel => 'memory.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 => [
|
||||||
|
{ value => 'free_absolute', template => '%d', min => 0, max => 'total_absolute',
|
||||||
|
unit => 'B', cast_int => 1, label_extra_instance => 1 }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ label => 'usage-prct', nlabel => 'memory.usage.percentage', set => {
|
||||||
|
key_values => [ { name => 'prct_used' }, { name => 'display' } ],
|
||||||
|
output_template => 'used: %.2f %%',
|
||||||
|
perfdatas => [
|
||||||
|
{ value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100, unit => '%',
|
||||||
|
label_extra_instance => 1 },
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,33 +84,72 @@ sub prefix_memory_output {
|
|||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
my ($class, %options) = @_;
|
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;
|
bless $self, $class;
|
||||||
|
|
||||||
$options{options}->add_options(arguments =>
|
$options{options}->add_options(arguments => {
|
||||||
{
|
});
|
||||||
});
|
|
||||||
|
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $mapping = {
|
my $mapping = {
|
||||||
s5ChasUtilMemoryAvailable => { oid => '.1.3.6.1.4.1.45.1.6.3.8.1.1.9' },
|
s5ChasUtilMemoryAvailable => { oid => '.1.3.6.1.4.1.45.1.6.3.8.1.1.9' }
|
||||||
};
|
};
|
||||||
|
my $mapping_khi = {
|
||||||
|
rcKhiSlotMemUsed => { oid => '.1.3.6.1.4.1.2272.1.85.10.1.1.6' }, # KB
|
||||||
|
rcKhiSlotMemFree => { oid => '.1.3.6.1.4.1.2272.1.85.10.1.1.7' } # KB
|
||||||
|
};
|
||||||
|
my $oid_rcKhiSlotPerfEntry = '.1.3.6.1.4.1.2272.1.85.10.1.1';
|
||||||
|
|
||||||
|
sub check_khi {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
my $snmp_result = $options{snmp}->get_table(
|
||||||
|
oid => $oid_rcKhiSlotPerfEntry,
|
||||||
|
start => $mapping_khi->{rcKhiSlotMemUsed}->{oid},
|
||||||
|
end => $mapping_khi->{rcKhiSlotMemFree}->{oid},
|
||||||
|
nothing_quit => 1
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach (keys %$snmp_result) {
|
||||||
|
next if (! /^$mapping_khi->{rcKhiSlotMemUsed}->{oid}\.(\d+)$/);
|
||||||
|
my $instance = $1;
|
||||||
|
my $result = $options{snmp}->map_instance(mapping => $mapping_khi, results => $snmp_result, instance => $instance);
|
||||||
|
|
||||||
|
my $total = $result->{rcKhiSlotMemUsed} * 1024 + $result->{rcKhiSlotMemFree} * 1024;
|
||||||
|
$self->{memory}->{'slot_' . $1} = {
|
||||||
|
display => 'slot_' . $1,
|
||||||
|
used => $result->{rcKhiSlotMemUsed} * 1024,
|
||||||
|
free => $result->{rcKhiSlotMemFree} * 1024,
|
||||||
|
prct_used => $result->{rcKhiSlotMemUsed} * 1024 / $total,
|
||||||
|
prct_free => $result->{rcKhiSlotMemFree} * 1024 / $total,
|
||||||
|
total => $total
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sub manage_selection {
|
sub manage_selection {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
my $snmp_result = $options{snmp}->get_table(
|
||||||
|
oid => $mapping->{s5ChasUtilMemoryAvailable}->{oid},
|
||||||
|
);
|
||||||
|
|
||||||
$self->{memory} = {};
|
$self->{memory} = {};
|
||||||
$self->{results} = $options{snmp}->get_table(oid => $mapping->{s5ChasUtilMemoryAvailable}->{oid},
|
|
||||||
nothing_quit => 1);
|
|
||||||
foreach my $oid (keys %{$self->{results}}) {
|
foreach my $oid (keys %{$self->{results}}) {
|
||||||
next if ($oid !~ /^$mapping->{s5ChasUtilMemoryAvailable}->{oid}\.(.*)/);
|
next if ($oid !~ /^$mapping->{s5ChasUtilMemoryAvailable}->{oid}\.(.*)/);
|
||||||
my $instance = $1;
|
my $instance = $1;
|
||||||
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => $instance);
|
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
|
||||||
|
|
||||||
$self->{memory}->{$instance} = { display => $instance,
|
$self->{memory}->{$instance} = {
|
||||||
used => 100 - $result->{s5ChasUtilMemoryAvailable}};
|
display => $instance,
|
||||||
|
prct_used => 100 - $result->{s5ChasUtilMemoryAvailable}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (scalar(keys %{$self->{memory}}) <= 0) {
|
||||||
|
$self->check_khi(snmp => $options{snmp});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,13 +163,10 @@ Check memory usages.
|
|||||||
|
|
||||||
=over 8
|
=over 8
|
||||||
|
|
||||||
=item B<--warning-usage>
|
=item B<--warning-*> B<--critical-*>
|
||||||
|
|
||||||
Threshold warning (in percent).
|
Thresholds.
|
||||||
|
Can be: 'usage' (B), 'usage-free' (B), 'usage-prct' (%).
|
||||||
=item B<--critical-usage>
|
|
||||||
|
|
||||||
Threshold critical (in percent).
|
|
||||||
|
|
||||||
=back
|
=back
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user