From 1a701de7f4bf3af5b89d17f4b4e60bc9a79bd39b Mon Sep 17 00:00:00 2001 From: qgarnier Date: Tue, 3 Aug 2021 14:17:40 +0200 Subject: [PATCH] break(jvm/jmx): force metric v2 - tomcat/jboss/weblogic (#3011) --- .../centreon/common/jvm/mode/classcount.pm | 65 ++++---- .../centreon/common/jvm/mode/cpuload.pm | 101 +++++------- .../centreon/common/jvm/mode/fdusage.pm | 112 +++++++------ .../centreon/common/jvm/mode/gcusage.pm | 70 ++++---- .../centreon/common/jvm/mode/loadaverage.pm | 77 ++++----- .../centreon/common/jvm/mode/memory.pm | 118 ++++++++------ .../common/jvm/mode/memorydetailed.pm | 152 ++++++++++-------- .../centreon/common/jvm/mode/threads.pm | 56 ++++--- 8 files changed, 371 insertions(+), 380 deletions(-) diff --git a/centreon-plugins/centreon/common/jvm/mode/classcount.pm b/centreon-plugins/centreon/common/jvm/mode/classcount.pm index d5b6cef2e..ba20abe4f 100644 --- a/centreon-plugins/centreon/common/jvm/mode/classcount.pm +++ b/centreon-plugins/centreon/common/jvm/mode/classcount.pm @@ -26,56 +26,54 @@ use strict; use warnings; use Digest::MD5 qw(md5_hex); +sub prefix_global_output { + my ($self, %options) = @_; + + return 'Class '; +} + sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output', skipped_code => { -10 => 1 } }, + { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output', skipped_code => { -10 => 1 } } ]; $self->{maps_counters}->{global} = [ - { label => 'current', set => { + { label => 'current', nlabel => 'class.loaded.current.count', set => { key_values => [ { name => 'LoadedClassCount' } ], - output_template => 'Current : %s', + output_template => 'current: %s', perfdatas => [ - { label => 'current', value => 'LoadedClassCount', template => '%s', min => 0 }, - ], + { template => '%s', min => 0 } + ] } }, - { label => 'loaded', set => { + { label => 'loaded', nlabel => 'class.loaded.total.count', set => { key_values => [ { name => 'TotalLoadedClassCount', diff => 1 } ], - output_template => 'Loaded : %s', + output_template => 'loaded: %s', perfdatas => [ - { label => 'loaded', value => 'TotalLoadedClassCount', template => '%s', min => 0 }, - ], + { template => '%s', min => 0 } + ] } }, - { label => 'unloaded', set => { + { label => 'unloaded', nlabel => 'class.unloaded.total.count', set => { key_values => [ { name => 'UnloadedClassCount', diff => 1 } ], - output_template => 'Unloaded : %s', + output_template => 'unloaded: %s', perfdatas => [ - { label => 'unloaded', value => 'UnloadedClassCount', template => '%s', min => 0 }, - ], + { template => '%s', min => 0 } + ] } - }, + } ]; } -sub prefix_global_output { - my ($self, %options) = @_; - - return "Class "; -} - sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); bless $self, $class; - - $options{options}->add_options(arguments => - { - }); - + + $options{options}->add_options(arguments => {}); + return $self; } @@ -88,9 +86,9 @@ sub manage_selection { ]; my $result = $options{custom}->get_attributes(request => $request, nothing_quit => 1); - $self->{global} = { %{$result->{$mbean}} }; - - $self->{cache_name} = "jvm_standard_" . $self->{mode} . '_' . md5_hex($options{custom}->get_connection_info()) . '_' . + $self->{global} = $result->{$mbean}; + + $self->{cache_name} = 'jvm_standard_' . $self->{mode} . '_' . md5_hex($options{custom}->get_connection_info()) . '_' . (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); } @@ -109,14 +107,9 @@ Check Java Class Loading Mbean. Only display some counters (regexp can be used). Example: --filter-counters='current' -=item B<--warning-*> +=item B<--warning-*> B<--critical-*> -Threshold warning. -Can be: 'unloaded', 'loaded', 'current'. - -=item B<--critical-*> - -Threshold critical. +Thresholds. Can be: 'unloaded', 'loaded', 'current'. =back diff --git a/centreon-plugins/centreon/common/jvm/mode/cpuload.pm b/centreon-plugins/centreon/common/jvm/mode/cpuload.pm index 818779ee6..0d95f0034 100644 --- a/centreon-plugins/centreon/common/jvm/mode/cpuload.pm +++ b/centreon-plugins/centreon/common/jvm/mode/cpuload.pm @@ -20,84 +20,62 @@ package centreon::common::jvm::mode::cpuload; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, message_separator => ' - ', skipped_code => { -10 => 1 } } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'system', nlabel => 'system.cpu.load.percentage', set => { + key_values => [ { name => 'system_load' } ], + output_template => 'system cpu load: %.2f%%', + perfdatas => [ + { template => '%.2f', min => 0, max => 100, unit => '%' } + ] + } + }, + { label => 'process', nlabel => 'process.cpu.load.percentage', set => { + key_values => [ { name => 'process_load' } ], + output_template => 'process cpu load: %.2f%%', + perfdatas => [ + { template => '%.2f', min => 0, max => 100, unit => '%' } + ] + } + } + ]; +} + + sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $options{options}->add_options(arguments => - { - "warning-system:s" => { name => 'warning_system' }, - "critical-system:s" => { name => 'critical_system' }, - "warning-process:s" => { name => 'warning_process' }, - "critical-process:s" => { name => 'critical_process' } - }); + $options{options}->add_options(arguments => {}); + return $self; } -sub check_options { +sub manage_selection { my ($self, %options) = @_; - $self->SUPER::init(%options); - - if (($self->{perfdata}->threshold_validate(label => 'warning-system', value => $self->{option_results}->{warning_system})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning-system threshold '" . $self->{option_results}->{warning_system} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'critical-system', value => $self->{option_results}->{critical_system})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical-system threshold '" . $self->{option_results}->{critical_system} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'warning-process', value => $self->{option_results}->{warning_process})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning-process threshold '" . $self->{option_results}->{warning_process} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'critical-process', value => $self->{option_results}->{critical_process})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical-process threshold '" . $self->{option_results}->{critical_process} . "'."); - $self->{output}->option_exit(); - } -} - -sub run { - my ($self, %options) = @_; - $self->{connector} = $options{custom}; $self->{request} = [ - { mbean => "java.lang:type=OperatingSystem", attributes => [ { name => 'SystemCpuLoad' }, { name => 'ProcessCpuLoad' } ] } + { mbean => 'java.lang:type=OperatingSystem', attributes => [ { name => 'SystemCpuLoad' }, { name => 'ProcessCpuLoad' } ] } ]; - my $result = $self->{connector}->get_attributes(request => $self->{request}, nothing_quit => 1); - my $exit = $self->{perfdata}->threshold_check(value => $result->{"java.lang:type=OperatingSystem"}->{SystemCpuLoad} * 100, - threshold => [ { label => 'critical-system', exit_litteral => 'critical' }, { label => 'warning-system', exit_litteral => 'warning' } ]); - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("SystemCpuLoad: %.2f%%", - $result->{"java.lang:type=OperatingSystem"}->{SystemCpuLoad} * 100)); - - $exit = $self->{perfdata}->threshold_check(value => $result->{"java.lang:type=OperatingSystem"}->{ProcessCpuLoad} * 100, - threshold => [ { label => 'critical-process', exit_litteral => 'critical' }, { label => 'warning-process', exit_litteral => 'warning'} ]); - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("ProcessCpuLoad: %.2f%%", - $result->{"java.lang:type=OperatingSystem"}->{ProcessCpuLoad} * 100)); - - $self->{output}->perfdata_add(label => 'SystemCpuLoad', unit => '%', - value => sprintf("%.2f", $result->{"java.lang:type=OperatingSystem"}->{SystemCpuLoad} * 100), - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-system'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-system'), - min => 0, max => 100); - - $self->{output}->perfdata_add(label => 'ProcessCpuLoad', unit => '%', - value => sprintf("%.2f", $result->{"java.lang:type=OperatingSystem"}->{ProcessCpuLoad} * 100), - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-process'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-process'), - min => 0, max => 100); - - $self->{output}->display(); - $self->{output}->exit(); + my $result = $options{custom}->get_attributes(request => $self->{request}, nothing_quit => 1); + $self->{global} = { + system_load => $result->{'java.lang:type=OperatingSystem'}->{SystemCpuLoad} * 100, + process_load => $result->{'java.lang:type=OperatingSystem'}->{ProcessCpuLoad} * 100 + }; } 1; @@ -133,4 +111,3 @@ Threshold critical of Process cpuload =back =cut - diff --git a/centreon-plugins/centreon/common/jvm/mode/fdusage.pm b/centreon-plugins/centreon/common/jvm/mode/fdusage.pm index 55b5382d5..0f8ad6c71 100644 --- a/centreon-plugins/centreon/common/jvm/mode/fdusage.pm +++ b/centreon-plugins/centreon/common/jvm/mode/fdusage.pm @@ -20,62 +20,82 @@ package centreon::common::jvm::mode::fdusage; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; +sub custom_usage_output { + my ($self, %options) = @_; + + return sprintf( + "File descriptor usage total: %s used: %s (%.2f%%) free: %s (%.2f%%)", + $self->{result_values}->{total}, + $self->{result_values}->{used}, $self->{result_values}->{prct_used}, + $self->{result_values}->{free}, $self->{result_values}->{prct_free} + ); +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'usage', nlabel => 'fd.opened.usage.count', set => { + key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ], + closure_custom_output => $self->can('custom_usage_output'), + perfdatas => [ + { template => '%d', min => 0, max => 'total', cast_int => 1 }, + ] + } + }, + { label => 'usage-free', display_ok => 0, nlabel => 'fd.opened.free.count', set => { + key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ], + closure_custom_output => $self->can('custom_usage_output'), + perfdatas => [ + { template => '%d', min => 0, max => 'total', cast_int => 1 } + ] + } + }, + { label => 'usage-prct', display_ok => 0, nlabel => 'fd.opened.usage.percentage', set => { + key_values => [ { name => 'prct_used' }, { name => 'used' }, { name => 'free' }, { name => 'prct_free' }, { name => 'total' } ], + output_template => 'Used : %.2f %%', + perfdatas => [ + { template => '%.2f', min => 0, max => 100, unit => '%' } + ] + } + } + ]; +} + sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $options{options}->add_options(arguments => - { - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, - }); + $options{options}->add_options(arguments => {}); + return $self; } -sub check_options { +sub manage_selection { my ($self, %options) = @_; - $self->SUPER::init(%options); - - if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); - $self->{output}->option_exit(); - } -} - -sub run { - my ($self, %options) = @_; - $self->{connector} = $options{custom}; $self->{request} = [ - { mbean => "java.lang:type=OperatingSystem", attributes => [ { name => 'MaxFileDescriptorCount' }, { name => 'OpenFileDescriptorCount' } ] } + { mbean => 'java.lang:type=OperatingSystem', attributes => [ { name => 'MaxFileDescriptorCount' }, { name => 'OpenFileDescriptorCount' } ] } ]; - my $result = $self->{connector}->get_attributes(request => $self->{request}, nothing_quit => 1); - my $prct_fd = $result->{"java.lang:type=OperatingSystem"}->{OpenFileDescriptorCount} / $result->{"java.lang:type=OperatingSystem"}->{MaxFileDescriptorCount} * 100; - - my $exit = $self->{perfdata}->threshold_check(value => $prct_fd, - threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - - $self->{output}->perfdata_add(label => 'fd', - value => $result->{"java.lang:type=OperatingSystem"}->{OpenFileDescriptorCount}, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $result->{"java.lang:type=OperatingSystem"}->{MaxFileDescriptorCount}, cast_int => 1), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $result->{"java.lang:type=OperatingSystem"}->{MaxFileDescriptorCount}, cast_int => 1), - min => 0, max => $result->{"java.lang:type=OperatingSystem"}->{MaxFileDescriptorCount}); - - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("File descriptor percentage usage: %.2f%%", $prct_fd)); - - $self->{output}->display(); - $self->{output}->exit(); + my $result = $options{custom}->get_attributes(request => $self->{request}, nothing_quit => 1); + + $self->{global} = { + used => $result->{'java.lang:type=OperatingSystem'}->{OpenFileDescriptorCount}, + free => $result->{'java.lang:type=OperatingSystem'}->{MaxFileDescriptorCount} - $result->{'java.lang:type=OperatingSystem'}->{OpenFileDescriptorCount}, + total => $result->{'java.lang:type=OperatingSystem'}->{MaxFileDescriptorCount} + }; + $self->{global}->{prct_used} = $self->{global}->{used} / $self->{global}->{total} * 100; + $self->{global}->{prct_free} = 100 - $self->{global}->{prct_used}; } @@ -92,15 +112,11 @@ perl centreon_plugins.pl --plugin=apps::tomcat::jmx::plugin --custommode=jolokia =over 8 -=item B<--warning> +=item B<--warning-*> B<--critical-*> -Threshold warning percentage concerning fd capacity - -=item B<--critical> - -Threshold critical percentage concerning fd capacity +Thresholds. +Can be: 'usage', 'usage-free', 'usage-prct' (%). =back =cut - diff --git a/centreon-plugins/centreon/common/jvm/mode/gcusage.pm b/centreon-plugins/centreon/common/jvm/mode/gcusage.pm index 391ad99f4..40753e825 100644 --- a/centreon-plugins/centreon/common/jvm/mode/gcusage.pm +++ b/centreon-plugins/centreon/common/jvm/mode/gcusage.pm @@ -26,50 +26,48 @@ use strict; use warnings; use Digest::MD5 qw(md5_hex); -sub set_counters { - my ($self, %options) = @_; - - $self->{maps_counters_type} = [ - { name => 'gc', type => 1, cb_prefix_output => 'prefix_gc_output', message_multiple => 'All garbage collectors are ok' } - ]; - - $self->{maps_counters}->{gc} = [ - { label => 'time', set => { - key_values => [ { name => 'time', diff => 1 }, { name => 'display' } ], - output_template => 'Collection Time : %s ms', - perfdatas => [ - { label => 'time', value => 'time', template => '%s', - unit => 'ms', min => 0, label_extra_instance => 1, instance_use => 'display' }, - ], - } - }, - { label => 'count', set => { - key_values => [ { name => 'count', diff => 1 }, { name => 'display' } ], - output_template => 'Collection Count : %s', - perfdatas => [ - { label => 'count', value => 'count', template => '%s', - min => 0, label_extra_instance => 1, instance_use => 'display' }, - ], - } - }, - ]; -} - sub prefix_gc_output { my ($self, %options) = @_; return "Garbage collector '" . $options{instance_value}->{display} . "' "; } +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'gc', type => 1, cb_prefix_output => 'prefix_gc_output', message_multiple => 'All garbage collectors are ok' } + ]; + + $self->{maps_counters}->{gc} = [ + { label => 'time', nlabel => 'gc.collection.elapsed_time.milliseconds', set => { + key_values => [ { name => 'time', diff => 1 }, { name => 'display' } ], + output_template => 'collection time: %s ms', + perfdatas => [ + { template => '%s', unit => 'ms', min => 0, label_extra_instance => 1, instance_use => 'display' } + ] + } + }, + { label => 'count', nlabel => 'gc.collection.count', set => { + key_values => [ { name => 'count', diff => 1 }, { name => 'display' } ], + output_template => 'collection count: %s', + perfdatas => [ + { template => '%s', min => 0, label_extra_instance => 1, instance_use => 'display' } + ] + } + } + ]; +} + sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); bless $self, $class; - $options{options}->add_options(arguments => - { - "filter-name:s" => { name => 'filter_name' }, - }); + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' } + }); + return $self; } @@ -95,11 +93,11 @@ sub manage_selection { } if (scalar(keys %{$self->{gc}}) <= 0) { - $self->{output}->add_option_msg(short_msg => "No garbage collector found."); + $self->{output}->add_option_msg(short_msg => 'No garbage collector found.'); $self->{output}->option_exit(); } - $self->{cache_name} = "jvm_standard_" . $self->{mode} . '_' . md5_hex($options{custom}->get_connection_info()) . '_' . + $self->{cache_name} = 'jvm_standard_' . $self->{mode} . '_' . md5_hex($options{custom}->get_connection_info()) . '_' . (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' . (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')); } diff --git a/centreon-plugins/centreon/common/jvm/mode/loadaverage.pm b/centreon-plugins/centreon/common/jvm/mode/loadaverage.pm index 5253ca261..788817f5b 100644 --- a/centreon-plugins/centreon/common/jvm/mode/loadaverage.pm +++ b/centreon-plugins/centreon/common/jvm/mode/loadaverage.pm @@ -20,69 +20,55 @@ package centreon::common::jvm::mode::loadaverage; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'load1', nlabel => 'system.load.1m.count', set => { + key_values => [ { name => 'load' } ], + output_template => 'System load average: %.2f (1m)', + perfdatas => [ + { template => '%.2f', min => 0 } + ] + } + } + ]; +} + sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $options{options}->add_options(arguments => - { - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, - }); + $options{options}->add_options(arguments => {}); + return $self; } -sub check_options { +sub manage_selection { my ($self, %options) = @_; - $self->SUPER::init(%options); - - if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); - $self->{output}->option_exit(); - } -} - -sub run { - my ($self, %options) = @_; - $self->{connector} = $options{custom}; $self->{request} = [ { mbean => "java.lang:type=OperatingSystem", attributes => [ { name => 'SystemLoadAverage' } ] } ]; - my $result = $self->{connector}->get_attributes(request => $self->{request}, nothing_quit => 1); - my $load = $result->{"java.lang:type=OperatingSystem"}->{SystemLoadAverage}; + my $result = $options{custom}->get_attributes(request => $self->{request}, nothing_quit => 1); + my $load = $result->{'java.lang:type=OperatingSystem'}->{SystemLoadAverage}; if ($load == -1) { - $self->{output}->output_add(severity => 'UNKNOWN', - short_msg => "System load average is not set"); - $self->{output}->display(); - $self->{output}->exit(); + $self->{output}->add_option_msg(short_msg => 'System load average is not set'); + $self->{output}->option_exit(); } - - my $exit = $self->{perfdata}->threshold_check(value => $load, - threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - $self->{output}->perfdata_add(label => 'load', - value => $result->{"java.lang:type=OperatingSystem"}->{SystemLoadAverage}, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0); - - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("System load average: %.2f%%", $load)); - - $self->{output}->display(); - $self->{output}->exit(); + $self->{global} = { load => $load }; } 1; @@ -98,15 +84,14 @@ perl centreon_plugins.pl --plugin=apps::tomcat::jmx::plugin --custommode=jolokia =over 8 -=item B<--warning> +=item B<--warning-load1> Warning threshold for loadaverage -=item B<--critical> +=item B<--critical-load1> Critical threshold for loadaverage =back =cut - diff --git a/centreon-plugins/centreon/common/jvm/mode/memory.pm b/centreon-plugins/centreon/common/jvm/mode/memory.pm index edcafd7a2..656e06ba1 100644 --- a/centreon-plugins/centreon/common/jvm/mode/memory.pm +++ b/centreon-plugins/centreon/common/jvm/mode/memory.pm @@ -25,42 +25,12 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -sub set_counters { - my ($self, %options) = @_; - - $self->{maps_counters_type} = [ - { name => 'heap', type => 0 }, - { name => 'nonheap', type => 0 }, - ]; - - $self->{maps_counters}->{heap} = [ - { label => 'heap', set => { - key_values => [ { name => 'used' }, { name => 'max' }, { name => 'label' } ], - closure_custom_calc => $self->can('custom_usage_calc'), - closure_custom_output => $self->can('custom_usage_output'), - closure_custom_perfdata => $self->can('custom_usage_perfdata'), - closure_custom_threshold_check => $self->can('custom_usage_threshold'), - } - }, - ]; - $self->{maps_counters}->{nonheap} = [ - { label => 'nonheap', set => { - key_values => [ { name => 'used' }, { name => 'max' }, { name => 'label' } ], - closure_custom_calc => $self->can('custom_usage_calc'), - closure_custom_output => $self->can('custom_usage_output'), - closure_custom_perfdata => $self->can('custom_usage_perfdata'), - closure_custom_threshold_check => $self->can('custom_usage_threshold'), - } - }, - ]; -} - sub custom_usage_perfdata { my ($self, %options) = @_; my $use_th = 1; $use_th = 0 if ($self->{instance_mode}->{option_results}->{units} eq '%' && $self->{result_values}->{max} <= 0); - + my $value_perf = $self->{result_values}->{used}; my %total_options = (); if ($self->{instance_mode}->{option_results}->{units} eq '%' && $self->{result_values}->{max} > 0) { @@ -68,16 +38,19 @@ sub custom_usage_perfdata { $total_options{cast_int} = 1; } - $self->{output}->perfdata_add(label => $self->{result_values}->{label}, unit => 'B', - value => $value_perf, - warning => $use_th == 1 ? $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options) : undef, - critical => $use_th == 1 ? $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options) : undef, - min => 0, max => $self->{result_values}->{max} > 0 ? $self->{result_values}->{max} : undef); + $self->{output}->perfdata_add( + nlabel => $self->{nlabel}, + unit => 'B', + value => $value_perf, + warning => $use_th == 1 ? $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, %total_options) : undef, + critical => $use_th == 1 ? $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}, %total_options) : undef, + min => 0, max => $self->{result_values}->{max} > 0 ? $self->{result_values}->{max} : undef + ); } sub custom_usage_threshold { my ($self, %options) = @_; - + # Cannot use percent without total return 'ok' if ($self->{result_values}->{max} <= 0 && $self->{instance_mode}->{option_results}->{units} eq '%'); my ($exit, $threshold_value); @@ -85,7 +58,12 @@ sub custom_usage_threshold { if ($self->{instance_mode}->{option_results}->{units} eq '%') { $threshold_value = $self->{result_values}->{prct_used}; } - $exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]); + $exit = $self->{perfdata}->threshold_check( + value => $threshold_value, threshold => [ + { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, + { label => 'warning-'. $self->{thlabel}, exit_litteral => 'warning' } + ] + ); return $exit; } @@ -97,14 +75,20 @@ sub custom_usage_output { if ($self->{result_values}->{max} > 0) { my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{max}); my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{max} - $self->{result_values}->{used}); - $msg = sprintf("%s Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", $self->{result_values}->{label}, - $total_size_value . " " . $total_size_unit, - $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, - $total_free_value . " " . $total_free_unit, 100 - $self->{result_values}->{prct_used}); + $msg = sprintf( + "%s Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", $self->{result_values}->{label}, + $total_size_value . " " . $total_size_unit, + $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, + $total_free_value . " " . $total_free_unit, 100 - $self->{result_values}->{prct_used} + ); } else { - $msg = sprintf("%s Used: %s", $self->{result_values}->{label}, - $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}); + $msg = sprintf( + "%s Used: %s", + $self->{result_values}->{label}, + $total_used_value . " " . $total_used_unit + ); } + return $msg; } @@ -114,7 +98,7 @@ sub custom_usage_calc { $self->{result_values}->{label} = $options{new_datas}->{$self->{label} . '_label'}; $self->{result_values}->{max} = $options{new_datas}->{$self->{instance} . '_max'}; $self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_used'}; - + if ($self->{result_values}->{max} > 0) { $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{max}; } @@ -122,13 +106,44 @@ sub custom_usage_calc { return 0; } +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'heap', type => 0 }, + { name => 'nonheap', type => 0 } + ]; + + $self->{maps_counters}->{heap} = [ + { label => 'heap', nlabel => 'memory.heap.usage.bytes', set => { + key_values => [ { name => 'used' }, { name => 'max' }, { name => 'label' } ], + closure_custom_calc => $self->can('custom_usage_calc'), + closure_custom_output => $self->can('custom_usage_output'), + closure_custom_perfdata => $self->can('custom_usage_perfdata'), + closure_custom_threshold_check => $self->can('custom_usage_threshold') + } + }, + ]; + + $self->{maps_counters}->{nonheap} = [ + { label => 'nonheap', nlabel => 'memory.nonheap.usage.bytes', set => { + key_values => [ { name => 'used' }, { name => 'max' }, { name => 'label' } ], + closure_custom_calc => $self->can('custom_usage_calc'), + closure_custom_output => $self->can('custom_usage_output'), + closure_custom_perfdata => $self->can('custom_usage_perfdata'), + closure_custom_threshold_check => $self->can('custom_usage_threshold') + } + } + ]; +} + sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - + $options{options}->add_options(arguments => { - "units:s" => { name => 'units', default => '%' }, + 'units:s' => { name => 'units', default => '%' } }); return $self; @@ -138,13 +153,13 @@ sub manage_selection { my ($self, %options) = @_; $self->{request} = [ - { mbean => "java.lang:type=Memory" } + { mbean => 'java.lang:type=Memory' } ]; my $result = $options{custom}->get_attributes(request => $self->{request}, nothing_quit => 1); - $self->{heap} = { label => 'HeapMemory', used => $result->{"java.lang:type=Memory"}->{HeapMemoryUsage}->{used}, max => $result->{"java.lang:type=Memory"}->{HeapMemoryUsage}->{max} }; - $self->{nonheap} = { label => 'NonHeapMemoryUsage', used => $result->{"java.lang:type=Memory"}->{NonHeapMemoryUsage}->{used}, max => $result->{"java.lang:type=Memory"}->{NonHeapMemoryUsage}->{max} }; + $self->{heap} = { label => 'HeapMemory', used => $result->{'java.lang:type=Memory'}->{HeapMemoryUsage}->{used}, max => $result->{'java.lang:type=Memory'}->{HeapMemoryUsage}->{max} }; + $self->{nonheap} = { label => 'NonHeapMemoryUsage', used => $result->{'java.lang:type=Memory'}->{NonHeapMemoryUsage}->{used}, max => $result->{'java.lang:type=Memory'}->{NonHeapMemoryUsage}->{max} }; } 1; @@ -183,4 +198,3 @@ Units of thresholds (Default: '%') ('%', 'B'). =back =cut - diff --git a/centreon-plugins/centreon/common/jvm/mode/memorydetailed.pm b/centreon-plugins/centreon/common/jvm/mode/memorydetailed.pm index 789369355..7e151aeb8 100644 --- a/centreon-plugins/centreon/common/jvm/mode/memorydetailed.pm +++ b/centreon-plugins/centreon/common/jvm/mode/memorydetailed.pm @@ -41,60 +41,9 @@ my %mapping_memory = ( 'JIT Code Cache' => 'code', 'CMS Old Gen' => 'tenured', 'PS Old Gen' => 'tenured', - 'Tenured Gen' => 'tenured', + 'Tenured Gen' => 'tenured' ); -sub set_counters { - my ($self, %options) = @_; - - $self->{maps_counters_type} = [ - { name => 'mem', type => 1, cb_prefix_output => 'prefix_mem_output', message_multiple => 'All memories within bounds', skipped_code => { -12 => 1 } }, - ]; - - $self->{maps_counters}->{mem} = [ - { label => 'eden', set => { - key_values => [ { name => 'used' }, { name => 'max' }, { name => 'display' } ], - closure_custom_calc => $self->can('custom_usage_calc'), - closure_custom_output => $self->can('custom_usage_output'), - closure_custom_threshold_check => $self->can('custom_usage_threshold'), - closure_custom_perfdata => $self->can('custom_usage_perfdata'), - } - }, - { label => 'tenured', set => { - key_values => [ { name => 'used' }, { name => 'max' }, { name => 'display' } ], - closure_custom_calc => $self->can('custom_usage_calc'), - closure_custom_output => $self->can('custom_usage_output'), - closure_custom_threshold_check => $self->can('custom_usage_threshold'), - closure_custom_perfdata => $self->can('custom_usage_perfdata'), - } - }, - { label => 'survivor', set => { - key_values => [ { name => 'used' }, { name => 'max' }, { name => 'display' } ], - closure_custom_calc => $self->can('custom_usage_calc'), - closure_custom_output => $self->can('custom_usage_output'), - closure_custom_threshold_check => $self->can('custom_usage_threshold'), - closure_custom_perfdata => $self->can('custom_usage_perfdata'), - } - }, - { label => 'permanent', set => { - key_values => [ { name => 'used' }, { name => 'max' }, { name => 'display' } ], - closure_custom_calc => $self->can('custom_usage_calc'), - closure_custom_output => $self->can('custom_usage_output'), - closure_custom_threshold_check => $self->can('custom_usage_threshold'), - closure_custom_perfdata => $self->can('custom_usage_perfdata'), - } - }, - { label => 'code', set => { - key_values => [ { name => 'used' }, { name => 'max' }, { name => 'display' } ], - closure_custom_calc => $self->can('custom_usage_calc'), - closure_custom_output => $self->can('custom_usage_output'), - closure_custom_threshold_check => $self->can('custom_usage_threshold'), - closure_custom_perfdata => $self->can('custom_usage_perfdata'), - } - }, - ]; -} - sub custom_usage_perfdata { my ($self, %options) = @_; @@ -108,16 +57,19 @@ sub custom_usage_perfdata { $total_options{cast_int} = 1; } - $self->{output}->perfdata_add(label => $self->{label}, unit => 'B', - value => $value_perf, - warning => $use_th == 1 ? $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options) : undef, - critical => $use_th == 1 ? $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options) : undef, - min => 0, max => $self->{result_values}->{max} > 0 ? $self->{result_values}->{max} : undef); + $self->{output}->perfdata_add( + nlabel => $self->{nlabel}, + unit => 'B', + value => $value_perf, + warning => $use_th == 1 ? $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, %total_options) : undef, + critical => $use_th == 1 ? $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}, %total_options) : undef, + min => 0, max => $self->{result_values}->{max} > 0 ? $self->{result_values}->{max} : undef + ); } sub custom_usage_threshold { my ($self, %options) = @_; - + # Cannot use percent without total return 'ok' if ($self->{result_values}->{max} <= 0 && $self->{instance_mode}->{option_results}->{units} eq '%'); my ($exit, $threshold_value); @@ -125,7 +77,12 @@ sub custom_usage_threshold { if ($self->{instance_mode}->{option_results}->{units} eq '%') { $threshold_value = $self->{result_values}->{prct_used}; } - $exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]); + $exit = $self->{perfdata}->threshold_check( + value => $threshold_value, threshold => [ + { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, + { label => 'warning-'. $self->{thlabel}, exit_litteral => 'warning' } + ] + ); return $exit; } @@ -137,10 +94,12 @@ sub custom_usage_output { if ($self->{result_values}->{max} > 0) { my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{max}); my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{max} - $self->{result_values}->{used}); - $msg = sprintf("Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", - $total_size_value . " " . $total_size_unit, - $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, - $total_free_value . " " . $total_free_unit, 100 - $self->{result_values}->{prct_used}); + $msg = sprintf( + "Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", + $total_size_value . " " . $total_size_unit, + $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, + $total_free_value . " " . $total_free_unit, 100 - $self->{result_values}->{prct_used} + ); } else { $msg = sprintf("Used: %s", $total_used_value . " " . $total_used_unit); } @@ -169,13 +128,64 @@ sub prefix_mem_output { return "Memory '" . $options{instance_value}->{display} . "' "; } +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'mem', type => 1, cb_prefix_output => 'prefix_mem_output', message_multiple => 'All memories within bounds', skipped_code => { -12 => 1 } } + ]; + + $self->{maps_counters}->{mem} = [ + { label => 'eden', nlabel => 'memory.eden.usage.bytes', set => { + key_values => [ { name => 'used' }, { name => 'max' }, { name => 'display' } ], + closure_custom_calc => $self->can('custom_usage_calc'), + closure_custom_output => $self->can('custom_usage_output'), + closure_custom_threshold_check => $self->can('custom_usage_threshold'), + closure_custom_perfdata => $self->can('custom_usage_perfdata') + } + }, + { label => 'tenured', nlabel => 'memory.tenured.usage.bytes', set => { + key_values => [ { name => 'used' }, { name => 'max' }, { name => 'display' } ], + closure_custom_calc => $self->can('custom_usage_calc'), + closure_custom_output => $self->can('custom_usage_output'), + closure_custom_threshold_check => $self->can('custom_usage_threshold'), + closure_custom_perfdata => $self->can('custom_usage_perfdata') + } + }, + { label => 'survivor', nlabel => 'memory.survivor.usage.bytes', set => { + key_values => [ { name => 'used' }, { name => 'max' }, { name => 'display' } ], + closure_custom_calc => $self->can('custom_usage_calc'), + closure_custom_output => $self->can('custom_usage_output'), + closure_custom_threshold_check => $self->can('custom_usage_threshold'), + closure_custom_perfdata => $self->can('custom_usage_perfdata') + } + }, + { label => 'permanent', nlabel => 'memory.permanent.usage.bytes', set => { + key_values => [ { name => 'used' }, { name => 'max' }, { name => 'display' } ], + closure_custom_calc => $self->can('custom_usage_calc'), + closure_custom_output => $self->can('custom_usage_output'), + closure_custom_threshold_check => $self->can('custom_usage_threshold'), + closure_custom_perfdata => $self->can('custom_usage_perfdata') + } + }, + { label => 'code', nlabel => 'memory.code.usage.bytes', set => { + key_values => [ { name => 'used' }, { name => 'max' }, { name => 'display' } ], + closure_custom_calc => $self->can('custom_usage_calc'), + closure_custom_output => $self->can('custom_usage_output'), + closure_custom_threshold_check => $self->can('custom_usage_threshold'), + closure_custom_perfdata => $self->can('custom_usage_perfdata') + } + } + ]; +} + sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; $options{options}->add_options(arguments => { - "units:s" => { name => 'units', default => '%' }, + 'units:s' => { name => 'units', default => '%' } }); return $self; @@ -185,25 +195,25 @@ sub manage_selection { my ($self, %options) = @_; $self->{request} = [ - { mbean => "java.lang:type=MemoryPool,name=*", attributes => [ { name => 'Usage' } ] } + { mbean => 'java.lang:type=MemoryPool,name=*', attributes => [ { name => 'Usage' } ] } ]; - + my $result = $options{custom}->get_attributes(request => $self->{request}, nothing_quit => 1); $self->{mem} = {}; foreach my $key (keys %$result) { $key =~ /(?:[:,])name=(.*?)(?:,|$)/; my $memtype = $1; - + if (!defined($mapping_memory{$memtype})) { $self->{output}->output_add(long_msg => "unknown memory type: " . $memtype, debug => 1); next; } - + $self->{mem}->{$memtype} = { display => $memtype, - used => $result->{"java.lang:name=" . $memtype . ",type=MemoryPool"}->{Usage}->{used}, - max => $result->{"java.lang:name=".$memtype.",type=MemoryPool"}->{Usage}->{max}, + used => $result->{'java.lang:name=' . $memtype . ',type=MemoryPool'}->{Usage}->{used}, + max => $result->{'java.lang:name=' . $memtype . ',type=MemoryPool'}->{Usage}->{max} }; } } diff --git a/centreon-plugins/centreon/common/jvm/mode/threads.pm b/centreon-plugins/centreon/common/jvm/mode/threads.pm index 7c69a00e3..4a7e57f3d 100644 --- a/centreon-plugins/centreon/common/jvm/mode/threads.pm +++ b/centreon-plugins/centreon/common/jvm/mode/threads.pm @@ -26,56 +26,54 @@ use strict; use warnings; use Digest::MD5 qw(md5_hex); +sub prefix_global_output { + my ($self, %options) = @_; + + return 'Threads '; +} + sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output', skipped_code => { -10 => 1 } }, + { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output', skipped_code => { -10 => 1 } } ]; $self->{maps_counters}->{global} = [ - { label => 'active', set => { + { label => 'active', nlabel => 'threads.active.count', set => { key_values => [ { name => 'ThreadCount' } ], - output_template => 'Active : %s', + output_template => 'active: %s', perfdatas => [ - { label => 'active', value => 'ThreadCount', template => '%s', min => 0 }, - ], + { template => '%s', min => 0 } + ] } }, - { label => 'started', set => { + { label => 'started', nlabel => 'threads.started.count', set => { key_values => [ { name => 'TotalStartedThreadCount', diff => 1 } ], - output_template => 'Started : %s', + output_template => 'started: %s', perfdatas => [ - { label => 'started', value => 'TotalStartedThreadCount', template => '%s', min => 0 }, - ], + { template => '%s', min => 0 } + ] } }, - { label => 'daemon', set => { + { label => 'daemon', nlabel => 'threads.daemon.count', set => { key_values => [ { name => 'DaemonThreadCount' } ], - output_template => 'Daemon : %s', + output_template => 'daemon: %s', perfdatas => [ - { label => 'daemon', value => 'DaemonThreadCount', template => '%s', min => 0 }, - ], + { template => '%s', min => 0 } + ] } - }, + } ]; } -sub prefix_global_output { - my ($self, %options) = @_; - - return "Threads "; -} - sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); bless $self, $class; - - $options{options}->add_options(arguments => - { - }); - + + $options{options}->add_options(arguments => { }); + return $self; } @@ -88,9 +86,9 @@ sub manage_selection { ]; my $result = $options{custom}->get_attributes(request => $request, nothing_quit => 1); - $self->{global} = { %{$result->{$mbean}} }; - - $self->{cache_name} = "jvm_standard_" . $self->{mode} . '_' . md5_hex($options{custom}->get_connection_info()) . '_' . + $self->{global} = $result->{$mbean}; + + $self->{cache_name} = 'jvm_standard_' . $self->{mode} . '_' . md5_hex($options{custom}->get_connection_info()) . '_' . (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); }