break(jvm/jmx): force metric v2 - tomcat/jboss/weblogic (#3011)

This commit is contained in:
qgarnier 2021-08-03 14:17:40 +02:00 committed by GitHub
parent 4fafc965e1
commit f2c19ee6d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 371 additions and 380 deletions

View File

@ -26,55 +26,53 @@ use strict;
use warnings; use warnings;
use Digest::MD5 qw(md5_hex); use Digest::MD5 qw(md5_hex);
sub prefix_global_output {
my ($self, %options) = @_;
return 'Class ';
}
sub set_counters { sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{maps_counters_type} = [ $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} = [ $self->{maps_counters}->{global} = [
{ label => 'current', set => { { label => 'current', nlabel => 'class.loaded.current.count', set => {
key_values => [ { name => 'LoadedClassCount' } ], key_values => [ { name => 'LoadedClassCount' } ],
output_template => 'Current : %s', output_template => 'current: %s',
perfdatas => [ 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 } ], key_values => [ { name => 'TotalLoadedClassCount', diff => 1 } ],
output_template => 'Loaded : %s', output_template => 'loaded: %s',
perfdatas => [ 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 } ], key_values => [ { name => 'UnloadedClassCount', diff => 1 } ],
output_template => 'Unloaded : %s', output_template => 'unloaded: %s',
perfdatas => [ perfdatas => [
{ label => 'unloaded', value => 'UnloadedClassCount', template => '%s', min => 0 }, { template => '%s', min => 0 }
], ]
}
} }
},
]; ];
} }
sub prefix_global_output {
my ($self, %options) = @_;
return "Class ";
}
sub new { sub new {
my ($class, %options) = @_; 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; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {});
{
});
return $self; return $self;
} }
@ -88,9 +86,9 @@ sub manage_selection {
]; ];
my $result = $options{custom}->get_attributes(request => $request, nothing_quit => 1); my $result = $options{custom}->get_attributes(request => $request, nothing_quit => 1);
$self->{global} = { %{$result->{$mbean}} }; $self->{global} = $result->{$mbean};
$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_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). Only display some counters (regexp can be used).
Example: --filter-counters='current' Example: --filter-counters='current'
=item B<--warning-*> =item B<--warning-*> B<--critical-*>
Threshold warning. Thresholds.
Can be: 'unloaded', 'loaded', 'current'.
=item B<--critical-*>
Threshold critical.
Can be: 'unloaded', 'loaded', 'current'. Can be: 'unloaded', 'loaded', 'current'.
=back =back

View File

@ -20,84 +20,62 @@
package centreon::common::jvm::mode::cpuload; package centreon::common::jvm::mode::cpuload;
use base qw(centreon::plugins::mode); use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; 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 { sub new {
my ($class, %options) = @_; 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; bless $self, $class;
$options{options}->add_options(arguments => $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' }
});
return $self; return $self;
} }
sub check_options { sub manage_selection {
my ($self, %options) = @_; 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} = [ $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 $result = $options{custom}->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();
$self->{global} = {
system_load => $result->{'java.lang:type=OperatingSystem'}->{SystemCpuLoad} * 100,
process_load => $result->{'java.lang:type=OperatingSystem'}->{ProcessCpuLoad} * 100
};
} }
1; 1;
@ -133,4 +111,3 @@ Threshold critical of Process cpuload
=back =back
=cut =cut

View File

@ -20,62 +20,82 @@
package centreon::common::jvm::mode::fdusage; package centreon::common::jvm::mode::fdusage;
use base qw(centreon::plugins::mode); use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; 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 { sub new {
my ($class, %options) = @_; 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; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {});
{
"warning:s" => { name => 'warning' },
"critical:s" => { name => 'critical' },
});
return $self; return $self;
} }
sub check_options { sub manage_selection {
my ($self, %options) = @_; 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} = [ $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 $result = $options{custom}->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, $self->{global} = {
threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); used => $result->{'java.lang:type=OperatingSystem'}->{OpenFileDescriptorCount},
free => $result->{'java.lang:type=OperatingSystem'}->{MaxFileDescriptorCount} - $result->{'java.lang:type=OperatingSystem'}->{OpenFileDescriptorCount},
$self->{output}->perfdata_add(label => 'fd', total => $result->{'java.lang:type=OperatingSystem'}->{MaxFileDescriptorCount}
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), $self->{global}->{prct_used} = $self->{global}->{used} / $self->{global}->{total} * 100;
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $result->{"java.lang:type=OperatingSystem"}->{MaxFileDescriptorCount}, cast_int => 1), $self->{global}->{prct_free} = 100 - $self->{global}->{prct_used};
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();
} }
@ -92,15 +112,11 @@ perl centreon_plugins.pl --plugin=apps::tomcat::jmx::plugin --custommode=jolokia
=over 8 =over 8
=item B<--warning> =item B<--warning-*> B<--critical-*>
Threshold warning percentage concerning fd capacity Thresholds.
Can be: 'usage', 'usage-free', 'usage-prct' (%).
=item B<--critical>
Threshold critical percentage concerning fd capacity
=back =back
=cut =cut

