Debian Codegraph @

src/network/a10/ax/snmp/mode/cpu.pm

raw
1 #
2 # Copyright 2024 Centreon (http://www.centreon.com/)
3 #
4 # Centreon is a full-fledged industry-strength solution that meets
5 # the needs in IT infrastructure and application monitoring for
6 # service performance.
7 #
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
11 #
12 # http://www.apache.org/licenses/LICENSE-2.0
13 #
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
19 #
20
21 package network::a10::ax::snmp::mode::cpu;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27
28 sub set_counters {
29 my ($self, %options) = @_;
30
31 $self->{maps_counters_type} = [
32 { name => 'cpu', type => 1, cb_prefix_output => 'prefix_cpu_output', message_multiple => 'All CPUs are ok' },
33 ];
34
35 $self->{maps_counters}->{cpu} = [
36 { label => 'cpu-30s', nlabel => 'cpu.utilization.30s.percentage', set => {
37 key_values => [ { name => 'cpu_30s' }, { name => 'display' } ],
38 output_template => '30s : %s %%',
39 perfdatas => [
40 { label => 'cpu_30s', value => 'cpu_30s', template => '%s',
41 unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' },
42 ],
43 }
44 },
45 { label => 'cpu-1m', nlabel => 'cpu.utilization.1m.percentage', set => {
46 key_values => [ { name => 'cpu_1m' }, { name => 'display' } ],
47 output_template => '1m : %s %%',
48 perfdatas => [
49 { label => 'cpu_1m', value => 'cpu_1m', template => '%s',
50 unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' },
51 ],
52 }
53 },
54 ];
55 }
56
57 sub prefix_cpu_output {
58 my ($self, %options) = @_;
59
60 return "CPU '" . $options{instance_value}->{display} . "' ";
61 }
62
63 sub new {
64 my ($class, %options) = @_;
65 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
66 bless $self, $class;
67
68 $options{options}->add_options(arguments =>
69 {
70 });
71
72 return $self;
73 }
74
75 my $oid_axSysCpuUsageValueAtPeriod = '.1.3.6.1.4.1.22610.2.4.1.3.6.1.3';
76
77 sub manage_selection {
78 my ($self, %options) = @_;
79
80 my $results = $options{snmp}->get_table(oid => $oid_axSysCpuUsageValueAtPeriod,
81 nothing_quit => 1);
82
83 $self->{cpu} = {};
84 foreach my $oid (keys %$results) {
85 $oid =~ /\.(\d*?)\.\d*?$/;
86 next if (defined($self->{cpu}->{$1}));
87 my $instance = $1;
88
89 $self->{cpu}->{$instance} = { display => $instance,
90 cpu_1m => $results->{$oid_axSysCpuUsageValueAtPeriod . '.' . $instance . '.5'},
91 cpu_30s => $results->{$oid_axSysCpuUsageValueAtPeriod . '.' . $instance . '.4'}
92 };
93 }
94 }
95
96 1;
97
98 __END__
99
100 =head1 MODE
101
102 Check CPU usage.
103
104 =over 8
105
106 =item B<--filter-counters>
107
108 Only display some counters (regexp can be used).
109 Example : --filter-counters='^cpu-1m$'
110
111 =item B<--warning-*>
112
113 Warning threshold.
114 Can be: 'cpu-30s' (%), 'cpu-1m' (%).
115
116 =item B<--critical-*>
117
118 Critical threshold.
119 Can be: 'cpu-30s' (%), 'cpu-1m' (%).
120
121 =back
122
123 =cut