mirror of
https://github.com/centreon/centreon-plugins.git
synced 2025-07-28 08:04:36 +02:00
+ Fix Class count mode for jmx java
This commit is contained in:
parent
90c968b776
commit
94dfdbda99
@ -1,5 +1,5 @@
|
|||||||
################################################################################
|
################################################################################
|
||||||
# Copyright 2005-2013 MERETHIS
|
# Copyright 2005-2014 MERETHIS
|
||||||
# Centreon is developped by : Julien Mathis and Romain Le Merlus under
|
# Centreon is developped by : Julien Mathis and Romain Le Merlus under
|
||||||
# GPL Licence 2.0.
|
# GPL Licence 2.0.
|
||||||
#
|
#
|
||||||
@ -29,7 +29,7 @@
|
|||||||
# do not wish to do so, delete this exception statement from your version.
|
# do not wish to do so, delete this exception statement from your version.
|
||||||
#
|
#
|
||||||
# For more information : contact@centreon.com
|
# For more information : contact@centreon.com
|
||||||
# Authors : Simon BOMM <sbomm@centreon.com>
|
# Authors : Quentin Garnier <qgarnier@merethis.com>
|
||||||
#
|
#
|
||||||
####################################################################################
|
####################################################################################
|
||||||
|
|
||||||
@ -39,6 +39,37 @@ use base qw(centreon::plugins::mode);
|
|||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
use centreon::plugins::values;
|
||||||
|
use centreon::plugins::statefile;
|
||||||
|
use Digest::MD5 qw(md5_hex);
|
||||||
|
|
||||||
|
my $instance_mode;
|
||||||
|
|
||||||
|
my $maps_counters = {
|
||||||
|
class => {
|
||||||
|
'000_current' => { set => { key_values => [ { name => 'current' } ],
|
||||||
|
output_template => 'Current : %s',
|
||||||
|
perfdatas => [
|
||||||
|
{ label => 'current', value => 'current_absolute', template => '%s', min => 0 },
|
||||||
|
],
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'001_loaded' => { set => { key_values => [ { name => 'loaded', diff => 1 } ],
|
||||||
|
output_template => 'Loaded : %s',
|
||||||
|
perfdatas => [
|
||||||
|
{ label => 'loaded', value => 'loaded_absolute', template => '%s', min => 0 },
|
||||||
|
],
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'003_unloaded' => { set => { key_values => [ { name => 'unloaded', diff => 1 } ],
|
||||||
|
output_template => 'Unloaded : %s',
|
||||||
|
perfdatas => [
|
||||||
|
{ label => 'unloaded', value => 'unloaded_absolute', template => '%s', min => 0 },
|
||||||
|
],
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
my ($class, %options) = @_;
|
my ($class, %options) = @_;
|
||||||
@ -48,11 +79,26 @@ sub new {
|
|||||||
$self->{version} = '1.0';
|
$self->{version} = '1.0';
|
||||||
$options{options}->add_options(arguments =>
|
$options{options}->add_options(arguments =>
|
||||||
{
|
{
|
||||||
"warning-loaded:s" => { name => 'warning_loaded' },
|
|
||||||
"critical-loaded:s" => { name => 'critical_loaded' },
|
|
||||||
"warning-total:s" => { name => 'warning_total' },
|
|
||||||
"critical-total:s" => { name => 'critical_total' },
|
|
||||||
});
|
});
|
||||||
|
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
|
||||||
|
|
||||||
|
foreach my $key (('class')) {
|
||||||
|
foreach (keys %{$maps_counters->{$key}}) {
|
||||||
|
my ($id, $name) = split /_/;
|
||||||
|
if (!defined($maps_counters->{$key}->{$_}->{threshold}) || $maps_counters->{$key}->{$_}->{threshold} != 0) {
|
||||||
|
$options{options}->add_options(arguments => {
|
||||||
|
'warning-' . $name . ':s' => { name => 'warning-' . $name },
|
||||||
|
'critical-' . $name . ':s' => { name => 'critical-' . $name },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
$maps_counters->{$key}->{$_}->{obj} = centreon::plugins::values->new(
|
||||||
|
statefile => $self->{statefile_value},
|
||||||
|
output => $self->{output}, perfdata => $self->{perfdata},
|
||||||
|
label => $name);
|
||||||
|
$maps_counters->{$key}->{$_}->{obj}->set(%{$maps_counters->{$key}->{$_}->{set}});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,66 +106,97 @@ sub check_options {
|
|||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
$self->SUPER::init(%options);
|
$self->SUPER::init(%options);
|
||||||
|
|
||||||
if (($self->{perfdata}->threshold_validate(label => 'warning-loaded', value => $self->{option_results}->{warning_loaded})) == 0) {
|
foreach my $key (('class')) {
|
||||||
$self->{output}->add_option_msg(short_msg => "Wrong warning-loaded threshold '" . $self->{option_results}->{warning_loaded} . "'.");
|
foreach (keys %{$maps_counters->{$key}}) {
|
||||||
|
$maps_counters->{$key}->{$_}->{obj}->init(option_results => $self->{option_results});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$self->{statefile_value}->check_options(%options);
|
||||||
|
$instance_mode = $self;
|
||||||
|
|
||||||
|
$self->{overload_th} = {};
|
||||||
|
foreach my $val (@{$self->{option_results}->{threshold_overload}}) {
|
||||||
|
if ($val !~ /^(.*?),(.*?),(.*)$/) {
|
||||||
|
$self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'.");
|
||||||
$self->{output}->option_exit();
|
$self->{output}->option_exit();
|
||||||
}
|
}
|
||||||
if (($self->{perfdata}->threshold_validate(label => 'critical-loaded', value => $self->{option_results}->{critical_loaded})) == 0) {
|
my ($section, $status, $filter) = ($1, $2, $3);
|
||||||
$self->{output}->add_option_msg(short_msg => "Wrong critical-loaded threshold '" . $self->{option_results}->{critical_loaded} . "'.");
|
if ($self->{output}->is_litteral_status(status => $status) == 0) {
|
||||||
|
$self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'.");
|
||||||
$self->{output}->option_exit();
|
$self->{output}->option_exit();
|
||||||
}
|
}
|
||||||
if (($self->{perfdata}->threshold_validate(label => 'warning-total', value => $self->{option_results}->{warning_total})) == 0) {
|
$self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section}));
|
||||||
$self->{output}->add_option_msg(short_msg => "Wrong warning-total threshold '" . $self->{option_results}->{warning_total} . "'.");
|
push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status};
|
||||||
$self->{output}->option_exit();
|
|
||||||
}
|
|
||||||
if (($self->{perfdata}->threshold_validate(label => 'critical-total', value => $self->{option_results}->{critical_total})) == 0) {
|
|
||||||
$self->{output}->add_option_msg(short_msg => "Wrong critical-total threshold '" . $self->{option_results}->{critical_total} . "'.");
|
|
||||||
$self->{output}->option_exit();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub run {
|
sub run {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
# $options{snmp} = snmp object
|
|
||||||
$self->{connector} = $options{custom};
|
$self->{connector} = $options{custom};
|
||||||
|
|
||||||
$self->{request} = [
|
$self->manage_selection();
|
||||||
{ mbean => "java.lang:type=ClassLoading", attributes => [ { name => 'UnloadedClassCount' }, { name => 'LoadedClassCount' }, { name => 'TotalLoadedClassCount' } ] },
|
|
||||||
];
|
|
||||||
|
|
||||||
my $result = $self->{connector}->get_attributes(request => $self->{request}, nothing_quit => 1);
|
$self->{new_datas} = {};
|
||||||
my $exit1 = $self->{perfdata}->threshold_check(value => $result->{"java.lang:type=ClassLoading"}->{TotalLoadedClassCount},
|
$self->{statefile_value}->read(statefile => "jvm_standard_" . $self->{mode} . '_' . md5_hex($self->{connector}->{url}));
|
||||||
threshold => [ { label => 'critical-total', exit_litteral => 'critical' }, { label => 'warning-total', exit_litteral => 'warning'} ]);
|
$self->{new_datas}->{last_timestamp} = time();
|
||||||
my $exit2 = $self->{perfdata}->threshold_check(value => $result->{"java.lang:type=ClassLoading"}->{LoadedClassCount},
|
|
||||||
threshold => [ { label => 'critical-loaded', exit_litteral => 'critical' }, { label => 'warning-loaded', exit_litteral => 'warning'} ]);
|
|
||||||
|
|
||||||
my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2 ]);
|
my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', '');
|
||||||
|
my @exits;
|
||||||
|
foreach (sort keys %{$maps_counters->{class}}) {
|
||||||
|
my $obj = $maps_counters->{class}->{$_}->{obj};
|
||||||
|
$obj->set(instance => 'global');
|
||||||
|
|
||||||
|
my ($value_check) = $obj->execute(values => $self->{global},
|
||||||
|
new_datas => $self->{new_datas});
|
||||||
|
|
||||||
|
if ($value_check != 0) {
|
||||||
|
$long_msg .= $long_msg_append . $obj->output_error();
|
||||||
|
$long_msg_append = ', ';
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
my $exit2 = $obj->threshold_check();
|
||||||
|
push @exits, $exit2;
|
||||||
|
|
||||||
|
my $output = $obj->output();
|
||||||
|
$long_msg .= $long_msg_append . $output;
|
||||||
|
$long_msg_append = ', ';
|
||||||
|
|
||||||
|
if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) {
|
||||||
|
$short_msg .= $short_msg_append . $output;
|
||||||
|
$short_msg_append = ', ';
|
||||||
|
}
|
||||||
|
|
||||||
|
$obj->perfdata();
|
||||||
|
}
|
||||||
|
|
||||||
|
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
|
||||||
|
if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) {
|
||||||
$self->{output}->output_add(severity => $exit,
|
$self->{output}->output_add(severity => $exit,
|
||||||
short_msg => sprintf("Loaded Class Count : %i, Total Loaded Class : %i, Unloaded Class Count : %i",
|
short_msg => "Class $short_msg"
|
||||||
$result->{"java.lang:type=ClassLoading"}->{LoadedClassCount}, $result->{"java.lang:type=ClassLoading"}->{TotalLoadedClassCount},
|
);
|
||||||
$result->{"java.lang:type=ClassLoading"}->{UnloadedClassCount}));
|
} else {
|
||||||
|
$self->{output}->output_add(short_msg => "Class $long_msg");
|
||||||
$self->{output}->perfdata_add(label => 'TotalLoadedClassCount',
|
}
|
||||||
value => $result->{"java.lang:type=ClassLoading"}->{TotalLoadedClassCount},
|
|
||||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-total'),
|
|
||||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-total'),
|
|
||||||
min => 0);
|
|
||||||
|
|
||||||
$self->{output}->perfdata_add(label => 'LoadedClassCount',
|
|
||||||
value => $result->{"java.lang:type=ClassLoading"}->{LoadedClassCount},
|
|
||||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-loaded'),
|
|
||||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-loaded'),
|
|
||||||
min => 0);
|
|
||||||
|
|
||||||
$self->{output}->perfdata_add(label => 'UnloadedClassCount',
|
|
||||||
value => $result->{"java.lang:type=ClassLoading"}->{UnloadedClassCount},
|
|
||||||
min => 0);
|
|
||||||
|
|
||||||
|
|
||||||
|
$self->{statefile_value}->write(data => $self->{new_datas});
|
||||||
$self->{output}->display();
|
$self->{output}->display();
|
||||||
$self->{output}->exit();
|
$self->{output}->exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
sub manage_selection {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
my $mbean = 'java.lang:type=ClassLoading';
|
||||||
|
$self->{request} = [
|
||||||
|
{ mbean => $mbean, attributes => [ { name => 'UnloadedClassCount' }, { name => 'LoadedClassCount' }, { name => 'TotalLoadedClassCount' } ] },
|
||||||
|
];
|
||||||
|
my $result = $self->{connector}->get_attributes(request => $self->{request}, nothing_quit => 1);
|
||||||
|
|
||||||
|
$self->{global} = {};
|
||||||
|
$self->{global}->{unloaded} = $result->{$mbean}->{UnloadedClassCount} if (defined($result->{$mbean}->{UnloadedClassCount}));
|
||||||
|
$self->{global}->{loaded} = $result->{$mbean}->{TotalLoadedClassCount} if (defined($result->{$mbean}->{TotalLoadedClassCount}));
|
||||||
|
$self->{global}->{current} = $result->{$mbean}->{LoadedClassCount} if (defined($result->{$mbean}->{LoadedClassCount}));
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
@ -128,30 +205,20 @@ __END__
|
|||||||
|
|
||||||
=head1 MODE
|
=head1 MODE
|
||||||
|
|
||||||
Check Java Class Loading Mbean (Mbean java.lang:type=ClassLoading).
|
Check Java Class Loading Mbean.
|
||||||
|
|
||||||
Example:
|
|
||||||
perl centreon_plugins.pl --plugin=apps::tomcat::jmx::plugin --custommode=jolokia --url=http://10.30.2.22:8080/jolokia-war --mode=classcount --warning-loaded 60 --critical-loaded 75 --warning-total 65 --critical-total 75
|
|
||||||
|
|
||||||
=over 8
|
=over 8
|
||||||
|
|
||||||
=item B<--warning-loaded>
|
=item B<--warning-*>
|
||||||
|
|
||||||
Current number of loaded class triggering a warning
|
Threshold warning.
|
||||||
|
Can be: 'unloaded', 'loaded', 'current'.
|
||||||
|
|
||||||
=item B<--critical-loaded>
|
=item B<--critical-*>
|
||||||
|
|
||||||
Current number of loaded class triggering a critical
|
Threshold critical.
|
||||||
|
Can be: 'unloaded', 'loaded', 'current'.
|
||||||
=item B<--warning-total>
|
|
||||||
|
|
||||||
Total number of loaded class triggering a warning
|
|
||||||
|
|
||||||
=item B<--critical-total>
|
|
||||||
|
|
||||||
Total number total of loaded class triggering a critical
|
|
||||||
|
|
||||||
=back
|
=back
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user