Debian Codegraph @

src/centreon/common/jvm/mode/gcusage.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::gcusage;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27 use Digest::MD5 qw(md5_hex);
28
29 sub prefix_gc_output {
30 my ($self, %options) = @_;
31
32 return "Garbage collector '" . $options{instance_value}->{display} . "' ";
33 }
34
35 sub set_counters {
36 my ($self, %options) = @_;
37
38 $self->{maps_counters_type} = [
39 { name => 'gc', type => 1, cb_prefix_output => 'prefix_gc_output', message_multiple => 'All garbage collectors are ok' }
40 ];
41
42 $self->{maps_counters}->{gc} = [
43 { label => 'time', nlabel => 'gc.collection.time.elapsed.milliseconds', set => {
44 key_values => [ { name => 'time', diff => 1 }, { name => 'display' } ],
45 output_template => 'collection time: %s ms',
46 perfdatas => [
47 { template => '%s', unit => 'ms', min => 0, label_extra_instance => 1, instance_use => 'display' }
48 ]
49 }
50 },
51 { label => 'count', nlabel => 'gc.collection.count', set => {
52 key_values => [ { name => 'count', diff => 1 }, { name => 'display' } ],
53 output_template => 'collection count: %s',
54 perfdatas => [
55 { template => '%s', min => 0, label_extra_instance => 1, instance_use => 'display' }
56 ]
57 }
58 }
59 ];
60 }
61
62 sub new {
63 my ($class, %options) = @_;
64 my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1);
65 bless $self, $class;
66
67 $options{options}->add_options(arguments => {
68 'filter-name:s' => { name => 'filter_name' }
69 });
70
71 return $self;
72 }
73
74 sub manage_selection {
75 my ($self, %options) = @_;
76
77 $self->{request} = [
78 { mbean => "java.lang:type=GarbageCollector,name=*", attributes => [ { name => 'CollectionCount' }, { name => 'CollectionTime' } ] }
79 ];
80
81 $self->{gc} = {};
82 my $result = $options{custom}->get_attributes(request => $self->{request}, nothing_quit => 1);
83
84 foreach my $key (keys %$result) {
85 $key =~ /name=(.*?)(?:,|$)/;
86 my $name = $1;
87
88 $self->{gc}->{$name} = {
89 display => $name,
90 time => $result->{$key}->{CollectionTime},
91 count => $result->{$key}->{CollectionCount}
92 }
93 }
94
95 if (scalar(keys %{$self->{gc}}) <= 0) {
96 $self->{output}->add_option_msg(short_msg => 'No garbage collector found.');
97 $self->{output}->option_exit();
98 }
99
100 $self->{cache_name} = 'jvm_standard_' . $self->{mode} . '_' . md5_hex($options{custom}->get_connection_info()) . '_' .
101 (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
102 (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all'));
103 }
104
105 1;
106
107 __END__
108
109 =head1 MODE
110
111 Check garbage collectors.
112
113 =over 8
114
115 =item B<--filter-counters>
116
117 Only display some counters (regexp can be used).
118 Example: --filter-counters='^count$'
119
120 =item B<--filter-name>
121
122 Filter garbage collector name (can be a regexp).
123
124 =item B<--warning-*>
125
126 Warning threshold.
127 Can be: 'count', 'time' (ms).
128
129 =item B<--critical-*>
130
131 Critical threshold.
132 Can be: 'count', 'time' (ms).
133
134 =back
135
136 =cut