move custom modes to common
This commit is contained in:
parent
a4f7a4848d
commit
bb842efd69
|
@ -25,6 +25,7 @@ use base qw(centreon::plugins::mode);
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use centreon::plugins::misc;
|
use centreon::plugins::misc;
|
||||||
|
use centreon::common::monitoring::openmetrics::scrape;
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
my ($class, %options) = @_;
|
my ($class, %options) = @_;
|
||||||
|
@ -62,32 +63,17 @@ sub check_options {
|
||||||
sub run {
|
sub run {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
my $response = $options{custom}->scrape;
|
$self->{metrics} = centreon::common::monitoring::openmetrics::scrape::parse(%options);
|
||||||
|
|
||||||
my $nometrics = 1;
|
|
||||||
foreach my $line (split /\n/, $response) {
|
|
||||||
$self->{metrics}->{$1}->{type} = $2 if ($line =~ /^#\sTYPE\s(\w+)\s(.*)$/);
|
|
||||||
$self->{metrics}->{$1}->{help} = $2 if ($line =~ /^#\sHELP\s(\w+)\s(.*)$/);
|
|
||||||
|
|
||||||
next if ($line !~ /^[\d\/\s]*([\w.]+)(.*)?\s([\d.+-e]+)$/);
|
|
||||||
my ($metric, $dimensions, $value) = ($1, $2, $3);
|
|
||||||
next if (defined($self->{option_results}->{filter_metrics}) && $self->{option_results}->{filter_metrics} ne '' &&
|
|
||||||
$metric !~ /$self->{option_results}->{filter_metrics}/);
|
|
||||||
|
|
||||||
$dimensions =~ s/[{}]//g;
|
|
||||||
$dimensions =~ s/"/'/g;
|
|
||||||
my %dimensions = map { (split /=/) } split /,/, $dimensions;
|
|
||||||
|
|
||||||
push @{$self->{metrics}->{$metric}->{data}}, {
|
|
||||||
value => centreon::plugins::misc::expand_exponential(value => $value),
|
|
||||||
dimensions => \%dimensions,
|
|
||||||
dimensions_string => $dimensions };
|
|
||||||
}
|
|
||||||
|
|
||||||
my @exits;
|
my @exits;
|
||||||
my $short_msg = 'All metrics are ok';
|
my $short_msg = 'All metrics are ok';
|
||||||
|
|
||||||
|
my $nometrics = 1;
|
||||||
|
|
||||||
foreach my $metric (keys %{$self->{metrics}}) {
|
foreach my $metric (keys %{$self->{metrics}}) {
|
||||||
|
next if (defined($self->{option_results}->{filter_metrics}) && $self->{option_results}->{filter_metrics} ne '' &&
|
||||||
|
$metric !~ /$self->{option_results}->{filter_metrics}/);
|
||||||
|
|
||||||
foreach my $data (@{$self->{metrics}->{$metric}->{data}}) {
|
foreach my $data (@{$self->{metrics}->{$metric}->{data}}) {
|
||||||
next if (defined($self->{option_results}->{instance}) &&
|
next if (defined($self->{option_results}->{instance}) &&
|
||||||
!defined($data->{dimensions}->{$self->{option_results}->{instance}}) ||
|
!defined($data->{dimensions}->{$self->{option_results}->{instance}}) ||
|
||||||
|
|
|
@ -33,8 +33,8 @@ sub new {
|
||||||
%{$self->{modes}} = (
|
%{$self->{modes}} = (
|
||||||
'scrape-metrics' => 'apps::monitoring::openmetrics::mode::scrapemetrics',
|
'scrape-metrics' => 'apps::monitoring::openmetrics::mode::scrapemetrics',
|
||||||
);
|
);
|
||||||
$self->{custom_modes}{web} = 'apps::monitoring::openmetrics::custom::web';
|
$self->{custom_modes}{web} = 'centreon::common::monitoring::openmetrics::custom::web';
|
||||||
$self->{custom_modes}{file} = 'apps::monitoring::openmetrics::custom::file';
|
$self->{custom_modes}{file} = 'centreon::common::monitoring::openmetrics::custom::file';
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
|
|
||||||
package apps::monitoring::openmetrics::custom::file;
|
package centreon::common::monitoring::openmetrics::custom::file;
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
|
@ -18,7 +18,7 @@
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
|
|
||||||
package apps::monitoring::openmetrics::custom::web;
|
package centreon::common::monitoring::openmetrics::custom::web;
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
|
@ -0,0 +1,65 @@
|
||||||
|
#
|
||||||
|
# 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 centreon::common::monitoring::openmetrics::scrape;
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
use centreon::plugins::misc;
|
||||||
|
|
||||||
|
sub parse {
|
||||||
|
my (%options) = @_;
|
||||||
|
|
||||||
|
my $result;
|
||||||
|
my $response = $options{custom}->scrape;
|
||||||
|
|
||||||
|
foreach my $line (split /\n/, $response) {
|
||||||
|
$result->{metrics}->{$1}->{type} = $2 if ($line =~ /^#\sTYPE\s(\w+)\s(.*)$/);
|
||||||
|
$result->{metrics}->{$1}->{help} = $2 if ($line =~ /^#\sHELP\s(\w+)\s(.*)$/);
|
||||||
|
|
||||||
|
next if ($line !~ /^[\d\/\s]*([\w.]+)(.*)?\s([\d.+-e]+)$/);
|
||||||
|
my ($metric, $dimensions, $value) = ($1, $2, $3);
|
||||||
|
|
||||||
|
$dimensions =~ s/[{}]//g;
|
||||||
|
$dimensions =~ s/"/'/g;
|
||||||
|
my %dimensions = map { (split /=/) } split /,/, $dimensions;
|
||||||
|
|
||||||
|
push @{$result->{metrics}->{$metric}->{data}}, {
|
||||||
|
value => centreon::plugins::misc::expand_exponential(value => $value),
|
||||||
|
dimensions => \%dimensions,
|
||||||
|
dimensions_string => $dimensions };
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result->{metrics};
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
||||||
|
|
||||||
|
__END__
|
||||||
|
|
||||||
|
=head1 MODE
|
||||||
|
|
||||||
|
Scrape metrics.
|
||||||
|
|
||||||
|
=over 8
|
||||||
|
|
||||||
|
=back
|
||||||
|
|
||||||
|
=cut
|
Loading…
Reference in New Issue