Debian Codegraph @

src/os/aix/snmp/mode/swap.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 os::aix::snmp::mode::swap;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27
28 sub custom_usage_output {
29 my ($self, %options) = @_;
30
31 my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total});
32 my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
33 my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
34 return sprintf(
35 "Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
36 $total_size_value . " " . $total_size_unit,
37 $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
38 $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}
39 );
40 }
41
42 sub custom_usage_calc {
43 my ($self, %options) = @_;
44
45 return -10 if ($options{new_datas}->{$self->{instance} . '_total'} <= 0);
46 $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
47 $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'};
48 $self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_used'};
49 $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used};
50 $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total};
51 $self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used};
52
53 return 0;
54 }
55
56 sub set_counters {
57 my ($self, %options) = @_;
58
59 $self->{maps_counters_type} = [
60 { name => 'global', type => 0, message_separator => ' - ', cb_init => 'skip_global', },
61 { name => 'swap', type => 1, cb_prefix_output => 'prefix_swap_output', message_multiple => 'All page spaces are ok' }
62 ];
63
64 $self->{maps_counters}->{global} = [
65 { label => 'total-usage', nlabel => 'page.space.usage.bytes', set => {
66 key_values => [ { name => 'used' }, { name => 'total' } ],
67 closure_custom_calc => $self->can('custom_usage_calc'),
68 closure_custom_output => $self->can('custom_usage_output'),
69 threshold_use => 'prct_used',
70 perfdatas => [
71 { label => 'total_page_space', value => 'used', template => '%s', cast_int => 1,
72 unit => 'B', min => 0, max => 'total', threshold_total => 'total' }
73 ]
74 }
75 },
76 { label => 'total-active', nlabel => 'page.space.active.count', display_ok => 0, set => {
77 key_values => [ { name => 'nactive' }, { name => 'ntotal' } ],
78 output_template => 'Total page space active : %s',
79 perfdatas => [
80 { label => 'total_active', value => 'nactive', template => '%s',
81 min => 0, max => 'ntotal' }
82 ]
83 }
84 }
85 ];
86
87 $self->{maps_counters}->{swap} = [
88 { label => 'usage', nlabel => 'page.space.usage.bytes', set => {
89 key_values => [ { name => 'used' }, { name => 'total' }, { name => 'display' } ],
90 closure_custom_calc => $self->can('custom_usage_calc'),
91 closure_custom_output => $self->can('custom_usage_output'),
92 threshold_use => 'prct_used',
93 perfdatas => [
94 { label => 'page_space', value => 'used', template => '%s', cast_int => 1,
95 unit => 'B', min => 0, max => 'total', threshold_total => 'total',
96 label_extra_instance => 1, instance_use => 'display' }
97 ]
98 }
99 }
100 ];
101 }
102
103
104 sub prefix_swap_output {
105 my ($self, %options) = @_;
106
107 return "Page space '" . $options{instance_value}->{display} . "' ";
108 }
109
110 sub skip_global {
111 my ($self, %options) = @_;
112
113 scalar(keys %{$self->{swap}}) > 1 ? return(0) : return(1);
114 }
115
116 sub new {
117 my ($class, %options) = @_;
118 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
119 bless $self, $class;
120
121 $options{options}->add_options(arguments => {
122 'paging-state-buggy' => { name => 'paging_state_buggy' }
123 });
124
125 return $self;
126 }
127
128 my $mapping = {
129 swap_name => { oid => '.1.3.6.1.4.1.2.6.191.2.4.2.1.1' }, # aixPageName
130 swap_total => { oid => '.1.3.6.1.4.1.2.6.191.2.4.2.1.4' }, # aixPageSize (in MB)
131 swap_usage => { oid => '.1.3.6.1.4.1.2.6.191.2.4.2.1.5' }, # aixPagePercentUsed
132 swap_status => { oid => '.1.3.6.1.4.1.2.6.191.2.4.2.1.6' } # aixPageStatus
133 };
134
135 sub manage_selection {
136 my ($self, %options) = @_;
137
138 my $aix_swap_pool = ".1.3.6.1.4.1.2.6.191.2.4.2.1"; # aixPageEntry
139
140 my $snmp_result = $options{snmp}->get_table(
141 oid => $aix_swap_pool,
142 end => $mapping->{swap_status}->{oid},
143 nothing_quit => 1
144 );
145
146 # Check if the paging space is active.
147 # Values are :
148 # 1 = "active"
149 # 2 = "notActive"
150 # Some systems may however return the contrary.
151 my $active_swap = 1;
152 if (defined($self->{option_results}->{paging_state_buggy})) {
153 $active_swap = 2;
154 }
155
156 $self->{global} = { nactive => 0, ntotal => 0, total => 0, used => 0 };
157 $self->{swap} = {};
158
159 foreach (keys %$snmp_result) {
160 next if (! /^$mapping->{swap_status}->{oid}\.(.*)$/);
161
162 $self->{global}->{ntotal}++;
163 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $1);
164 next if ($result->{swap_status} != $active_swap);
165
166 $self->{global}->{nactive}++;
167
168 my $used = ($result->{swap_usage} * $result->{swap_total} / 100) * 1024 * 1024;
169 my $total = $result->{swap_total} * 1024 * 1024;
170 $self->{swap}->{ $result->{swap_name} } = {
171 display => $result->{swap_name},
172 used => $used,
173 total => $total
174 };
175 $self->{global}->{used} += $used;
176 $self->{global}->{total} += $total;
177 }
178 }
179
180 1;
181
182 __END__
183
184 =head1 MODE
185
186 Check AIX swap memory.
187
188 =over 8
189
190 =item B<--warning-usage>
191
192 Warning threshold in percent.
193
194 =item B<--critical-usage>
195
196 Critical threshold in percent.
197
198 =item B<--warning-total-usage>
199
200 Warning threshold in percent.
201
202 =item B<--critical-total-usage>
203
204 Critical threshold in percent.
205
206 =item B<--warning-total-active>
207
208 Warning threshold total page space active.
209
210 =item B<--critical-total-active>
211
212 Critical threshold total page space active.
213
214 =item B<--paging-state-buggy>
215
216 Paging state can be buggy. Please use the following option to swap state value.
217
218 =back
219
220 =cut