enhance jmx mode with statefile for proxy mode

This commit is contained in:
qgarnier 2017-12-04 16:00:12 +01:00
parent 7eeda8d113
commit 5af3a42684
13 changed files with 120 additions and 283 deletions

View File

@ -148,7 +148,7 @@ sub manage_selection {
$self->{output}->option_exit();
}
$self->{cache_name} = "hibernate_" . $self->{mode} . '_' . md5_hex($options{custom}->{url}) . '_' .
$self->{cache_name} = "hibernate_" . $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'));
}

View File

@ -131,7 +131,7 @@ sub manage_selection {
$self->{output}->option_exit();
}
$self->{cache_name} = "solr_" . $self->{mode} . '_' . md5_hex($options{custom}->{url}) . '_' .
$self->{cache_name} = "solr_" . $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'));
}

View File

@ -128,7 +128,7 @@ sub manage_selection {
$self->{output}->option_exit();
}
$self->{cache_name} = "solr_" . $self->{mode} . '_' . md5_hex($options{custom}->{url}) . '_' .
$self->{cache_name} = "solr_" . $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'));
}

View File

@ -141,7 +141,7 @@ sub manage_selection {
$self->{output}->option_exit();
}
$self->{cache_name} = "zookeeper_" . $self->{mode} . '_' . md5_hex($options{custom}->{url}) . '_' .
$self->{cache_name} = "zookeeper_" . $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'));
}

View File

@ -142,7 +142,7 @@ sub check_value {
if ($self->{attributes}->{type} =~ /^counter$/i) {
if (!defined($self->{datas})) {
$self->{datas} = {};
$self->{statefile_cache}->read(statefile => "jmxstandard_" . $self->{mode} . '_' . md5_hex($self->{connector}->{url} . ' ' . $self->{option_results}->{mbean_pattern}));
$self->{statefile_cache}->read(statefile => "jmxstandard_" . $self->{mode} . '_' . md5_hex($self->{connector}->get_connection_info() . ' ' . $self->{option_results}->{mbean_pattern}));
}
my $old_timestamp = $self->{statefile_cache}->get(name => 'timestamp');

View File

@ -213,7 +213,7 @@ sub manage_selection {
$self->{tomcatconnector}->{$connector} = { %{$self->{tomcatconnector}->{$connector}}, %{$result->{$key}} };
}
$self->{cache_name} = "tomcat_" . $self->{mode} . '_' . md5_hex($options{custom}->{url}) . '_' .
$self->{cache_name} = "tomcat_" . $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'));
}

View File

@ -189,7 +189,7 @@ sub manage_selection {
};
}
$self->{cache_name} = "tomcat_" . $self->{mode} . '_' . md5_hex($options{custom}->{url}) . '_' .
$self->{cache_name} = "tomcat_" . $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'));
}

View File

@ -184,7 +184,7 @@ sub manage_selection {
};
}
$self->{cache_name} = "tomcat_" . $self->{mode} . '_' . md5_hex($options{custom}->{url}) . '_' .
$self->{cache_name} = "tomcat_" . $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'));
}

View File

