Debian Codegraph @

src/centreon/common/jvm/mode/cpuload.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::cpuload;
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 => 'global', type => 0, message_separator => ' - ', skipped_code => { -10 => 1 } }
33 ];
34
35 $self->{maps_counters}->{global} = [
36 { label => 'system', nlabel => 'system.cpu.load.percentage', set => {
37 key_values => [ { name => 'system_load' } ],
38 output_template => 'system cpu load: %.2f%%',
39 perfdatas => [
40 { template => '%.2f', min => 0, max => 100, unit => '%' }
41 ]
42 }
43 },
44 { label => 'process', nlabel => 'process.cpu.load.percentage', set => {
45 key_values => [ { name => 'process_load' } ],
46 output_template => 'process cpu load: %.2f%%',
47 perfdatas => [
48 { template => '%.2f', min => 0, max => 100, unit => '%' }
49 ]
50 }
51 }
52 ];
53 }
54
55
56 sub new {
57 my ($class, %options) = @_;
58 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
59 bless $self, $class;
60
61 $options{options}->add_options(arguments => {});
62
63 return $self;
64 }
65
66 sub manage_selection {
67 my ($self, %options) = @_;
68
69 $self->{request} = [
70 { mbean => 'java.lang:type=OperatingSystem', attributes => [ { name => 'SystemCpuLoad' }, { name => 'ProcessCpuLoad' } ] }
71 ];
72
73 my $result = $options{custom}->get_attributes(request => $self->{request}, nothing_quit => 1);
74
75 $self->{global} = {
76 system_load => $result->{'java.lang:type=OperatingSystem'}->{SystemCpuLoad} * 100,
77 process_load => $result->{'java.lang:type=OperatingSystem'}->{ProcessCpuLoad} * 100
78 };
79 }
80
81 1;
82
83 __END__
84
85 =head1 MODE
86
87 Check JVM SystemCpuLoad and ProcessCpuLoad (From 0 to 1 where 1 means 100% of CPU ressources are in use, here we * by 100 for convenience).
88 WARN : Probably not work for java -version < 7.
89
90 Example:
91 perl centreon_plugins.pl --plugin=apps::tomcat::jmx::plugin --custommode=jolokia --url=http://10.30.2.22:8080/jolokia --mode=cpu-load --warning-system 50 --critical-system 75 --warning-process 60 --critical-process 80
92
93 =over 8
94
95 =item B<--warning-system>
96
97 Warning threshold of system CPU load.
98
99 =item B<--critical-system>
100
101 Critical threshold of system CPU load.
102
103 =item B<--warning-process>
104
105 Warning threshold of process CPU load.
106
107 =item B<--critical-process>
108
109 Critical threshold of process CPU load.
110
111 =back
112
113 =cut