This commit is contained in:
garnier-quentin 2019-07-10 16:50:46 +02:00
commit 36ba6de7ac
3 changed files with 392 additions and 0 deletions

View File

@ -0,0 +1,149 @@
#
# Copyright 2019 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package database::warp10::sensision::mode::fetchstatistics;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::common::monitoring::openmetrics::scrape;
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'fetchs', type => 1, cb_prefix_output => 'prefix_output',
message_multiple => 'All fetchs statistics are ok' },
];
$self->{maps_counters}->{fetchs} = [
{ label => 'calls', nlabel => 'fetch.calls.count', set => {
key_values => [ { name => 'calls' }, { name => 'display' } ],
output_template => 'Calls: %d',
perfdatas => [
{ value => 'calls_absolute', template => '%d',
min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
{ label => 'bytes-values', nlabel => 'fetch.bytes.values.bytes', set => {
key_values => [ { name => 'bytes_values' }, { name => 'display' } ],
output_template => 'Bytes Values: %s%s',
output_change_bytes => 1,
perfdatas => [
{ value => 'bytes_values_absolute', template => '%s',
min => 0, unit => 'B', label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
{ label => 'bytes-keys', nlabel => 'fetch.bytes.keys.bytes', set => {
key_values => [ { name => 'bytes_keys' }, { name => 'display' } ],
output_template => 'Bytes Keys: %s%s',
output_change_bytes => 1,
perfdatas => [
{ value => 'bytes_keys_absolute', template => '%s',
min => 0, unit => 'B', label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
];
}
sub prefix_output {
my ($self, %options) = @_;
return "Fetch '" . $options{instance_value}->{display} . "' ";
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
"filter-name:s" => { name => 'filter_name' },
});
return $self;
}
sub manage_selection {
my ($self, %options) = @_;
$self->{metrics} = centreon::common::monitoring::openmetrics::scrape::parse(%options);
foreach my $fetch (@{$self->{metrics}->{'warp.fetch.count'}->{data}}) {
$self->{fetchs}->{$fetch->{dimensions}->{app}}->{calls} = $fetch->{value};
$self->{fetchs}->{$fetch->{dimensions}->{app}}->{display} = $fetch->{dimensions}->{app};
}
foreach my $fetch (@{$self->{metrics}->{'warp.fetch.bytes.values'}->{data}}) {
$self->{fetchs}->{$fetch->{dimensions}->{app}}->{bytes_values} = $fetch->{value};
$self->{fetchs}->{$fetch->{dimensions}->{app}}->{display} = $fetch->{dimensions}->{app};
}
foreach my $fetch (@{$self->{metrics}->{'warp.fetch.bytes.keys'}->{data}}) {
$self->{fetchs}->{$fetch->{dimensions}->{app}}->{bytes_keys} = $fetch->{value};
$self->{fetchs}->{$fetch->{dimensions}->{app}}->{display} = $fetch->{dimensions}->{app};
}
foreach (keys %{$self->{fetchs}}) {
delete $self->{fetchs}->{$_} if (defined($self->{option_results}->{filter_name}) &&
$self->{option_results}->{filter_name} ne '' &&
$_ !~ /$self->{option_results}->{filter_name}/);
}
if (scalar(keys %{$self->{fetchs}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No fetchs found.");
$self->{output}->option_exit();
}
}
1;
__END__
=head1 MODE
Check fetchs statistics.
=over 8
=item B<--filter-name>
Filter app name (can be a regexp).
=item B<--filter-counters>
Only display some counters (regexp can be used).
Example: --filter-counters='calls'
=item B<--warning-*>
Threshold warning.
Can be: 'calls', 'bytes-values', 'bytes-keys'.
=item B<--critical-*>
Threshold critical.
Can be: 'calls', 'bytes-values', 'bytes-keys'.
=back
=cut

View File

@ -0,0 +1,193 @@
#
# Copyright 2019 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package database::warp10::sensision::mode::scriptstatistics;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::common::monitoring::openmetrics::scrape;
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0 },
{ name => 'functions', type => 1, cb_prefix_output => 'prefix_output',
message_multiple => 'All functions statistics are ok' },
];
$self->{maps_counters}->{global} = [
{ label => 'time-total', nlabel => 'time.total.microseconds', set => {
key_values => [ { name => 'time' } ],
output_template => 'Time Spent: %d us',
perfdatas => [
{ value => 'time_absolute', template => '%d',
min => 0, unit => 'us' },
],
}
},
{ label => 'requests', nlabel => 'requests.count', set => {
key_values => [ { name => 'requests' } ],
output_template => 'Requests: %d',
perfdatas => [
{ value => 'requests_absolute', template => '%d',
min => 0 },
],
}
},
{ label => 'ops', nlabel => 'ops.count', set => {
key_values => [ { name => 'ops' } ],
output_template => 'Ops: %d',
perfdatas => [
{ value => 'ops_absolute', template => '%d',
min => 0 },
],
}
},
{ label => 'errors', nlabel => 'errors.count', set => {
key_values => [ { name => 'errors' } ],
output_template => 'Errors: %d',
perfdatas => [
{ value => 'errors_absolute', template => '%d',
min => 0 },
],
}
},
{ label => 'bootstrap-loads', nlabel => 'bootstrap.loads.count', set => {
key_values => [ { name => 'bootstrap_loads' } ],
output_template => 'Bootstrap Loads: %d',
perfdatas => [
{ value => 'bootstrap_loads_absolute', template => '%d',
min => 0 },
],
}
},
];
$self->{maps_counters}->{functions} = [
{ label => 'time', nlabel => 'function.time.microseconds', set => {
key_values => [ { name => 'time' }, { name => 'display' } ],
output_template => 'Time Spent: %d us',
perfdatas => [
{ value => 'time_absolute', template => '%d',
min => 0, unit => 'us', label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
{ label => 'uses', nlabel => 'function.uses.count', set => {
key_values => [ { name => 'count' }, { name => 'display' } ],
output_template => 'Uses: %d',
perfdatas => [
{ value => 'count_absolute', template => '%d',
min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
];
}
sub prefix_output {
my ($self, %options) = @_;
return "Function '" . $options{instance_value}->{display} . "' ";
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
"filter-name:s" => { name => 'filter_name' },
});
return $self;
}
sub manage_selection {
my ($self, %options) = @_;
$self->{functions} = {};
$self->{metrics} = centreon::common::monitoring::openmetrics::scrape::parse(%options);
$self->{global} = {
time => $self->{metrics}->{'warp.script.time.us'}->{data}[0]->{value},
requests => $self->{metrics}->{'warp.script.requests'}->{data}[0]->{value},
ops => $self->{metrics}->{'warp.script.ops'}->{data}[0]->{value},
errors => $self->{metrics}->{'warp.script.errors'}->{data}[0]->{value},
bootstrap_loads => $self->{metrics}->{'warp.script.bootstrap.loads'}->{data}[0]->{value},
};
foreach my $function (@{$self->{metrics}->{'warp.script.function.count'}->{data}}) {
$self->{functions}->{$function->{dimensions}->{function}}->{count} = $function->{value};
$self->{functions}->{$function->{dimensions}->{function}}->{display} = $function->{dimensions}->{function};
}
foreach my $function (@{$self->{metrics}->{'warp.script.function.time.us'}->{data}}) {
$self->{functions}->{$function->{dimensions}->{function}}->{time} = $function->{value};
$self->{functions}->{$function->{dimensions}->{function}}->{display} = $function->{dimensions}->{function};
}
foreach (keys %{$self->{functions}}) {
delete $self->{functions}->{$_} if (defined($self->{option_results}->{filter_name}) &&
$self->{option_results}->{filter_name} ne '' &&
$_ !~ /$self->{option_results}->{filter_name}/);
}
if (scalar(keys %{$self->{functions}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No functions found.");
$self->{output}->option_exit();
}
}
1;
__END__
=head1 MODE
Check script and functions statistics.
=over 8
=item B<--filter-name>
Filter function name (can be a regexp).
=item B<--filter-counters>
Only display some counters (regexp can be used).
Example: --filter-counters='^time$|uses'
=item B<--warning-*>
Threshold warning.
Can be: 'time-total', 'requests', 'ops',
'errors', 'bootstrap-loads', 'time', 'uses'.
=item B<--critical-*>
Threshold critical.
Can be: 'time-total', 'requests', 'ops',
'errors', 'bootstrap-loads', 'time', 'uses'.
=back
=cut

View File

@ -0,0 +1,50 @@
#
# Copyright 2019 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package database::warp10::sensision::plugin;
use strict;
use warnings;
use base qw(centreon::plugins::script_custom);
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '0.1';
%{$self->{modes}} = (
'fetch-statistics' => 'database::warp10::sensision::mode::fetchstatistics',
'script-statistics' => 'database::warp10::sensision::mode::scriptstatistics',
);
$self->{custom_modes}{web} = 'centreon::common::monitoring::openmetrics::custom::web';
$self->{custom_modes}{file} = 'centreon::common::monitoring::openmetrics::custom::file';
return $self;
}
1;
__END__
=head1 PLUGIN DESCRIPTION
Check Warp10 using Sensision metrics.
=cut