enhance tomcat jmx (#2284)
This commit is contained in:
parent
afdcf4b4ab
commit
bbd0364a21
|
@ -30,7 +30,7 @@ sub set_counters {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
$self->{maps_counters_type} = [
|
$self->{maps_counters_type} = [
|
||||||
{ name => 'datasource', type => 1, cb_prefix_output => 'prefix_ds_output', message_multiple => 'All datasources are ok' },
|
{ name => 'datasource', type => 1, cb_prefix_output => 'prefix_ds_output', message_multiple => 'All datasources are ok' }
|
||||||
];
|
];
|
||||||
|
|
||||||
$self->{maps_counters}->{datasource} = [
|
$self->{maps_counters}->{datasource} = [
|
||||||
|
@ -40,7 +40,7 @@ sub set_counters {
|
||||||
closure_custom_calc_extra_options => { label_ref => 'Active', message => 'Current Num Active' },
|
closure_custom_calc_extra_options => { label_ref => 'Active', message => 'Current Num Active' },
|
||||||
closure_custom_output => $self->can('custom_usage_output'),
|
closure_custom_output => $self->can('custom_usage_output'),
|
||||||
closure_custom_threshold_check => $self->can('custom_usage_threshold'),
|
closure_custom_threshold_check => $self->can('custom_usage_threshold'),
|
||||||
closure_custom_perfdata => $self->can('custom_usage_perfdata'),
|
closure_custom_perfdata => $self->can('custom_usage_perfdata')
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ label => 'num-idle', set => {
|
{ label => 'num-idle', set => {
|
||||||
|
@ -49,9 +49,9 @@ sub set_counters {
|
||||||
closure_custom_calc_extra_options => { label_ref => 'Idle', message => 'Current Num Idle' },
|
closure_custom_calc_extra_options => { label_ref => 'Idle', message => 'Current Num Idle' },
|
||||||
closure_custom_output => $self->can('custom_usage_output'),
|
closure_custom_output => $self->can('custom_usage_output'),
|
||||||
closure_custom_threshold_check => $self->can('custom_usage_threshold'),
|
closure_custom_threshold_check => $self->can('custom_usage_threshold'),
|
||||||
closure_custom_perfdata => $self->can('custom_usage_perfdata'),
|
closure_custom_perfdata => $self->can('custom_usage_perfdata')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,8 +135,8 @@ sub new {
|
||||||
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' },
|
||||||
"units:s" => { name => 'units', default => '%' },
|
'units:s' => { name => 'units', default => '%' }
|
||||||
});
|
});
|
||||||
|
|
||||||
return $self;
|
return $self;
|
||||||
|
@ -151,20 +151,28 @@ sub manage_selection {
|
||||||
[ { name => 'numActive' }, { name => 'numIdle' }, { name => 'maxIdle' }, { name => 'maxTotal' }, { name => 'maxActive' } ] },
|
[ { name => 'numActive' }, { name => 'numIdle' }, { name => 'maxIdle' }, { name => 'maxTotal' }, { name => 'maxActive' } ] },
|
||||||
{ mbean => "*:type=DataSource,class=*,path=*,host=*,name=*", attributes =>
|
{ mbean => "*:type=DataSource,class=*,path=*,host=*,name=*", attributes =>
|
||||||
[ { name => 'numActive' }, { name => 'numIdle' }, { name => 'maxIdle' }, { name => 'maxTotal' }, { name => 'maxActive' } ] },
|
[ { name => 'numActive' }, { name => 'numIdle' }, { name => 'maxIdle' }, { name => 'maxTotal' }, { name => 'maxActive' } ] },
|
||||||
|
{ mbean => "*:type=DataSource,class=*,name=*", attributes =>
|
||||||
|
[ { name => 'numActive' }, { name => 'numIdle' }, { name => 'maxIdle' }, { name => 'maxTotal' }, { name => 'maxActive' } ] }
|
||||||
];
|
];
|
||||||
|
|
||||||
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->{datasource} = {};
|
$self->{datasource} = {};
|
||||||
foreach my $key (keys %$result) {
|
foreach my $key (keys %$result) {
|
||||||
$key =~ /(?:[:,])host=(.*?)(?:,|$)/;
|
my ($ds_name, $append) = ('', '');
|
||||||
my $ds_name = $1;
|
|
||||||
$key =~ /(?:[:,])(?:path|context)=(.*?)(?:,|$)/;
|
if ($key =~ /(?:[:,])host=(.*?)(?:,|$)/) {
|
||||||
$ds_name .= '.' . $1;
|
$ds_name = $1;
|
||||||
$key =~ /(?:[:,])name=(.*?)(?:,|$)/; # double quote a virer
|
$append = '.';
|
||||||
|
}
|
||||||
|
if ($key =~ /(?:[:,])(?:path|context)=(.*?)(?:,|$)/) {
|
||||||
|
$ds_name .= $append . $1;
|
||||||
|
$append = '.';
|
||||||
|
}
|
||||||
|
$key =~ /(?:[:,])name=(.*?)(?:,|$)/;
|
||||||
my $tmp_name = $1;
|
my $tmp_name = $1;
|
||||||
$tmp_name =~ s/^"(.*)"$/$1/;
|
$tmp_name =~ s/^"(.*)"$/$1/;
|
||||||
$ds_name .= '.' . $tmp_name;
|
$ds_name .= $append . $tmp_name;
|
||||||
|
|
||||||
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
|
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
|
||||||
$ds_name !~ /$self->{option_results}->{filter_name}/) {
|
$ds_name !~ /$self->{option_results}->{filter_name}/) {
|
||||||
|
@ -177,11 +185,11 @@ sub manage_selection {
|
||||||
numActive => $result->{$key}->{numActive},
|
numActive => $result->{$key}->{numActive},
|
||||||
maxActive => defined($result->{$key}->{maxTotal}) ? $result->{$key}->{maxTotal} : $result->{$key}->{maxActive},
|
maxActive => defined($result->{$key}->{maxTotal}) ? $result->{$key}->{maxTotal} : $result->{$key}->{maxActive},
|
||||||
numIdle => $result->{$key}->{numIdle},
|
numIdle => $result->{$key}->{numIdle},
|
||||||
maxIdle => $result->{$key}->{maxIdle},
|
maxIdle => $result->{$key}->{maxIdle}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->{cache_name} = "tomcat_" . $self->{mode} . '_' . md5_hex($options{custom}->get_connection_info()) . '_' .
|
$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_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'));
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,12 +30,11 @@ sub new {
|
||||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||||
bless $self, $class;
|
bless $self, $class;
|
||||||
|
|
||||||
$options{options}->add_options(arguments =>
|
$options{options}->add_options(arguments => {
|
||||||
{
|
'filter-host:s' => { name => 'filter_host' },
|
||||||
"filter-host:s" => { name => 'filter_host' },
|
'filter-path:s' => { name => 'filter_path' }
|
||||||
"filter-path:s" => { name => 'filter_path' },
|
|
||||||
});
|
});
|
||||||
$self->{ds} = {};
|
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,20 +46,35 @@ sub check_options {
|
||||||
sub manage_selection {
|
sub manage_selection {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
$self->{request} = [
|
my $mbeans = $options{custom}->get_attributes(
|
||||||
|
request => [
|
||||||
{ mbean => "*:type=DataSource,class=*,context=*,host=*,name=*", attributes =>
|
{ mbean => "*:type=DataSource,class=*,context=*,host=*,name=*", attributes =>
|
||||||
[ { name => 'numActive' } ] },
|
[ { name => 'numActive' } ] },
|
||||||
];
|
{ mbean => "*:type=DataSource,class=*,path=*,host=*,name=*", attributes =>
|
||||||
my $result = $options{custom}->get_attributes(request => $self->{request});
|
[ { name => 'numActive' } ] },
|
||||||
|
{ mbean => "*:type=DataSource,class=*,name=*", attributes =>
|
||||||
|
[ { name => 'numActive' } ] }
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
foreach my $mbean (keys %{$result}) {
|
my $results = {};
|
||||||
$mbean =~ /(?:[:,])host=(.*?)(?:,|$)/;
|
foreach my $mbean (keys %$mbeans) {
|
||||||
my $host = $1;
|
my ($ds_name, $path, $host, $append) = ('', '', '', '');
|
||||||
$mbean =~ /(?:[:,])(?:path|context)=(.*?)(?:,|$)/;
|
|
||||||
my $path = $1;
|
if ($mbean =~ /(?:[:,])host=(.*?)(?:,|$)/) {
|
||||||
|
$host = $1;
|
||||||
|
$ds_name = $host;
|
||||||
|
$append = '.';
|
||||||
|
}
|
||||||
|
if ($mbean =~ /(?:[:,])(?:path|context)=(.*?)(?:,|$)/) {
|
||||||
|
$path = $1;
|
||||||
|
$ds_name .= $append . $path;
|
||||||
|
$append = '.';
|
||||||
|
}
|
||||||
$mbean =~ /(?:[:,])name=(.*?)(?:,|$)/;
|
$mbean =~ /(?:[:,])name=(.*?)(?:,|$)/;
|
||||||
my $name = $1;
|
my $name = $1;
|
||||||
$name =~ s/^"(.*)"$/$1/;
|
$name =~ s/^"(.*)"$/$1/;
|
||||||
|
$ds_name .= $append . $name;
|
||||||
|
|
||||||
if (defined($self->{option_results}->{filter_host}) && $self->{option_results}->{filter_host} ne '' &&
|
if (defined($self->{option_results}->{filter_host}) && $self->{option_results}->{filter_host} ne '' &&
|
||||||
$host !~ /$self->{option_results}->{filter_host}/) {
|
$host !~ /$self->{option_results}->{filter_host}/) {
|
||||||
|
@ -73,25 +87,34 @@ sub manage_selection {
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->{ds}->{$host . '.' . $path} = {
|
$results->{$ds_name} = {
|
||||||
host => $host, path => $path, name => $name,
|
host => $host,
|
||||||
|
path => $path,
|
||||||
|
name => $name,
|
||||||
|
fullname => $ds_name
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $results;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub run {
|
sub run {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
$self->manage_selection(%options);
|
my $results = $self->manage_selection(%options);
|
||||||
foreach my $instance (sort keys %{$self->{ds}}) {
|
foreach my $instance (sort keys %$results) {
|
||||||
$self->{output}->output_add(long_msg => '[host = ' . $self->{ds}->{$instance}->{host} . "]" .
|
$self->{output}->output_add(
|
||||||
" [path = '" . $self->{ds}->{$instance}->{path} . "']" .
|
long_msg =>
|
||||||
" [name = '" . $self->{ds}->{$instance}->{name} . "']"
|
'[host = ' . $results->{$instance}->{host} . "]" .
|
||||||
|
" [path = '" . $results->{$instance}->{path} . "']" .
|
||||||
|
" [name = '" . $results->{$instance}->{name} . "']"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->{output}->output_add(severity => 'OK',
|
$self->{output}->output_add(
|
||||||
short_msg => 'List data sources:');
|
severity => 'OK',
|
||||||
|
short_msg => 'List data sources:'
|
||||||
|
);
|
||||||
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
|
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
|
||||||
$self->{output}->exit();
|
$self->{output}->exit();
|
||||||
}
|
}
|
||||||
|
@ -99,16 +122,16 @@ sub run {
|
||||||
sub disco_format {
|
sub disco_format {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
$self->{output}->add_disco_format(elements => ['host', 'path', 'name']);
|
$self->{output}->add_disco_format(elements => ['host', 'path', 'name', 'fullname']);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub disco_show {
|
sub disco_show {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
$self->manage_selection(%options);
|
my $results = $self->manage_selection(%options);
|
||||||
foreach my $instance (sort keys %{$self->{ds}}) {
|
foreach my $instance (sort keys %$results) {
|
||||||
$self->{output}->add_disco_entry(
|
$self->{output}->add_disco_entry(
|
||||||
%{$self->{ds}->{$instance}}
|
%{$results->{$instance}}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ sub new {
|
||||||
bless $self, $class;
|
bless $self, $class;
|
||||||
|
|
||||||
$self->{version} = '0.1';
|
$self->{version} = '0.1';
|
||||||
%{$self->{modes}} = (
|
$self->{modes} = {
|
||||||
'class-count' => 'centreon::common::jvm::mode::classcount',
|
'class-count' => 'centreon::common::jvm::mode::classcount',
|
||||||
'connector-usage' => 'apps::tomcat::jmx::mode::connectorusage',
|
'connector-usage' => 'apps::tomcat::jmx::mode::connectorusage',
|
||||||
'cpu-load' => 'centreon::common::jvm::mode::cpuload',
|
'cpu-load' => 'centreon::common::jvm::mode::cpuload',
|
||||||
|
@ -43,10 +43,10 @@ sub new {
|
||||||
'memory' => 'centreon::common::jvm::mode::memory',
|
'memory' => 'centreon::common::jvm::mode::memory',
|
||||||
'memory-detailed' => 'centreon::common::jvm::mode::memorydetailed',
|
'memory-detailed' => 'centreon::common::jvm::mode::memorydetailed',
|
||||||
'threads' => 'centreon::common::jvm::mode::threads',
|
'threads' => 'centreon::common::jvm::mode::threads',
|
||||||
'webapps-sessions' => 'apps::tomcat::jmx::mode::webappssessions',
|
'webapps-sessions' => 'apps::tomcat::jmx::mode::webappssessions'
|
||||||
);
|
};
|
||||||
|
|
||||||
$self->{custom_modes}{jolokia} = 'centreon::common::protocols::jmx::custom::jolokia';
|
$self->{custom_modes}->{jolokia} = 'centreon::common::protocols::jmx::custom::jolokia';
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue