This commit is contained in:
qgarnier 2017-11-29 15:29:15 +01:00
parent 296c3f0ff5
commit e9e2a99c7e
1 changed files with 139 additions and 23 deletions

View File

@ -29,46 +29,120 @@ sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0, cb_prefix_output => 'prefix_cpu_output' }
{ name => 'mp_cpu', type => 0, cb_prefix_output => 'prefix_mp_cpu_output', skipped_code => { -10 => 1 } },
{ name => 'sp_ga_avg', type => 0, skipped_code => { -10 => 1 } },
{ name => 'sp_ga', type => 1, cb_init => 'skip_sp_ga', cb_prefix_output => 'prefix_sp_ga_output', message_multiple => 'All SP GA CPU are ok' },
];
$self->{maps_counters}->{global} = [
{ label => '1s', set => {
key_values => [ { name => '1s' } ],
$self->{maps_counters}->{mp_cpu} = [
{ label => 'mp-1s', set => {
key_values => [ { name => 'mp_1s' } ],
output_template => '%.2f%% (1sec)',
perfdatas => [
{ label => 'cpu_1s', value => '1s_absolute', template => '%.2f',
{ label => 'mp_cpu_1s', value => 'mp_1s_absolute', template => '%.2f',
min => 0, max => 100, unit => '%' },
],
}
},
{ label => '4s', set => {
key_values => [ { name => '4s' } ],
{ label => 'mp-4s', set => {
key_values => [ { name => 'mp_4s' } ],
output_template => '%.2f%% (4sec)',
perfdatas => [
{ label => 'cpu_4s', value => '4s_absolute', template => '%.2f',
{ label => 'mp_cpu_4s', value => 'mp_4s_absolute', template => '%.2f',
min => 0, max => 100, unit => '%' },
],
}
},
{ label => '64s', set => {
key_values => [ { name => '64s' } ],
{ label => 'mp-64s', set => {
key_values => [ { name => 'mp_64s' } ],
output_template => '%.2f%% (64sec)',
perfdatas => [
{ label => 'cpu_64s', value => '64s_absolute', template => '%.2f',
{ label => 'mp_cpu_64s', value => 'mp_64s_absolute', template => '%.2f',
min => 0, max => 100, unit => '%' },
],
}
},
];
$self->{maps_counters}->{sp_ga_avg} = [
{ label => 'sp-ga-avg-1s', set => {
key_values => [ { name => 'sp_1s' } ],
output_template => 'SP GA Average CPU Usage: %.2f%% (1sec)',
perfdatas => [
{ label => 'avg_spga_cpu_1s', value => 'sp_1s_absolute', template => '%.2f',
min => 0, max => 100, unit => '%' },
],
}
},
{ label => 'sp-ga-avg-4s', set => {
key_values => [ { name => 'sp_4s' } ],
output_template => '%.2f%% (4sec)',
perfdatas => [
{ label => 'avg_spga_cpu_4s', value => 'sp_4s_absolute', template => '%.2f',
min => 0, max => 100, unit => '%' },
],
}
},
{ label => 'sp-ga-avg-64s', set => {
key_values => [ { name => 'sp_64s' } ],
output_template => '%.2f%% (64sec)',
perfdatas => [
{ label => 'avg_spga_cpu_64s', value => 'sp_64s_absolute', template => '%.2f',
min => 0, max => 100, unit => '%' },
],
}
},
];
$self->{maps_counters}->{sp_ga} = [
{ label => 'sp-ga-1s', set => {
key_values => [ { name => 'sp_1s' }, { name => 'display' } ],
output_template => '%.2f%% (1sec)',
perfdatas => [
{ label => 'spga_cpu_1s', value => 'sp_1s_absolute', template => '%.2f',
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
{ label => 'sp-ga-4s', set => {
key_values => [ { name => 'sp_4s' }, { name => 'display' } ],
output_template => '%.2f%% (4sec)',
perfdatas => [
{ label => 'spga_cpu_4s', value => 'sp_4s_absolute', template => '%.2f',
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
{ label => 'sp-ga-64s', set => {
key_values => [ { name => 'sp_64s' }, { name => 'display' } ],
output_template => '%.2f%% (64sec)',
perfdatas => [
{ label => 'spga_cpu_64s', value => 'sp_64s_absolute', template => '%.2f',
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
];
}
sub prefix_cpu_output {
sub prefix_mp_cpu_output {
my ($self, %options) = @_;
return "MP CPU Usage: ";
}
sub prefix_sp_ga_output {
my ($self, %options) = @_;
return "SP GA CPU '" . $options{instance_value}->{display} . "' Usage: ";
}
sub skip_sp_ga {
my ($self, %options) = @_;
scalar(keys %{$self->{sp_ga}}) <= 0 ? return(1) : return(0);
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
@ -82,18 +156,56 @@ sub new {
return $self;
}
my $mapping = {
mpCpuStatsUtil1Second => { oid => '.1.3.6.1.4.1.1872.2.5.1.2.2.1' },
mpCpuStatsUtil4Seconds => { oid => '.1.3.6.1.4.1.1872.2.5.1.2.2.2' },
mpCpuStatsUtil64Seconds => { oid => '.1.3.6.1.4.1.1872.2.5.1.2.2.3' },
};
my $mapping2 = {
spGAStatsCpuUtil1Second => { oid => '.1.3.6.1.4.1.1872.2.5.1.2.13.1.1.3' },
spGAStatsCpuUtil4Seconds => { oid => '.1.3.6.1.4.1.1872.2.5.1.2.13.1.1.4' },
spGAStatsCpuUtil64Seconds => { oid => '.1.3.6.1.4.1.1872.2.5.1.2.13.1.1.5' },
};
my $oid_mpCpuStats = '.1.3.6.1.4.1.1872.2.5.1.2.2';
my $oid_spGAStatsCpuUtilTableEntry = '.1.3.6.1.4.1.1872.2.5.1.2.13.1.1';
sub manage_selection {
my ($self, %options) = @_;
my $snmp_result = $options{snmp}->get_multiple_table(oids => [ { oid => $oid_mpCpuStats }, { oid => $oid_spGAStatsCpuUtilTableEntry } ],
return_type => 1, nothing_quit => 1);
$self->{sp_ga} = {};
my ($avg_sp_1s, $avg_sp_4s, $avg_sp_64s) = (0, 0, 0);
foreach my $oid (keys %{$snmp_result}) {
next if ($oid !~ /^$mapping2->{spGAStatsCpuUtil64Seconds}->{oid}\.(.*)$/);
my $instance = $1;
my $result = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result, instance => $instance);
my $oid_mpCpuStatsUtil1Second = '.1.3.6.1.4.1.1872.2.5.1.2.2.1.0';
my $oid_mpCpuStatsUtil4Seconds = '.1.3.6.1.4.1.1872.2.5.1.2.2.2.0';
my $oid_mpCpuStatsUtil64Seconds = '.1.3.6.1.4.1.1872.2.5.1.2.2.3.0';
my $snmp_result = $options{snmp}->get_leef(oids => [
$oid_mpCpuStatsUtil1Second, $oid_mpCpuStatsUtil4Seconds,
$oid_mpCpuStatsUtil64Seconds], nothing_quit => 1);
$self->{sp_ga}->{$instance} = {
display => $instance,
sp_1s => $result->{spGAStatsCpuUtil1Second},
sp_4s => $result->{spGAStatsCpuUtil4Seconds},
sp_64s => $result->{spGAStatsCpuUtil64Seconds},
};
$avg_sp_1s += $result->{spGAStatsCpuUtil1Second};
$avg_sp_4s += $result->{spGAStatsCpuUtil4Seconds};
$avg_sp_64s += $result->{spGAStatsCpuUtil64Seconds};
}
$self->{global} = { '1s' => $snmp_result->{$oid_mpCpuStatsUtil1Second}, '4s' => $snmp_result->{$oid_mpCpuStatsUtil4Seconds},
'64s' => $snmp_result->{$oid_mpCpuStatsUtil64Seconds} };
$self->{sp_ga_avg} = {};
if (scalar(keys %{$self->{sp_ga}}) > 1) {
$self->{sp_ga_avg} = {
sp_1s => $avg_sp_1s / scalar(keys %{$self->{sp_ga}}),
sp_4s => $avg_sp_4s / scalar(keys %{$self->{sp_ga}}),
sp_64s => $avg_sp_64s / scalar(keys %{$self->{sp_ga}}),
};
}
$self->{mp_cpu} = {
mp_1s => $snmp_result->{$mapping->{mpCpuStatsUtil1Second}->{oid} . '.0'},
mp_4s => $snmp_result->{$mapping->{mpCpuStatsUtil4Seconds}->{oid} . '.0'},
mp_64s => $snmp_result->{$mapping->{mpCpuStatsUtil64Seconds}->{oid} . '.0'},
};
}
1;
@ -114,14 +226,18 @@ Example: --filter-counters='^(64s)$'
=item B<--warning-*>
Threshold warning.
Can be: '1s', '4s', '64s'.
Can be: 'mp-1s', 'mp-4s', 'mp-64s',
'sp-ga-1s', 'sp-ga-4s', 'sp-ga-64s',
'sp-ga-avg-1s', 'sp-ga-avg-4s', 'sp-ga-avg-64s'.
=item B<--critical-*>
Threshold critical.
Can be: '1s', '4s', '64s'.
Can be: 'mp-1s', 'mp-4s', 'mp-64s',
'sp-ga-1s', 'sp-ga-4s', 'sp-ga-64s',
'sp-ga-avg-1s', 'sp-ga-avg-4s', 'sp-ga-avg-64s'.
=back
=cut