View File

@ -26,6 +26,12 @@ use strict;
use warnings; use warnings;
use Digest::MD5 qw(md5_hex); use Digest::MD5 qw(md5_hex);
sub prefix_gc_output {
my ($self, %options) = @_;
return "Garbage collector '" . $options{instance_value}->{display} . "' ";
}
sub set_counters { sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
@ -34,42 +40,34 @@ sub set_counters {
]; ];
$self->{maps_counters}->{gc} = [ $self->{maps_counters}->{gc} = [
{ label => 'time', set => { { label => 'time', nlabel => 'gc.collection.elapsed_time.milliseconds', set => {
key_values => [ { name => 'time', diff => 1 }, { name => 'display' } ], key_values => [ { name => 'time', diff => 1 }, { name => 'display' } ],
output_template => 'Collection Time : %s ms', output_template => 'collection time: %s ms',
perfdatas => [ perfdatas => [
{ label => 'time', value => 'time', template => '%s', { template => '%s', unit => 'ms', min => 0, label_extra_instance => 1, instance_use => 'display' }
unit => 'ms', min => 0, label_extra_instance => 1, instance_use => 'display' }, ]
],
} }
}, },
{ label => 'count', set => { { label => 'count', nlabel => 'gc.collection.count', set => {
key_values => [ { name => 'count', diff => 1 }, { name => 'display' } ], key_values => [ { name => 'count', diff => 1 }, { name => 'display' } ],
output_template => 'Collection Count : %s', output_template => 'collection count: %s',
perfdatas => [ perfdatas => [
{ label => 'count', value => 'count', template => '%s', { template => '%s', min => 0, label_extra_instance => 1, instance_use => 'display' }
min => 0, label_extra_instance => 1, instance_use => 'display' }, ]
], }
} }
},
]; ];
} }
sub prefix_gc_output {
my ($self, %options) = @_;
return "Garbage collector '" . $options{instance_value}->{display} . "' ";
}
sub new { sub new {
my ($class, %options) = @_; 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; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{ 'filter-name:s' => { name => 'filter_name' }
"filter-name:s" => { name => 'filter_name' },
}); });
return $self; return $self;
} }
@ -95,11 +93,11 @@ sub manage_selection {
} }
if (scalar(keys %{$self->{gc}}) <= 0) { 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->{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_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')); (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all'));
} }

View File

