Debian Codegraph @

src/apps/oracle/ucp/jmx/mode/connectionpools.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 apps::oracle::ucp::jmx::mode::connectionpools;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27
28 sub custom_usage_perfdata {
29 my ($self, %options) = @_;
30
31 $self->{output}->perfdata_add(
32 nlabel => $self->{nlabel},
33 instances => $self->{result_values}->{poolName},
34 value => $self->{result_values}->{used},
35 warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}),
36 critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}),
37 min => 0,
38 max => $self->{result_values}->{total} > 0 ? $self->{result_values}->{total} : undef
39 );
40 }
41
42 sub custom_usage_free_perfdata {
43 my ($self, %options) = @_;
44
45 $self->{output}->perfdata_add(
46 nlabel => $self->{nlabel},
47 instances => $self->{result_values}->{poolName},
48 value => $self->{result_values}->{free},
49 warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}),
50 critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}),
51 min => 0,
52 max => $self->{result_values}->{total}
53 );
54 }
55
56 sub custom_usage_prct_perfdata {
57 my ($self, %options) = @_;
58
59 $self->{output}->perfdata_add(
60 nlabel => $self->{nlabel},
61 unit => '%',
62 instances => $self->{result_values}->{poolName},
63 value => sprintf('%.2f', $self->{result_values}->{prct_used}),
64 warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}),
65 critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}),
66 min => 0, max => 100
67 );
68 }
69
70 sub custom_usage_threshold {
71 my ($self, %options) = @_;
72
73 return $self->{perfdata}->threshold_check(
74 value => $self->{result_values}->{used}, threshold => [
75 { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' },
76 { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' },
77 ]
78 );
79 }
80
81 sub custom_usage_free_threshold {
82 my ($self, %options) = @_;
83
84 return $self->{perfdata}->threshold_check(
85 value => $self->{result_values}->{free}, threshold => [
86 { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' },
87 { label => 'warning-'. $self->{thlabel}, exit_litteral => 'warning' }
88 ]
89 );
90 }
91
92 sub custom_usage_prct_threshold {
93 my ($self, %options) = @_;
94
95 return $self->{perfdata}->threshold_check(
96 value => $self->{result_values}->{prct_used}, threshold => [
97 { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' },
98 { label => 'warning-'. $self->{thlabel}, exit_litteral => 'warning' }
99 ]
100 );
101 }
102
103 sub custom_usage_output {
104 my ($self, %options) = @_;
105
106 my $msg;
107 if ($self->{result_values}->{total} <= 0) {
108 $msg = sprintf("used: %s (unlimited)", $self->{result_values}->{used});
109 } else {
110 $msg = sprintf(
111 "total: %s used: %s (%.2f%%) free: %s (%.2f%%)",
112 $self->{result_values}->{total},
113 $self->{result_values}->{used}, $self->{result_values}->{prct_used},
114 $self->{result_values}->{free}, $self->{result_values}->{prct_free}
115 );
116 }
117
118 return $msg;
119 }
120
121 sub custom_usage_calc {
122 my ($self, %options) = @_;
123
124 $self->{result_values}->{poolName} = $options{new_datas}->{$self->{instance} . '_poolName'};
125 $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'};
126 $self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_used'};
127
128 if ($self->{result_values}->{total} == 0) {
129 return -10 if ($options{extra_options}->{label} ne 'usage');
130 return 0;
131 }
132
133 $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total};
134 $self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used};
135 $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used};
136
137 return 0;
138 }
139
140 sub prefix_pool_output {
141 my ($self, %options) = @_;
142
143 return sprintf(
144 "Connection pool '%s' ",
145 $options{instance_value}->{poolName}
146 );
147 }
148
149 sub set_counters {
150 my ($self, %options) = @_;
151
152 $self->{maps_counters_type} = [
153 { name => 'pools', type => 1, cb_prefix_output => 'prefix_pool_output', message_multiple => 'All connection pools are ok', skipped_code => { -10 => 1 } }
154 ];
155
156 $self->{maps_counters}->{pools} = [
157 { label => 'usage', nlabel => 'connection_pool.usage.count', set => {
158 key_values => [
159 { name => 'poolName' }, { name => 'used' }, { name => 'total' }
160 ],
161 closure_custom_calc_extra_options => { label => 'usage' },
162 closure_custom_calc => $self->can('custom_usage_calc'),
163 closure_custom_output => $self->can('custom_usage_output'),
164 closure_custom_threshold_check => $self->can('custom_usage_threshold'),
165 closure_custom_perfdata => $self->can('custom_usage_perfdata')
166 }
167 },
168 { label => 'usage-free', nlabel => 'connection_pool.free.count', display_ok => 0, set => {
169 key_values => [
170 { name => 'poolName' }, { name => 'used' }, { name => 'total' }
171 ],
172 closure_custom_calc_extra_options => { label => 'free' },
173 closure_custom_calc => $self->can('custom_usage_calc'),
174 closure_custom_output => $self->can('custom_usage_output'),
175 closure_custom_threshold_check => $self->can('custom_usage_free_threshold'),
176 closure_custom_perfdata => $self->can('custom_usage_free_perfdata')
177 }
178 },
179 { label => 'usage-prct', nlabel => 'connection_pool.usage.percentage', display_ok => 0, set => {
180 key_values => [
181 { name => 'poolName' }, { name => 'used' }, { name => 'total' }
182 ],
183 closure_custom_calc_extra_options => { label => 'prct' },
184 closure_custom_calc => $self->can('custom_usage_calc'),
185 closure_custom_output => $self->can('custom_usage_output'),
186 closure_custom_threshold_check => $self->can('custom_usage_prct_threshold'),
187 closure_custom_perfdata => $self->can('custom_usage_prct_perfdata')
188 }
189 }
190 ];
191 }
192
193
194 sub new {
195 my ($class, %options) = @_;
196 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
197 bless $self, $class;
198
199 $options{options}->add_options(arguments => {
200 'filter-pool-name:s' => { name => 'filter_pool_name' }
201 });
202
203 return $self;
204 }
205
206 sub manage_selection {
207 my ($self, %options) = @_;
208
209 my $request = [
210 { mbean => "oracle.ucp.admin.UniversalConnectionPoolMBean:name=UniversalConnectionPoolManager*,poolName=*", attributes =>
211 [ { name => 'remainingPoolCapacityCount' }, { name => 'totalConnectionsCount' }, { name => 'maxPoolSize' } ] }
212 ];
213
214 my $result = $options{custom}->get_attributes(request => $request, nothing_quit => 1);
215
216 $self->{pools} = {};
217 foreach my $key (keys %$result) {
218 $key =~ /(?:[:,])poolName=(.*?)(?:,|$)/;
219 my $poolName = $1;
220
221 next if (defined($self->{option_results}->{filter_pool_name}) && $self->{option_results}->{filter_pool_name} ne '' &&
222 $poolName !~ /$self->{option_results}->{filter_pool_name}/);
223
224 $self->{pools}->{$poolName} = {
225 poolName => $poolName,
226 used => $result->{$key}->{totalConnectionsCount},
227 total => defined($result->{$key}->{maxPoolSize}) ? $result->{$key}->{maxPoolSize} : 0
228 };
229 }
230
231 if (scalar(keys %{$self->{pools}}) <= 0) {
232 $self->{output}->add_option_msg(short_msg => 'No connection pools found');
233 $self->{output}->option_exit();
234 }
235 }
236
237 1;
238
239 __END__
240
241 =head1 MODE
242
243 Check connection pools.
244
245 =over 8
246
247 =item B<--filter-pool-name>
248
249 Filter connection pools by name (can be a regexp).
250
251 =item B<--warning-*> B<--critical-*>
252
253 Thresholds.
254 Can be: 'usage', 'usage-free', 'usage-prct'.
255
256 =back
257
258 =cut