Debian Codegraph @

src/centreon/common/jvm/mode/fdusage.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 centreon::common::jvm::mode::fdusage;
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 return sprintf(
32 "File descriptor usage total: %s used: %s (%.2f%%) free: %s (%.2f%%)",
33 $self->{result_values}->{total},
34 $self->{result_values}->{used}, $self->{result_values}->{prct_used},
35 $self->{result_values}->{free}, $self->{result_values}->{prct_free}
36 );
37 }
38
39 sub set_counters {
40 my ($self, %options) = @_;
41
42 $self->{maps_counters_type} = [
43 { name => 'global', type => 0 }
44 ];
45
46 $self->{maps_counters}->{global} = [
47 { label => 'usage', nlabel => 'fd.opened.usage.count', set => {
48 key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ],
49 closure_custom_output => $self->can('custom_usage_output'),
50 perfdatas => [
51 { template => '%d', min => 0, max => 'total', cast_int => 1 },
52 ]
53 }
54 },
55 { label => 'usage-free', display_ok => 0, nlabel => 'fd.opened.free.count', set => {
56 key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ],
57 closure_custom_output => $self->can('custom_usage_output'),
58 perfdatas => [
59 { template => '%d', min => 0, max => 'total', cast_int => 1 }
60 ]
61 }
62 },
63 { label => 'usage-prct', display_ok => 0, nlabel => 'fd.opened.usage.percentage', set => {
64 key_values => [ { name => 'prct_used' }, { name => 'used' }, { name => 'free' }, { name => 'prct_free' }, { name => 'total' } ],
65 output_template => 'Used : %.2f %%',
66 perfdatas => [
67 { template => '%.2f', min => 0, max => 100, unit => '%' }
68 ]
69 }
70 }
71 ];
72 }
73
74 sub new {
75 my ($class, %options) = @_;
76 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
77 bless $self, $class;
78
79 $options{options}->add_options(arguments => {});
80
81 return $self;
82 }
83
84 sub manage_selection {
85 my ($self, %options) = @_;
86
87 $self->{request} = [
88 { mbean => 'java.lang:type=OperatingSystem', attributes => [ { name => 'MaxFileDescriptorCount' }, { name => 'OpenFileDescriptorCount' } ] }
89 ];
90 my $result = $options{custom}->get_attributes(request => $self->{request}, nothing_quit => 1);
91
92 $self->{global} = {
93 used => $result->{'java.lang:type=OperatingSystem'}->{OpenFileDescriptorCount},
94 free => $result->{'java.lang:type=OperatingSystem'}->{MaxFileDescriptorCount} - $result->{'java.lang:type=OperatingSystem'}->{OpenFileDescriptorCount},
95 total => $result->{'java.lang:type=OperatingSystem'}->{MaxFileDescriptorCount}
96 };
97 $self->{global}->{prct_used} = $self->{global}->{used} / $self->{global}->{total} * 100;
98 $self->{global}->{prct_free} = 100 - $self->{global}->{prct_used};
99
100 }
101
102 1;
103
104 __END__
105
106 =head1 MODE
107
108 Check number/percentage of file descriptors
109
110 Example:
111 perl centreon_plugins.pl --plugin=apps::tomcat::jmx::plugin --custommode=jolokia --url=http://10.30.2.22:8080/jolokia-war --mode=fd-usage --warning 60 --critical 75
112
113 =over 8
114
115 =item B<--warning-*> B<--critical-*>
116
117 Thresholds.
118 Can be: 'usage', 'usage-free', 'usage-prct' (%).
119
120 =back
121
122 =cut