@ -20,69 +20,55 @@
package centreon::common::jvm::mode::loadaverage; package centreon::common::jvm::mode::loadaverage;
use base qw(centreon::plugins::mode); use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; 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 { sub new {
my ($class, %options) = @_; 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; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {});
{
"warning:s" => { name => 'warning' },
"critical:s" => { name => 'critical' },
});
return $self; return $self;
} }
sub check_options { sub manage_selection {
my ($self, %options) = @_; 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} = [ $self->{request} = [
{ mbean => "java.lang:type=OperatingSystem", attributes => [ { name => 'SystemLoadAverage' } ] } { mbean => "java.lang:type=OperatingSystem", attributes => [ { name => 'SystemLoadAverage' } ] }
]; ];
my $result = $self->{connector}->get_attributes(request => $self->{request}, nothing_quit => 1); my $result = $options{custom}->get_attributes(request => $self->{request}, nothing_quit => 1);
my $load = $result->{"java.lang:type=OperatingSystem"}->{SystemLoadAverage}; my $load = $result->{'java.lang:type=OperatingSystem'}->{SystemLoadAverage};
if ($load == -1) { if ($load == -1) {
$self->{output}->output_add(severity => 'UNKNOWN', $self->{output}->add_option_msg(short_msg => 'System load average is not set');
short_msg => "System load average is not set"); $self->{output}->option_exit();
$self->{output}->display();
$self->{output}->exit();
} }
my $exit = $self->{perfdata}->threshold_check(value => $load, $self->{global} = { load => $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();
} }
1; 1;
@ -98,15 +84,14 @@ perl centreon_plugins.pl --plugin=apps::tomcat::jmx::plugin --custommode=jolokia
=over 8 =over 8
=item B<--warning> =item B<--warning-load1>
Warning threshold for loadaverage Warning threshold for loadaverage
=item B<--critical> =item B<--critical-load1>
Critical threshold for loadaverage Critical threshold for loadaverage
=back =back
=cut =cut

View File

@ -25,36 +25,6 @@ use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; 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 { sub custom_usage_perfdata {
my ($self, %options) = @_; my ($self, %options) = @_;
@ -68,11 +38,14 @@ sub custom_usage_perfdata {
$total_options{cast_int} = 1; $total_options{cast_int} = 1;
} }
$self->{output}->perfdata_add(label => $self->{result_values}->{label}, unit => 'B', $self->{output}->perfdata_add(
nlabel => $self->{nlabel},
unit => 'B',
value => $value_perf, value => $value_perf,
warning => $use_th == 1 ? $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options) : undef, 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->{label}, %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); min => 0, max => $self->{result_values}->{max} > 0 ? $self->{result_values}->{max} : undef
);
} }
sub custom_usage_threshold { sub custom_usage_threshold {
@ -85,7 +58,12 @@ sub custom_usage_threshold {
if ($self->{instance_mode}->{option_results}->{units} eq '%') { if ($self->{instance_mode}->{option_results}->{units} eq '%') {
$threshold_value = $self->{result_values}->{prct_used}; $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; return $exit;
} }
@ -97,14 +75,20 @@ sub custom_usage_output {
if ($self->{result_values}->{max} > 0) { if ($self->{result_values}->{max} > 0) {
my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{max}); 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}); 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}, $msg = sprintf(
"%s Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", $self->{result_values}->{label},
$total_size_value . " " . $total_size_unit, $total_size_value . " " . $total_size_unit,
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
$total_free_value . " " . $total_free_unit, 100 - $self->{result_values}->{prct_used}); $total_free_value . " " . $total_free_unit, 100 - $self->{result_values}->{prct_used}
);
} else { } else {
$msg = sprintf("%s Used: %s", $self->{result_values}->{label}, $msg = sprintf(
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}); "%s Used: %s",
$self->{result_values}->{label},
$total_used_value . " " . $total_used_unit
);
} }
return $msg; return $msg;
} }
@ -122,13 +106,44 @@ sub custom_usage_calc {
return 0; 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 { sub new {
my ($class, %options) = @_; 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; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
"units:s" => { name => 'units', default => '%' }, 'units:s' => { name => 'units', default => '%' }
}); });
return $self; return $self;
@ -138,13 +153,13 @@ sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{request} = [ $self->{request} = [
{ mbean => "java.lang:type=Memory" } { mbean => 'java.lang:type=Memory' }
]; ];
my $result = $options{custom}->get_attributes(request => $self->{request}, nothing_quit => 1); 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->{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->{nonheap} = { label => 'NonHeapMemoryUsage', used => $result->{'java.lang:type=Memory'}->{NonHeapMemoryUsage}->{used}, max => $result->{'java.lang:type=Memory'}->{NonHeapMemoryUsage}->{max} };
} }
1; 1;
@ -183,4 +198,3 @@ Units of thresholds (Default: '%') ('%', 'B').
=back =back
=cut =cut

View File

