150 lines
4.9 KiB
Perl
150 lines
4.9 KiB
Perl
|
#
|
||
|
# 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
|