@ -20,168 +20,79 @@
package centreon::common::jvm::mode::classcount;
use base qw(centreon::plugins::mode);
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::values;
use centreon::plugins::statefile;
use Digest::MD5 qw(md5_hex);
my $instance_mode;
sub set_counters {
my ($self, %options) = @_;
my $maps_counters = {
class => {
'000_current' => { set => { key_values => [ { name => 'current' } ],
$self->{maps_counters_type} = [
{ name => 'global', type => 0, cb_prefix_output => 'prefix_global_output', skipped_code => { -10 => 1 } },
];
$self->{maps_counters}->{global} = [
{ label => 'current', set => {
key_values => [ { name => 'LoadedClassCount' } ],
output_template => 'Current : %s',
perfdatas => [
{ label => 'current', value => 'current_absolute', template => '%s', min => 0 },
{ label => 'current', value => 'LoadedClassCount_absolute', template => '%s', min => 0 },
],
}
},
'001_loaded' => { set => { key_values => [ { name => 'loaded', diff => 1 } ],
{ label => 'loaded', set => {
key_values => [ { name => 'TotalLoadedClassCount', diff => 1 } ],
output_template => 'Loaded : %s',
perfdatas => [
{ label => 'loaded', value => 'loaded_absolute', template => '%s', min => 0 },
{ label => 'loaded', value => 'TotalLoadedClassCount_absolute', template => '%s', min => 0 },
],
}
},
'003_unloaded' => { set => { key_values => [ { name => 'unloaded', diff => 1 } ],
{ label => 'unloaded', set => {
key_values => [ { name => 'UnloadedClassCount', diff => 1 } ],
output_template => 'Unloaded : %s',
perfdatas => [
{ label => 'unloaded', value => 'unloaded_absolute', template => '%s', min => 0 },
{ label => 'unloaded', value => 'UnloadedClassCount_absolute', 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);
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
});
$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;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
foreach my $key (('class')) {
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();
}
my ($section, $status, $filter) = ($1, $2, $3);
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->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section}));
push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status};
}
}
sub run {
my ($self, %options) = @_;
$self->{connector} = $options{custom};
$self->manage_selection();
$self->{new_datas} = {};
$self->{statefile_value}->read(statefile => "jvm_standard_" . $self->{mode} . '_' . md5_hex($self->{connector}->{url}));
$self->{new_datas}->{last_timestamp} = time();
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,
short_msg => "Class $short_msg"
);
} else {
$self->{output}->output_add(short_msg => "Class $long_msg");
}
$self->{statefile_value}->write(data => $self->{new_datas});
$self->{output}->display();
$self->{output}->exit();
}
sub manage_selection {
my ($self, %options) = @_;
my $mbean = 'java.lang:type=ClassLoading';
$self->{request} = [
my $request = [
{ mbean => $mbean, attributes => [ { name => 'UnloadedClassCount' }, { name => 'LoadedClassCount' }, { name => 'TotalLoadedClassCount' } ] },
];
my $result = $self->{connector}->get_attributes(request => $self->{request}, nothing_quit => 1);
my $result = $options{custom}->get_attributes(request => $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}));
$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'));
}
1;
@ -194,6 +105,11 @@ Check Java Class Loading Mbean.
=over 8
=item B<--filter-counters>
Only display some counters (regexp can be used).
Example: --filter-counters='current'
=item B<--warning-*>
Threshold warning.

View File

@ -100,7 +100,7 @@ sub manage_selection {
$self->{output}->option_exit();
}
$self->{cache_name} = "jvm_standard_" . $self->{mode} . '_' . md5_hex($options{custom}->{url}) . '_' .
$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'));
}

View File

@ -36,7 +36,9 @@ my %mapping_memory = (
'PS Perm Gen' => 'permanent',
'Perm Gen' => 'permanent',
'Metaspace' => 'permanent',
'JIT data cache' => 'permanent',
'Code Cache' => 'code',
'JIT Code Cache' => 'code',
'CMS Old Gen' => 'tenured',
'PS Old Gen' => 'tenured',
'Tenured Gen' => 'tenured',

View File

@ -20,168 +20,79 @@
package centreon::common::jvm::mode::threads;
use base qw(centreon::plugins::mode);
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::values;
use centreon::plugins::statefile;
use Digest::MD5 qw(md5_hex);
my $instance_mode;
sub set_counters {
my ($self, %options) = @_;
my $maps_counters = {
threads => {
'000_active' => { set => { key_values => [ { name => 'active' } ],
$self->{maps_counters_type} = [
{ name => 'global', type => 0, cb_prefix_output => 'prefix_global_output', skipped_code => { -10 => 1 } },
];
$self->{maps_counters}->{global} = [
{ label => 'active', set => {
key_values => [ { name => 'ThreadCount' } ],
output_template => 'Active : %s',
perfdatas => [
{ label => 'active', value => 'active_absolute', template => '%s', min => 0 },
{ label => 'active', value => 'ThreadCount_absolute', template => '%s', min => 0 },
],
}
},
'001_started' => { set => { key_values => [ { name => 'started', diff => 1 } ],
{ label => 'started', set => {
key_values => [ { name => 'TotalStartedThreadCount', diff => 1 } ],
output_template => 'Started : %s',
perfdatas => [
{ label => 'started', value => 'started_absolute', template => '%s', min => 0 },
{ label => 'started', value => 'TotalStartedThreadCount_absolute', template => '%s', min => 0 },
],
}
},
'003_daemon' => { set => { key_values => [ { name => 'daemon' } ],
{ label => 'daemon', set => {
key_values => [ { name => 'DaemonThreadCount' } ],
output_template => 'Daemon : %s',
perfdatas => [
{ label => 'daemon', value => 'daemon_absolute', template => '%s', min => 0 },
{ label => 'daemon', value => 'DaemonThreadCount_absolute', 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);
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
});
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
foreach my $key (('threads')) {
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;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
foreach my $key (('threads')) {
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();
}
my ($section, $status, $filter) = ($1, $2, $3);
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->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section}));
push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status};
}
}
sub run {
my ($self, %options) = @_;
$self->{connector} = $options{custom};
$self->manage_selection();
$self->{new_datas} = {};
$self->{statefile_value}->read(statefile => "jvm_standard_" . $self->{mode} . '_' . md5_hex($self->{connector}->{url}));
$self->{new_datas}->{last_timestamp} = time();
my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', '');
my @exits;
foreach (sort keys %{$maps_counters->{threads}}) {
my $obj = $maps_counters->{threads}->{$_}->{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,
short_msg => "Threads $short_msg"
);
} else {
$self->{output}->output_add(short_msg => "Threads $long_msg");
}
$self->{statefile_value}->write(data => $self->{new_datas});
$self->{output}->display();
$self->{output}->exit();
}
sub manage_selection {
my ($self, %options) = @_;
my $mbean = 'java.lang:type=Threading';
$self->{request} = [
my $request = [
{ mbean => $mbean, attributes => [ { name => 'TotalStartedThreadCount' }, { name => 'ThreadCount' }, { name => 'DaemonThreadCount' } ] },
];
my $result = $self->{connector}->get_attributes(request => $self->{request}, nothing_quit => 1);
my $result = $options{custom}->get_attributes(request => $request, nothing_quit => 1);
$self->{global} = {};
$self->{global}->{started} = $result->{$mbean}->{TotalStartedThreadCount} if (defined($result->{$mbean}->{TotalStartedThreadCount}));
$self->{global}->{active} = $result->{$mbean}->{ThreadCount} if (defined($result->{$mbean}->{ThreadCount}));
$self->{global}->{daemon} = $result->{$mbean}->{DaemonThreadCount} if (defined($result->{$mbean}->{DaemonThreadCount}));
$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'));
}
1;

View File

@ -146,6 +146,14 @@ sub check_options {
return 1;
}
sub get_connection_info {
my ($self, %options) = @_;
my $connection_info = $self->{url};
$connection_info .= '_' . $self->{proxy_url} if (defined($self->{proxy_url}));
return $connection_info;
}
sub connect {
my ($self, %options) = @_;