@ -41,60 +41,9 @@ my %mapping_memory = (
'JIT Code Cache' => 'code', 'JIT Code Cache' => 'code',
'CMS Old Gen' => 'tenured', 'CMS Old Gen' => 'tenured',
'PS 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 { sub custom_usage_perfdata {
my ($self, %options) = @_; my ($self, %options) = @_;
@ -108,11 +57,14 @@ sub custom_usage_perfdata {
$total_options{cast_int} = 1; $total_options{cast_int} = 1;
} }
$self->{output}->perfdata_add(label => $self->{label}, unit => 'B', $self->{output}->perfdata_add(
nlabel => $self->{nlabel},
unit => 'B',
value => $value_perf, value => $value_perf,
warning => $use_th == 1 ? $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options) : undef, 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->{label}, %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); min => 0, max => $self->{result_values}->{max} > 0 ? $self->{result_values}->{max} : undef
);
} }
sub custom_usage_threshold { sub custom_usage_threshold {
@ -125,7 +77,12 @@ sub custom_usage_threshold {
if ($self->{instance_mode}->{option_results}->{units} eq '%') { if ($self->{instance_mode}->{option_results}->{units} eq '%') {
$threshold_value = $self->{result_values}->{prct_used}; $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; return $exit;
} }
@ -137,10 +94,12 @@ sub custom_usage_output {
if ($self->{result_values}->{max} > 0) { if ($self->{result_values}->{max} > 0) {
my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{max}); 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}); 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%%)", $msg = sprintf(
"Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
$total_size_value . " " . $total_size_unit, $total_size_value . " " . $total_size_unit,
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
$total_free_value . " " . $total_free_unit, 100 - $self->{result_values}->{prct_used}); $total_free_value . " " . $total_free_unit, 100 - $self->{result_values}->{prct_used}
);
} else { } else {
$msg = sprintf("Used: %s", $total_used_value . " " . $total_used_unit); $msg = sprintf("Used: %s", $total_used_value . " " . $total_used_unit);
} }
@ -169,13 +128,64 @@ sub prefix_mem_output {
return "Memory '" . $options{instance_value}->{display} . "' "; 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 { sub new {
my ($class, %options) = @_; 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; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
"units:s" => { name => 'units', default => '%' }, 'units:s' => { name => 'units', default => '%' }
}); });
return $self; return $self;
@ -185,7 +195,7 @@ sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{request} = [ $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); my $result = $options{custom}->get_attributes(request => $self->{request}, nothing_quit => 1);
@ -202,8 +212,8 @@ sub manage_selection {
$self->{mem}->{$memtype} = { $self->{mem}->{$memtype} = {
display => $memtype, display => $memtype,
used => $result->{"java.lang:name=" . $memtype . ",type=MemoryPool"}->{Usage}->{used}, used => $result->{'java.lang:name=' . $memtype . ',type=MemoryPool'}->{Usage}->{used},
max => $result->{"java.lang:name=".$memtype.",type=MemoryPool"}->{Usage}->{max}, max => $result->{'java.lang:name=' . $memtype . ',type=MemoryPool'}->{Usage}->{max}
}; };
} }
} }

View File

@ -26,55 +26,53 @@ use strict;
use warnings; use warnings;
use Digest::MD5 qw(md5_hex); use Digest::MD5 qw(md5_hex);
sub prefix_global_output {
my ($self, %options) = @_;
return 'Threads ';
}
sub set_counters { sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{maps_counters_type} = [ $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} = [ $self->{maps_counters}->{global} = [
{ label => 'active', set => { { label => 'active', nlabel => 'threads.active.count', set => {
key_values => [ { name => 'ThreadCount' } ], key_values => [ { name => 'ThreadCount' } ],
output_template => 'Active : %s', output_template => 'active: %s',
perfdatas => [ 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 } ], key_values => [ { name => 'TotalStartedThreadCount', diff => 1 } ],
output_template => 'Started : %s', output_template => 'started: %s',
perfdatas => [ 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' } ], key_values => [ { name => 'DaemonThreadCount' } ],
output_template => 'Daemon : %s', output_template => 'daemon: %s',
perfdatas => [ perfdatas => [
{ label => 'daemon', value => 'DaemonThreadCount', template => '%s', min => 0 }, { template => '%s', min => 0 }
], ]
}
} }
},
]; ];
} }
sub prefix_global_output {
my ($self, %options) = @_;
return "Threads ";
}
sub new { sub new {
my ($class, %options) = @_; 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; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => { });
{
});
return $self; return $self;
} }
@ -88,9 +86,9 @@ sub manage_selection {
]; ];
my $result = $options{custom}->get_attributes(request => $request, nothing_quit => 1); my $result = $options{custom}->get_attributes(request => $request, nothing_quit => 1);
$self->{global} = { %{$result->{$mbean}} }; $self->{global} = $result->{$mbean};
$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_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
} }