add influxdb plugin
This commit is contained in:
parent
598f48f16a
commit
325c8a67cd
|
@ -0,0 +1,287 @@
|
|||
#
|
||||
# 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::influxdb::custom::api;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::http;
|
||||
use URI::Encode;
|
||||
use JSON::XS;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = {};
|
||||
bless $self, $class;
|
||||
|
||||
if (!defined($options{output})) {
|
||||
print "Class Custom: Need to specify 'output' argument.\n";
|
||||
exit 3;
|
||||
}
|
||||
if (!defined($options{options})) {
|
||||
$options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument.");
|
||||
$options{output}->option_exit();
|
||||
}
|
||||
|
||||
if (!defined($options{noptions})) {
|
||||
$options{options}->add_options(arguments => {
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"port:s" => { name => 'port' },
|
||||
"proto:s" => { name => 'proto' },
|
||||
"credentials" => { name => 'credentials' },
|
||||
"basic" => { name => 'basic' },
|
||||
"username:s" => { name => 'username' },
|
||||
"password:s" => { name => 'password' },
|
||||
"timeout:s" => { name => 'timeout' },
|
||||
});
|
||||
}
|
||||
$options{options}->add_help(package => __PACKAGE__, sections => 'CUSTOM MODE OPTIONS', once => 1);
|
||||
|
||||
$self->{output} = $options{output};
|
||||
$self->{mode} = $options{mode};
|
||||
$self->{http} = centreon::plugins::http->new(%options);
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub set_options {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{option_results} = $options{option_results};
|
||||
}
|
||||
|
||||
sub set_defaults {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
foreach (keys %{$options{default}}) {
|
||||
if ($_ eq $self->{mode}) {
|
||||
for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) {
|
||||
foreach my $opt (keys %{$options{default}->{$_}[$i]}) {
|
||||
if (!defined($self->{option_results}->{$opt}[$i])) {
|
||||
$self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : '';
|
||||
$self->{port} = (defined($self->{option_results}->{port})) ? $self->{option_results}->{port} : 8086;
|
||||
$self->{proto} = (defined($self->{option_results}->{proto})) ? $self->{option_results}->{proto} : 'http';
|
||||
$self->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 10;
|
||||
$self->{username} = (defined($self->{option_results}->{username})) ? $self->{option_results}->{username} : undef;
|
||||
$self->{password} = (defined($self->{option_results}->{password})) ? $self->{option_results}->{password} : undef;
|
||||
$self->{credentials} = (defined($self->{option_results}->{credentials})) ? 1 : undef;
|
||||
$self->{basic} = (defined($self->{option_results}->{basic})) ? 1 : undef;
|
||||
|
||||
if (!defined($self->{hostname}) || $self->{hostname} eq '') {
|
||||
$self->{output}->add_option_msg(short_msg => "Need to specify --hostname option.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub get_hostname {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return $self->{hostname};
|
||||
}
|
||||
|
||||
sub get_port {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return $self->{port};
|
||||
}
|
||||
|
||||
sub build_options_for_httplib {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{option_results}->{hostname} = $self->{hostname};
|
||||
$self->{option_results}->{timeout} = $self->{timeout};
|
||||
$self->{option_results}->{port} = $self->{port};
|
||||
$self->{option_results}->{proto} = $self->{proto};
|
||||
$self->{option_results}->{timeout} = $self->{timeout};
|
||||
$self->{option_results}->{warning_status} = '';
|
||||
$self->{option_results}->{critical_status} = '';
|
||||
$self->{option_results}->{unknown_status} = '%{http_code} < 200 or %{http_code} >= 300';
|
||||
}
|
||||
|
||||
sub settings {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->build_options_for_httplib();
|
||||
$self->{http}->set_options(%{$self->{option_results}});
|
||||
}
|
||||
|
||||
sub request {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->settings();
|
||||
|
||||
$self->{output}->output_add(long_msg => "URL: '" . $self->{proto} . '://' . $self->{hostname} . ':' . $self->{port} . $options{url_path} . "'", debug => 1);
|
||||
$self->{output}->output_add(long_msg => "Parameters: '" . join(', ', @{$options{post_param}}) . "'", debug => 1) if (defined($options{post_param}));
|
||||
|
||||
my $content = $self->{http}->request(%options);
|
||||
|
||||
if (!defined($content) || $content eq '') {
|
||||
$self->{output}->add_option_msg(short_msg => "API returns empty content [code: '" . $self->{http}->get_code() . "'] [message: '" . $self->{http}->get_message() . "']");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
my $decoded;
|
||||
eval {
|
||||
$decoded = JSON::XS->new->utf8->decode($content);
|
||||
};
|
||||
if ($@) {
|
||||
$self->{output}->output_add(long_msg => $content, debug => 1);
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot decode response (add --debug option to display returned content)");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (defined($decoded->{error})) {
|
||||
$self->{output}->add_option_msg(short_msg => "API returns error '" . $decoded->{error} . "'");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
return $decoded;
|
||||
}
|
||||
|
||||
sub query {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
# push @post_params, 'db=' . $options{db} if (defined($options{db}) && $options{db} ne '');
|
||||
|
||||
my $data;
|
||||
foreach my $query (@{$options{queries}}) {
|
||||
my @post_params;
|
||||
push @post_params, 'q=' . $query;
|
||||
my $results = $self->request(method => 'POST', url_path => '/query', post_param => \@post_params);
|
||||
push @{$data}, @{$results->{results}[0]->{series}};
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
sub compute {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $result;
|
||||
|
||||
if ($options{aggregation} eq 'average') {
|
||||
my $points = 0;
|
||||
foreach my $value (@{$options{values}}) {
|
||||
$result = 0 if (!defined($result));
|
||||
$result += $$value[1];
|
||||
$points++;
|
||||
}
|
||||
$result /= $points;
|
||||
} elsif ($options{aggregation} eq 'minimum') {
|
||||
foreach my $value (@{$options{values}}) {
|
||||
$result = $$value[1] if (!defined($result) || $$value[1] < $result);
|
||||
}
|
||||
} elsif ($options{aggregation} eq 'maximum') {
|
||||
foreach my $value (@{$options{values}}) {
|
||||
$result = $$value[1] if (!defined($result) || $$value[1] > $result);
|
||||
}
|
||||
} elsif ($options{aggregation} eq 'sum') {
|
||||
foreach my $value (@{$options{values}}) {
|
||||
$result = 0 if (!defined($result));
|
||||
$result += $$value[1];
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 NAME
|
||||
|
||||
InfluxDB Rest API
|
||||
|
||||
=head1 CUSTOM MODE OPTIONS
|
||||
|
||||
InfluxDB Rest API
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--hostname>
|
||||
|
||||
Remote hostname or IP address.
|
||||
|
||||
=item B<--port>
|
||||
|
||||
Port used (Default: 8086)
|
||||
|
||||
=item B<--proto>
|
||||
|
||||
Specify https if needed (Default: 'http')
|
||||
|
||||
=item B<--credentials>
|
||||
|
||||
Specify this option if you access webpage with authentication
|
||||
|
||||
=item B<--username>
|
||||
|
||||
Specify username for authentication (Mandatory if --credentials is specified)
|
||||
|
||||
=item B<--password>
|
||||
|
||||
Specify password for authentication (Mandatory if --credentials is specified)
|
||||
|
||||
=item B<--basic>
|
||||
|
||||
Specify this option if you access webpage over basic authentication and don't want a '401 UNAUTHORIZED' error to be logged on your webserver.
|
||||
|
||||
Specify this option if you access webpage over hidden basic authentication or you'll get a '404 NOT FOUND' error.
|
||||
|
||||
(Use with --credentials)
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Set timeout in seconds (Default: 10).
|
||||
|
||||
=item B<--unknown-status>
|
||||
|
||||
Threshold warning for http response code.
|
||||
(Default: '%{http_code} < 200 or %{http_code} >= 300')
|
||||
|
||||
=item B<--warning-status>
|
||||
|
||||
Threshold warning for http response code.
|
||||
|
||||
=item B<--critical-status>
|
||||
|
||||
Threshold critical for http response code.
|
||||
|
||||
=back
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
B<custom>.
|
||||
|
||||
=cut
|
|
@ -0,0 +1,97 @@
|
|||
#
|
||||
# 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::influxdb::mode::connectiontime;
|
||||
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Time::HiRes;
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'global', type => 0 },
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{global} = [
|
||||
{ label => 'connection-time', nlabel => 'connection.time.milliseconds', set => {
|
||||
key_values => [ { name => 'connection_time' } ],
|
||||
output_template => 'Connection established in %d ms',
|
||||
perfdatas => [
|
||||
{ value => 'connection_time_absolute', template => '%d', unit => 'ms',
|
||||
min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments => {});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{custom} = $options{custom};
|
||||
|
||||
my $start = Time::HiRes::time();
|
||||
$self->{custom}->request(url_path => '/ping?verbose=true');
|
||||
my $end = Time::HiRes::time();
|
||||
|
||||
$self->{global}->{connection_time} = ($end - $start) * 1000;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check database connection time.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--warning-connection-time-milliseconds>
|
||||
|
||||
Threshold warning in milliseconds.
|
||||
|
||||
=item B<--critical-connection-time-milliseconds>>
|
||||
|
||||
Threshold critical in milliseconds.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,136 @@
|
|||
#
|
||||
# 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::influxdb::mode::databasestatistics;
|
||||
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'databases', type => 1, cb_prefix_output => 'prefix_database_output',
|
||||
message_multiple => 'All databases statistics are ok' },
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{databases} = [
|
||||
{ label => 'measurements', nlabel => 'database.measurements.count', set => {
|
||||
key_values => [ { name => 'numMeasurements' }, { name => 'display' } ],
|
||||
output_template => 'Measurements: %s',
|
||||
perfdatas => [
|
||||
{ value => 'numMeasurements_absolute', template => '%s',
|
||||
min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'series', nlabel => 'database.series.count', set => {
|
||||
key_values => [ { name => 'numSeries' }, { name => 'display' } ],
|
||||
output_template => 'Series: %s',
|
||||
perfdatas => [
|
||||
{ value => 'numSeries_absolute', template => '%s',
|
||||
min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
|
||||
],
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
sub prefix_database_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Database '" . $options{instance_value}->{display} . "' ";
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments => {
|
||||
"filter-database:s" => { name => 'filter_database' },
|
||||
});
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::check_options(%options);
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{custom} = $options{custom};
|
||||
|
||||
$self->{databases} = {};
|
||||
|
||||
my $results = $self->{custom}->query(queries => [ "SHOW STATS FOR 'database'" ]);
|
||||
|
||||
foreach my $database (@{$results}) {
|
||||
next if (defined($self->{option_results}->{filter_database}) && $self->{option_results}->{filter_database} ne ''
|
||||
&& $database->{tags}->{database} !~ /$self->{option_results}->{filter_database}/);
|
||||
|
||||
$self->{databases}->{$database->{tags}->{database}}->{display} = $database->{tags}->{database};
|
||||
|
||||
my $i = 0;
|
||||
foreach my $column (@{$database->{columns}}) {
|
||||
$column =~ s/influxdb_//;
|
||||
$self->{databases}->{$database->{tags}->{database}}->{$column} = $database->{values}[0][$i];
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
if (scalar(keys %{$self->{databases}}) <= 0) {
|
||||
$self->{output}->add_option_msg(short_msg => 'No databases found');
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check databases statistics
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--filter-database>
|
||||
|
||||
Filter database name (Can use regexp).
|
||||
|
||||
=item B<--warning-*>
|
||||
|
||||
Threshold warning.
|
||||
Can be: 'measurements', 'series'.
|
||||
|
||||
=item B<--critical-*>
|
||||
|
||||
Threshold warning.
|
||||
Can be: 'measurements', 'series'.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,189 @@
|
|||
#
|
||||
# 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::influxdb::mode::httpserverstatistics;
|
||||
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'global', type => 0 },
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{global} = [
|
||||
{ label => 'requests-query-count', nlabel => 'requests.query.count.persecond', set => {
|
||||
key_values => [ { name => 'queryReq', diff => 1 } ],
|
||||
per_second => 1,
|
||||
output_template => 'Query Requests: %.2f/s',
|
||||
perfdatas => [
|
||||
{ value => 'queryReq_per_second', template => '%.2f', min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'requests-write-count', nlabel => 'requests.write.count.persecond', set => {
|
||||
key_values => [ { name => 'writeReq', diff => 1 } ],
|
||||
per_second => 1,
|
||||
output_template => 'Write Requests: %.2f/s',
|
||||
perfdatas => [
|
||||
{ value => 'writeReq_per_second', template => '%.2f', min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'requests-ping-count', nlabel => 'requests.ping.count.persecond', set => {
|
||||
key_values => [ { name => 'pingReq', diff => 1 } ],
|
||||
per_second => 1,
|
||||
output_template => 'Ping Requests: %.2f/s',
|
||||
perfdatas => [
|
||||
{ value => 'pingReq_per_second', template => '%.2f', min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'requests-status-count', nlabel => 'requests.status.count.persecond', set => {
|
||||
key_values => [ { name => 'statusReq', diff => 1 } ],
|
||||
per_second => 1,
|
||||
output_template => 'Status Requests: %.2f/s',
|
||||
perfdatas => [
|
||||
{ value => 'statusReq_per_second', template => '%.2f', min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'requests-active', nlabel => 'requests.active.count', set => {
|
||||
key_values => [ { name => 'reqActive' } ],
|
||||
output_template => 'Active Requests: %d',
|
||||
perfdatas => [
|
||||
{ value => 'reqActive_absolute', template => '%d', min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'requests-write-active', nlabel => 'requests.write.active.count', set => {
|
||||
key_values => [ { name => 'writeReqActive' } ],
|
||||
output_template => 'Active Write Requests: %d',
|
||||
perfdatas => [
|
||||
{ value => 'writeReqActive_absolute', template => '%d', min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'requests-response-data', nlabel => 'requests.response.data.bytes', set => {
|
||||
key_values => [ { name => 'queryRespBytes', diff => 1 } ],
|
||||
per_second => 1,
|
||||
output_change_bytes => 1,
|
||||
output_template => 'Response Data: %s%s/s',
|
||||
perfdatas => [
|
||||
{ value => 'queryRespBytes_per_second', template => '%s', min => 0, unit => 'B/s' },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'requests-write-data', nlabel => 'requests.write.data.bytes', set => {
|
||||
key_values => [ { name => 'writeReqBytes', diff => 1 } ],
|
||||
per_second => 1,
|
||||
output_change_bytes => 1,
|
||||
output_template => 'Write Data: %s%s/s',
|
||||
perfdatas => [
|
||||
{ value => 'writeReqBytes_per_second', template => '%s', min => 0, unit => 'B/s' },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'errors-server', nlabel => 'errors.server.persecond', set => {
|
||||
key_values => [ { name => 'serverError', diff => 1 } ],
|
||||
per_second => 1,
|
||||
output_template => 'Server Errors: %.2f/s',
|
||||
perfdatas => [
|
||||
{ value => 'serverError_per_second', template => '%.2f', min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'errors-client', nlabel => 'errors.client.persecond', set => {
|
||||
key_values => [ { name => 'clientError', diff => 1 } ],
|
||||
per_second => 1,
|
||||
output_template => 'Client Errors: %.2f/s',
|
||||
perfdatas => [
|
||||
{ value => 'clientError_per_second', template => '%.2f', min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1, statefile => 1);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments => {});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{custom} = $options{custom};
|
||||
|
||||
$self->{global} = {};
|
||||
|
||||
my $results = $self->{custom}->query(queries => [ "SHOW STATS FOR 'httpd'" ]);
|
||||
|
||||
my $i = 0;
|
||||
foreach my $column (@{$$results[0]->{columns}}) {
|
||||
$column =~ s/influxdb_//;
|
||||
$self->{global}->{$column} = $$results[0]->{values}[0][$i];
|
||||
$i++;
|
||||
}
|
||||
|
||||
$self->{cache_name} = "influxdb_" . $self->{mode} . '_' . $self->{custom}->get_hostname() . '_' . $self->{custom}->get_port() . '_' .
|
||||
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check several statistics from the HTTP server serving API.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--warning-*>
|
||||
|
||||
Threshold warning.
|
||||
Can be: 'requests-query-count', 'requests-write-count',
|
||||
'requests-ping-count', 'requests-status-count', 'requests-active',
|
||||
'requests-write-active', 'requests-response-data',
|
||||
'requests-write-data', 'errors-server', 'errors-client'.
|
||||
|
||||
=item B<--critical-*>
|
||||
|
||||
Threshold critical.
|
||||
Can be: 'requests-query-count', 'requests-write-count',
|
||||
'requests-ping-count', 'requests-status-count', 'requests-active',
|
||||
'requests-write-active', 'requests-response-data',
|
||||
'requests-write-data', 'errors-server', 'errors-client'.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,98 @@
|
|||
#
|
||||
# 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::influxdb::mode::listdatabases;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments => {});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
$self->{custom} = $options{custom};
|
||||
|
||||
my $results = $self->{custom}->query(query => 'SHOW DATABASES');
|
||||
|
||||
foreach my $value (@{$$results[0]->{values}}) {
|
||||
push @{$self->{databases}}, $$value[0];
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->manage_selection(%options);
|
||||
|
||||
foreach my $database (sort @{$self->{databases}}) {
|
||||
$self->{output}->output_add(long_msg => sprintf("[name = %s]",
|
||||
$database));
|
||||
}
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => "List databases:");
|
||||
|
||||
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
sub disco_format {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{output}->add_disco_format(elements => ['name']);
|
||||
}
|
||||
|
||||
sub disco_show {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->manage_selection(%options);
|
||||
foreach my $database (sort @{$self->{databases}}) {
|
||||
$self->{output}->add_disco_entry(name => $database);
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
List databases.
|
||||
|
||||
=over 8
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,179 @@
|
|||
#
|
||||
# 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::influxdb::mode::query;
|
||||
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
|
||||
|
||||
sub custom_status_perfdata {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
foreach my $key (@{$self->{instance_mode}->{custom_keys}}) {
|
||||
$self->{output}->perfdata_add(
|
||||
label => $key,
|
||||
nlabel => $key,
|
||||
value => $self->{result_values}->{$key},
|
||||
instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
sub custom_status_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $msg = $self->{instance_mode}->{option_results}->{output};
|
||||
while ($msg =~ /%\{(.*?)\}/g) {
|
||||
my $key = $1;
|
||||
if (defined($self->{result_values}->{$key})) {
|
||||
$msg =~ s/%\{$key\}/$self->{result_values}->{$key}/g;
|
||||
}
|
||||
}
|
||||
|
||||
return $msg;
|
||||
}
|
||||
|
||||
sub custom_status_calc {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{result_values}->{instance} = $options{new_datas}->{$self->{instance} . '_instance'};
|
||||
foreach my $key (@{$self->{instance_mode}->{custom_keys}}) {
|
||||
$self->{result_values}->{$key} = $options{new_datas}->{$self->{instance} . '_' . $key};
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'queries_results', type => 1,
|
||||
message_multiple => 'All queries results are ok', skipped_code => { -11 => 1 } },
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{queries_results} = [
|
||||
{ label => 'status', set => {
|
||||
key_values => [ { name => 'instance' }, { name => 'display' } ],
|
||||
closure_custom_calc => $self->can('custom_status_calc'),
|
||||
closure_custom_output => $self->can('custom_status_output'),
|
||||
closure_custom_perfdata => $self->can('custom_status_perfdata'),
|
||||
closure_custom_threshold_check => \&catalog_status_threshold,
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments => {
|
||||
"query:s@" => { name => 'query' },
|
||||
"instance:s" => { name => 'instance' },
|
||||
"aggregation:s" => { name => 'aggregation', default => 'average' },
|
||||
"output:s" => { name => 'output' },
|
||||
"multiple-output:s" => { name => 'multiple_output' },
|
||||
"warning-status:s" => { name => 'warning_status', default => '' },
|
||||
"critical-status:s" => { name => 'critical_status', default => '' },
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::check_options(%options);
|
||||
|
||||
if (!defined($self->{option_results}->{output}) || $self->{option_results}->{output} eq '') {
|
||||
$self->{output}->add_option_msg(short_msg => "Need to specify --output option.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
if (!defined($self->{option_results}->{query})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Need to specify --query option.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$self->{custom_keys} = [];
|
||||
$self->{queries} = {};
|
||||
foreach my $query (@{$self->{option_results}->{query}}) {
|
||||
next if ($query !~ /^(\w+),(.*)/);
|
||||
$self->{queries}->{$1} = $2;
|
||||
push @{$self->{maps_counters}->{queries_results}[0]->{set}->{key_values}}, { name => $1 };
|
||||
push @{$self->{custom_keys}}, $1;
|
||||
}
|
||||
|
||||
$self->{maps_counters_type}[0]->{message_multiple} = $self->{option_results}->{multiple_output} if (defined($self->{option_results}->{multiple_output}));
|
||||
|
||||
$self->change_macros(macros => ['warning_status', 'critical_status']);
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{queries_results} = {};
|
||||
my (@results, @queries);
|
||||
|
||||
foreach my $label (keys %{$self->{queries}}) {
|
||||
push @queries, $self->{queries}->{$label};
|
||||
}
|
||||
|
||||
my $queries_results = $options{custom}->query(queries => \@queries) if (scalar(@queries) > 0);
|
||||
|
||||
foreach my $result (@{$queries_results}) {
|
||||
next if (!defined($result->{tags}->{$self->{option_results}->{instance}}));
|
||||
my $value;
|
||||
$value = $options{custom}->compute(aggregation => $self->{option_results}->{aggregation}, values => $result->{values}) if (defined($result->{values}));
|
||||
$value = ${$result->{value}}[1] if (defined($result->{value}));
|
||||
|
||||
$self->{queries_results}->{$result->{tags}->{$self->{option_results}->{instance}}}->{instance} = $result->{tags}->{$self->{option_results}->{instance}};
|
||||
$self->{queries_results}->{$result->{tags}->{$self->{option_results}->{instance}}}->{display} = $result->{tags}->{$self->{option_results}->{instance}};
|
||||
$self->{queries_results}->{$result->{tags}->{$self->{option_results}->{instance}}}->{$result->{columns}[1]} = $value;
|
||||
}
|
||||
|
||||
if (scalar(keys %{$self->{queries_results}}) <= 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "No queries found.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Launch queries.
|
||||
|
||||
Examples:
|
||||
|
||||
To come
|
||||
|
||||
=over 8
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,140 @@
|
|||
#
|
||||
# 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::influxdb::mode::writestatistics;
|
||||
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'global', type => 0 },
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{global} = [
|
||||
{ label => 'points-written', nlabel => 'points.written.persecond', set => {
|
||||
key_values => [ { name => 'pointReq', diff => 1 } ],
|
||||
per_second => 1,
|
||||
output_template => 'Points Written: %.2f/s',
|
||||
perfdatas => [
|
||||
{ value => 'pointReq_per_second', template => '%.2f', min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'writes-ok', nlabel => 'writes.ok.persecond', set => {
|
||||
key_values => [ { name => 'writeOk', diff => 1 } ],
|
||||
per_second => 1,
|
||||
output_template => 'Writes Ok: %.2f/s',
|
||||
perfdatas => [
|
||||
{ value => 'writeOk_per_second', template => '%.2f', min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'writes-error', nlabel => 'writes.error.persecond', set => {
|
||||
key_values => [ { name => 'writeError', diff => 1 } ],
|
||||
per_second => 1,
|
||||
output_template => 'Writes Error: %.2f/s',
|
||||
perfdatas => [
|
||||
{ value => 'writeError_per_second', template => '%.2f', min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'writes-drop', nlabel => 'writes.drop.persecond', set => {
|
||||
key_values => [ { name => 'writeDrop', diff => 1 } ],
|
||||
per_second => 1,
|
||||
output_template => 'Writes Drop: %.2f/s',
|
||||
perfdatas => [
|
||||
{ value => 'writeDrop_per_second', template => '%.2f', min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'writes-timeout', nlabel => 'writes.timeout.persecond', set => {
|
||||
key_values => [ { name => 'writeTimeout', diff => 1 } ],
|
||||
per_second => 1,
|
||||
output_template => 'Writes Timeout: %.2f/s',
|
||||
perfdatas => [
|
||||
{ value => 'writeTimeout_per_second', template => '%.2f', min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1, statefile => 1);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments => {});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{custom} = $options{custom};
|
||||
|
||||
$self->{global} = {};
|
||||
|
||||
my $results = $self->{custom}->query(queries => [ "SHOW STATS FOR 'write'" ]);
|
||||
|
||||
my $i = 0;
|
||||
foreach my $column (@{$$results[0]->{columns}}) {
|
||||
$column =~ s/influxdb_//;
|
||||
$self->{global}->{$column} = $$results[0]->{values}[0][$i];
|
||||
$i++;
|
||||
}
|
||||
|
||||
$self->{cache_name} = "influxdb_" . $self->{mode} . '_' . $self->{custom}->get_hostname() . '_' . $self->{custom}->get_port() . '_' .
|
||||
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check writes statistics to the data node.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--warning-*>
|
||||
|
||||
Threshold warning.
|
||||
Can be: 'points-written', 'writes-ok', 'writes-error',
|
||||
'writes-drop', 'writes-timeout'.
|
||||
|
||||
=item B<--critical-*>
|
||||
|
||||
Threshold critical.
|
||||
Can be: 'points-written', 'writes-ok', 'writes-error',
|
||||
'writes-drop', 'writes-timeout'.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,54 @@
|
|||
#
|
||||
# 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::influxdb::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} = '1.0';
|
||||
%{$self->{modes}} = (
|
||||
'connection-time' => 'database::influxdb::mode::connectiontime',
|
||||
'database-statistics' => 'database::influxdb::mode::databasestatistics',
|
||||
'http-server-statistics' => 'database::influxdb::mode::httpserverstatistics',
|
||||
'list-databases' => 'database::influxdb::mode::listdatabases',
|
||||
'query' => 'database::influxdb::mode::query',
|
||||
'write-statistics' => 'database::influxdb::mode::writestatistics',
|
||||
);
|
||||
|
||||
$self->{custom_modes}{api} = 'database::influxdb::custom::api';
|
||||
return $self;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 PLUGIN DESCRIPTION
|
||||
|
||||
Check InfluxDB server.
|
||||
|
||||
=cut
|
Loading…
Reference in New Issue