initial commit
This commit is contained in:
parent
5e9a05c2a2
commit
a1eec7c31f
|
@ -0,0 +1,243 @@
|
|||
#
|
||||
# Copyright 2020 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 apps::monitoring::netdata::restapi::custom::api;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use DateTime;
|
||||
use centreon::plugins::http;
|
||||
use centreon::plugins::statefile;
|
||||
use JSON::XS;
|
||||
use URI::Encode;
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
|
||||
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' },
|
||||
'timeout:s' => { name => 'timeout' },
|
||||
'reload-cache-time:s' => { name => 'reload_cache_time' },
|
||||
'endpoint:s' => { name => 'endpoint'},
|
||||
});
|
||||
}
|
||||
$options{options}->add_help(package => __PACKAGE__, sections => 'REST API 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} : 19999;
|
||||
$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->{endpoint} = (defined($self->{option_results}->{endpoint})) ? $self->{option_results}->{endpoint} : '/api/v1';
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
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} > 400';
|
||||
}
|
||||
|
||||
sub settings {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->build_options_for_httplib();
|
||||
$self->{http}->add_header(key => 'Accept', value => 'application/json');
|
||||
$self->{http}->set_options(%{$self->{option_results}});
|
||||
}
|
||||
|
||||
sub request_api {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->settings(content_type => 'application/x-www-form-urlencoded');
|
||||
|
||||
$self->{output}->output_add(long_msg => "URL: '" . $self->{proto} . '://' . $self->{hostname} . ':' . $self->{port} .
|
||||
$options{url_path} . "'", debug => 1);
|
||||
|
||||
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_code})) {
|
||||
$self->{output}->output_add(long_msg => "Error message : " . $decoded->{error}, debug => 1);
|
||||
$self->{output}->add_option_msg(short_msg => "API returns error code '" . $decoded->{error_code} . "' (add --debug option for detailed message)");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
return $decoded;
|
||||
}
|
||||
|
||||
sub get_alarms {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $url_path = $self->{endpoint} . '/alarms';
|
||||
my $response = $self->request_api(method => 'GET', url_path => $url_path);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
sub list_charts {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $url_path = $self->{endpoint} . '/charts';
|
||||
my $response = $self->request_api(method => 'GET', url_path => $url_path);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
sub get_chart_properties {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $url_path = $self->{endpoint} . '/chart';
|
||||
$url_path .= '?chart=' . $options{chart};
|
||||
my $response = $self->request_api(method => 'GET', url_path => $url_path);
|
||||
my $filter_info = defined ($options{filter_info}) ? $options{filter_info} : '';
|
||||
|
||||
return defined ($filter_info) ? $response->{$filter_info} : $response;
|
||||
}
|
||||
|
||||
sub get_data {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $url_path = $self->{endpoint} . '/data';
|
||||
$url_path .= '?chart=' . $options{chart};
|
||||
$url_path .= '&options=null2zero';
|
||||
$url_path .= '&options=abs' if defined ($options{absolute});
|
||||
$url_path .= '&after=-' . $options{after_period};
|
||||
$url_path .= '&group=' . $options{group};
|
||||
$url_path .= defined ($options{points}) ? '&points=' . $options{points} : '&points=1';
|
||||
$url_path .= '&dimensions=' . $options{dimensions} if defined ($options{dimensions});
|
||||
my $response = $self->request_api(method => 'GET', url_path => $url_path),;
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
sub get_info {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $url_path = $self->{endpoint} . '/info';
|
||||
my $response = $self->request_api(method => 'GET', url_path => $url_path);
|
||||
my $filter_info = defined ($options{filter_info}) ? $options{filter_info} : '';
|
||||
return defined ($filter_info) ? $response->{$filter_info} : $response;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Netdata Rest API
|
||||
|
||||
=head1 REST API OPTIONS
|
||||
|
||||
Netdata Rest API
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--hostname>
|
||||
|
||||
Netdata API hostname (server address)
|
||||
|
||||
=item B<--port>
|
||||
|
||||
Port used (Default: 19999)
|
||||
|
||||
=item B<--proto>
|
||||
|
||||
Specify https if needed (Default: 'http')
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Set timeout in seconds (Default: 10).
|
||||
|
||||
=back
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
B<custom>.
|
||||
|
||||
=cut
|
|
@ -0,0 +1,162 @@
|
|||
#
|
||||
# Copyright 2020 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and alarm 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 apps::monitoring::netdata::restapi::mode::alarms;
|
||||
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc);
|
||||
|
||||
sub custom_status_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return sprintf('Status: %s, Current state: %s', $self->{result_values}->{status}, $self->{result_values}->{value_string});
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' },
|
||||
{ name => 'alarms', type => 1, cb_prefix_output => 'prefix_alarm_output', message_multiple => 'No current alarms' }
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{global} = [
|
||||
{ label => 'alarms-total', nlabel => 'netdata.alarms.current.total.count', set => {
|
||||
key_values => [ { name => 'total' } ],
|
||||
output_template => "%s",
|
||||
perfdatas => [ { value => 'total', template => '%d', min => 0 } ]
|
||||
}
|
||||
},
|
||||
{ label => 'alarms-warning', nlabel => 'netdata.alarms.current.warning.count', set => {
|
||||
key_values => [ { name => 'warning' } ],
|
||||
output_template => "Warning Alarms : %s",
|
||||
perfdatas => [ { value => 'warning', template => '%d', min => 0 } ],
|
||||
}
|
||||
},
|
||||
{ label => 'alarms-critical', nlabel => 'netdata.alarms.current.critical.count', set => {
|
||||
key_values => [ { name => 'critical' } ],
|
||||
output_template => "Critical Alarms : %s",
|
||||
perfdatas => [ { value => 'critical', template => '%d', min => 0 } ],
|
||||
}
|
||||
},
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{alarms} = [
|
||||
{ label => 'alarm', threshold => 0, set => {
|
||||
key_values => [ { name => 'display' }, { name => 'name' }, { name => 'status' }, { name => 'value_string'} ],
|
||||
closure_custom_calc => \&catalog_status_calc,
|
||||
closure_custom_output => $self->can('custom_status_output'),
|
||||
closure_custom_perfdata => sub { return 0; },
|
||||
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;
|
||||
|
||||
$options{options}->add_options(arguments => {
|
||||
'filter-status:s' => { name => 'filter_status' },
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::check_options(%options);
|
||||
}
|
||||
|
||||
sub prefix_global_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Total alarms ";
|
||||
}
|
||||
|
||||
sub prefix_alarm_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Alarm on '" . $options{instance_value}->{name} . "' ";
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{alarms} = {};
|
||||
my $result = $options{custom}->get_alarms();
|
||||
foreach my $alarm (values %{$result->{alarms}}) {
|
||||
next if ( defined($self->{option_results}->{filter_status})
|
||||
&& $self->{option_results}->{filter_status} ne ''
|
||||
&& $alarm->{status} !~ /$self->{option_results}->{filter_status}/ );
|
||||
$self->{alarms}->{$alarm} = {
|
||||
display => $alarm,
|
||||
id => $alarm->{id},
|
||||
name => $alarm->{name},
|
||||
chart => $alarm->{chart},
|
||||
status => $alarm->{status},
|
||||
value_string => $alarm->{value_string}
|
||||
};
|
||||
|
||||
$self->{global}->{warning}++ if $alarm->{status} =~ m/WARNING/;
|
||||
$self->{global}->{critical}++ if $alarm->{status} =~ m/CRITICAL/;
|
||||
}
|
||||
|
||||
$self->{global}->{total} = scalar (keys %{$self->{alarms}});
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check Netdata agent current active alarms.
|
||||
|
||||
Example:
|
||||
perl centreon_plugins.pl --plugin=apps::monitoring::netdata::restapi::plugin
|
||||
--mode=alarms --hostname=10.0.0.1 --warning-alarms-warning=0 --critical-alarms-critical=0--verbose
|
||||
|
||||
More information on 'https://learn.netdata.cloud/docs/agent/web/api''.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--filter-status>
|
||||
|
||||
Filter on specific alarm status.
|
||||
Can be 'WARNING' or 'CRITICAL'
|
||||
(Default: both status shown)
|
||||
|
||||
=item B<--warning-alarms-*>
|
||||
|
||||
Set Warning threshold for alarms count (Default: '') where '*' can be warning or 'critical'
|
||||
|
||||
=item B<--critical-alarms-*>
|
||||
|
||||
Set Critical threshold for alarms count (Default: '') where '*' can be 'warning' or 'critical'
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,168 @@
|
|||
#
|
||||
# Copyright 2020 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and alarm 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 apps::monitoring::netdata::restapi::mode::cpu;
|
||||
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'cpu_avg', type => 0, cb_prefix_output => 'prefix_cpu_avg_output' },
|
||||
{ name => 'cpu_results', type => 1, cb_prefix_output => 'prefix_cpu_core_output' }
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{cpu_avg} = [
|
||||
{ label => 'average', nlabel => 'cpu.utilization.percentage', set => {
|
||||
key_values => [ { name => 'average' }, { name => 'count' } ],
|
||||
output_template => '%.2f %%',
|
||||
perfdatas => [
|
||||
{ label => 'total_cpu_avg', value => 'average', template => '%.2f',
|
||||
min => 0, max => 100, unit => '%' },
|
||||
],
|
||||
}
|
||||
},
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{cpu_results} = [
|
||||
{ label => 'core', nlabel => 'core.cpu.utilization.percentage', set => {
|
||||
key_values => [ { name => 'usage' }, { name => 'display' } ],
|
||||
output_template => 'usage : %.2f %%',
|
||||
perfdatas => [
|
||||
{ label => 'cpu', value => 'usage', template => '%.2f',
|
||||
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display' },
|
||||
],
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
sub prefix_cpu_avg_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return $self->{cpu_avg}->{count} . " CPU(s) average usage is ";
|
||||
}
|
||||
|
||||
sub prefix_cpu_core_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "CPU '" . $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 => {
|
||||
'chart-period:s' => { name => 'chart_period', default => '300' },
|
||||
'chart-statistics:s' => { name => 'chart_statistics', default => 'average' },
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::check_options(%options);
|
||||
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $cpu_total_usage;
|
||||
my $cpu_number = $options{custom}->get_info(filter_info => 'cores_total');
|
||||
foreach (my $i = 0; $i < $cpu_number; $i++) {
|
||||
my $cpu_core = 'cpu.cpu' . $i;
|
||||
my $result = $options{custom}->get_data(
|
||||
chart => $cpu_core,
|
||||
points => $self->{option_results}->{chart_point},
|
||||
after_period => $self->{option_results}->{chart_period},
|
||||
group => $self->{option_results}->{chart_statistics}
|
||||
);
|
||||
foreach my $cpu_value (@{$result->{data}}) {
|
||||
foreach my $cpu_label (@{$result->{labels}}) {
|
||||
$self->{cpu_core}->{$i}->{$cpu_label} = shift @{$cpu_value};
|
||||
}
|
||||
}
|
||||
$self->{cpu_results}->{$i} = {
|
||||
display => $cpu_core,
|
||||
usage => $self->{cpu_core}->{$i}->{user}
|
||||
};
|
||||
$cpu_total_usage += $self->{cpu_results}->{$i}->{usage};
|
||||
}
|
||||
my $avg_cpu = $cpu_total_usage / $cpu_number;
|
||||
$self->{cpu_avg} = {
|
||||
average => $avg_cpu,
|
||||
count => $cpu_number
|
||||
};
|
||||
};
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check *nix based servers CPU using the Netdata agent RestAPI.
|
||||
|
||||
Example:
|
||||
perl centreon_plugins.pl --plugin=apps::monitoring::netdata::restapi::plugin
|
||||
--mode=cpu --hostname=10.0.0.1 --chart-period=300 --warning-average=70 --critical-average=80 --verbose
|
||||
|
||||
More information on 'https://learn.netdata.cloud/docs/agent/web/api'.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--chart-period>
|
||||
|
||||
The period in seconds on which the values are calculated
|
||||
Default: 300
|
||||
|
||||
=item B<--chart-statistic>
|
||||
|
||||
The statistic calculation method used to parse the collected data.
|
||||
Can be : average, sum, min, max
|
||||
Default: average
|
||||
|
||||
=item B<--warning-average>
|
||||
|
||||
Warning threshold on average CPU utilization.
|
||||
|
||||
=item B<--critical-average>
|
||||
|
||||
Critical threshold on average CPU utilization.
|
||||
|
||||
=item B<--warning-core>
|
||||
|
||||
Warning threshold for each CPU core
|
||||
|
||||
=item B<--critical-core>
|
||||
|
||||
Critical threshold for each CPU core
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,243 @@
|
|||
#
|
||||
# Copyright 2020 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 apps::monitoring::netdata::restapi::mode::diskusage;
|
||||
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
sub custom_usage_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total});
|
||||
my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
|
||||
my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
|
||||
return sprintf(
|
||||
'Usage - Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)',
|
||||
$total_size_value . " " . $total_size_unit,
|
||||
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
|
||||
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}
|
||||
);
|
||||
}
|
||||
|
||||
sub prefix_diskpath_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Partition '" . $options{instance_value}->{display} . "' ";
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'global', type => 0 },
|
||||
{ name => 'diskpath', type => 1, cb_prefix_output => 'prefix_diskpath_output', message_multiple => 'All partitions are ok' },
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{global} = [
|
||||
{ label => 'count', nlabel => 'storage.partitions.count', display_ok => 0, set => {
|
||||
key_values => [ { name => 'count' } ],
|
||||
output_template => 'Partitions count : %d',
|
||||
perfdatas => [ { label => 'count', value => 'count', template => '%d', min => 0 } ]
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{diskpath} = [
|
||||
{ label => 'usage', nlabel => 'storage.space.usage.bytes', set => {
|
||||
key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' }, { name => 'display' } ],
|
||||
closure_custom_output => $self->can('custom_usage_output'),
|
||||
perfdatas => [
|
||||
{ label => 'used', value => 'used', template => '%d', min => 0, max => 'total',
|
||||
unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display' }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'free', display_ok => 0, nlabel => 'storage.space.free.bytes', set => {
|
||||
key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' }, { name => 'display' } ],
|
||||
closure_custom_output => $self->can('custom_usage_output'),
|
||||
perfdatas => [
|
||||
{ label => 'free', value => 'free', template => '%d', min => 0, max => 'total',
|
||||
unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display' }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'usage-prct', display_ok => 0, nlabel => 'storage.space.usage.percentage', set => {
|
||||
key_values => [ { name => 'prct_used' }, { name => 'display' } ],
|
||||
output_template => 'Used : %.2f %%',
|
||||
perfdatas => [
|
||||
{ label => 'used_prct', value => 'prct_used', template => '%.2f', min => 0, max => 100,
|
||||
unit => '%', label_extra_instance => 1, instance_use => '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 => {
|
||||
'chart-period:s' => { name => 'chart_period', default => '300' },
|
||||
'chart-statistics:s' => { name => 'chart_statistics', default => 'average' },
|
||||
'fs-name:s' => { name => 'fs_name' },
|
||||
'space-reservation' => { name => 'space_reservation'}
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::check_options(%options);
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $full_list = $options{custom}->list_charts();
|
||||
|
||||
foreach my $chart (values %{$full_list->{charts}}) {
|
||||
next if ($chart->{name} !~ 'disk_space._');
|
||||
push @{$self->{fs_list}}, $chart->{name};
|
||||
}
|
||||
|
||||
foreach my $fs (@{$self->{fs_list}}) {
|
||||
my $result = $options{custom}->get_data(
|
||||
chart => $fs,
|
||||
dimensions => 'used,avail,reserved_for_root',
|
||||
points => $self->{option_results}->{chart_point},
|
||||
after_period => $self->{option_results}->{chart_period},
|
||||
group => $self->{option_results}->{chart_statistics}
|
||||
);
|
||||
|
||||
$fs =~ s/disk_space.//;
|
||||
$fs =~ s/_/\//g;
|
||||
|
||||
next if (defined($self->{option_results}->{fs_name}) &&
|
||||
$self->{option_results}->{fs_name} ne '' &&
|
||||
$fs !~ /$self->{option_results}->{fs_name}/
|
||||
);
|
||||
|
||||
foreach my $fs_value (@{$result->{data}}) {
|
||||
foreach my $fs_label (@{$result->{labels}}) {
|
||||
$self->{fs}->{$fs}->{$fs_label} = shift @{$fs_value};
|
||||
}
|
||||
}
|
||||
|
||||
my $reserved_space = defined($self->{option_results}->{space_reservation}) ? $self->{fs}->{$fs}->{"reserved for root"} * (1024 ** 3) : '0';
|
||||
my $used = $self->{fs}->{$fs}->{used} * (1024 ** 3);
|
||||
my $free = $self->{fs}->{$fs}->{avail} * (1024 ** 3);
|
||||
my $total = $used + $free + $reserved_space;
|
||||
my $prct_used = $used * 100 / $total;
|
||||
my $prct_free = 100 - $prct_used;
|
||||
|
||||
if ($prct_used > 100) {
|
||||
$free = 0;
|
||||
$prct_used = 100;
|
||||
$prct_free = 0;
|
||||
}
|
||||
|
||||
$self->{diskpath}->{$fs} = {
|
||||
display => $fs,
|
||||
used => $used,
|
||||
total => $total,
|
||||
free => $free,
|
||||
prct_used => $prct_used,
|
||||
prct_free => $prct_free
|
||||
};
|
||||
$self->{global}->{count}++;
|
||||
}
|
||||
|
||||
if (scalar(keys %{$self->{diskpath}}) <= 0) {
|
||||
$self->{output}->add_option_msg(short_msg => 'Issue with disk path information (see details)');
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
};
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check disks FS usage of *nix based servers using the Netdata agent RestAPI.
|
||||
|
||||
Example:
|
||||
perl centreon_plugins.pl --plugin=apps::monitoring::netdata::restapi::plugin
|
||||
--mode=diskusage --hostname=10.0.0.1 --chart-period=300 --chart-statistics=average --warning-usage-prct=80 --critical-usage-prct=90 --verbose
|
||||
|
||||
More information on'https://learn.netdata.cloud/docs/agent/web/api'.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--chart-period>
|
||||
|
||||
The period in seconds on which the values are calculated
|
||||
Default: 300
|
||||
|
||||
=item B<--chart-statistic>
|
||||
|
||||
The statistic calculation method used to parse the collected data.
|
||||
Can be : average, sum, min, max
|
||||
Default: average
|
||||
|
||||
=item B<--fs-name>
|
||||
|
||||
Filter on one or more specific FS. Regexp can be used
|
||||
Example: --fs-name='(^/$|^/boot$)'
|
||||
|
||||
=item B<--warning-usage>
|
||||
|
||||
Warning threshold on FS space usage (in B).
|
||||
|
||||
=item B<--critical-usage>
|
||||
|
||||
Critical threshold on FS space usage (in B).
|
||||
|
||||
=item B<--warning-usage-prct>
|
||||
|
||||
Warning threshold on FS percentage space usage (in %).
|
||||
|
||||
=item B<--critical-usage-prct>
|
||||
|
||||
Critical threshold on FS percentage space usage (in %).
|
||||
|
||||
=item B<--warning-free>
|
||||
|
||||
Warning threshold on FS free space.
|
||||
|
||||
=item B<--critical-free>
|
||||
|
||||
Critical threshold on FS free space.
|
||||
|
||||
=item B<--space-reservation>
|
||||
|
||||
On specific systems, partitions can have reserved space (like ext4 for root).
|
||||
This option will consider this space in the calculation (like for the 'df' command).
|
||||
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,205 @@
|
|||
#
|
||||
# Copyright 2020 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and alarm 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 apps::monitoring::netdata::restapi::mode::getchart;
|
||||
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc);
|
||||
|
||||
sub custom_metric_perfdata {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{output}->perfdata_add(
|
||||
label => $self->{result_values}->{perf_label},
|
||||
value => $self->{result_values}->{value},
|
||||
unit => $self->{result_values}->{unit},
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-metric'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-metric'),
|
||||
);
|
||||
}
|
||||
|
||||
sub custom_metric_threshold {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $exit = $self->{perfdata}->threshold_check(
|
||||
value => $self->{result_values}->{value},
|
||||
threshold => [
|
||||
{ label => 'critical-metric', exit_litteral => 'critical' },
|
||||
{ label => 'warning-metric', exit_litteral => 'warning' }
|
||||
]
|
||||
);
|
||||
return $exit;
|
||||
}
|
||||
|
||||
sub custom_metric_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return sprintf(
|
||||
"Metric '%s' value is %.2f %s",
|
||||
$self->{result_values}->{display}, $self->{result_values}->{value}, $self->{result_values}->{unit}
|
||||
);
|
||||
}
|
||||
|
||||
sub custom_metric_calc {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{result_values}->{value} = $options{new_datas}->{$self->{instance} . '_value'};
|
||||
$self->{result_values}->{perf_label} = $options{new_datas}->{$self->{instance} . '_perf_label'};
|
||||
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
|
||||
$self->{result_values}->{unit} = $options{new_datas}->{$self->{instance} . '_unit'};
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'metric', type => 1, message_multiple => 'All metrics are ok' },
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{metric} = [
|
||||
{ label => 'metric', set => {
|
||||
key_values => [ { name => 'value' }, { name => 'perf_label' }, { name => 'display' }, { name => 'unit' } ],
|
||||
closure_custom_calc => $self->can('custom_metric_calc'),
|
||||
closure_custom_output => $self->can('custom_metric_output'),
|
||||
closure_custom_perfdata => $self->can('custom_metric_perfdata'),
|
||||
closure_custom_threshold_check => $self->can('custom_metric_threshold'),
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
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 => {
|
||||
'chart-name:s' => { name => 'chart_name' },
|
||||
'chart-period:s' => { name => 'chart_period', default => '300' },
|
||||
'chart-statistics:s' => { name => 'chart_statistics', default => 'average' },
|
||||
'filter-metric:s' => { name => 'filter_metric' }
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::check_options(%options);
|
||||
|
||||
if (!defined($self->{option_results}->{chart_name}) || $self->{option_results}->{chart_name} eq '') {
|
||||
$self->{output}->add_option_msg(short_msg => "Missing --chart-name option or value.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
my $dimensions = '';
|
||||
|
||||
if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne '') {
|
||||
$dimensions = $self->{option_results}->{filter_metric}
|
||||
};
|
||||
|
||||
my $unit = $options{custom}->get_chart_properties(chart => $self->{option_results}->{chart_name}, filter_info => 'units');
|
||||
my $result = $options{custom}->get_data(
|
||||
chart => $self->{option_results}->{chart_name},
|
||||
points => $self->{option_results}->{chart_point},
|
||||
after_period => $self->{option_results}->{chart_period},
|
||||
group => $self->{option_results}->{chart_statistics},
|
||||
dimensions => $dimensions
|
||||
);
|
||||
|
||||
my $chart_name = $self->{option_results}->{chart_name};
|
||||
my $stat = $self->{option_results}->{chart_statistics};
|
||||
|
||||
foreach my $chart_value (@{$result->{data}}) {
|
||||
foreach my $chart_label (@{$result->{labels}}) {
|
||||
$self->{metrics}->{$chart_name}->{$chart_label} = shift @{$chart_value};
|
||||
}
|
||||
}
|
||||
foreach my $metric (keys %{$self->{metrics}->{$chart_name}}) {
|
||||
next if $metric eq 'time';
|
||||
foreach my $value (values %{$self->{metrics}->{$chart_name}}) {
|
||||
$self->{metric}->{$metric . '_' . $stat} = {
|
||||
display => $metric . '_' . $stat,
|
||||
value => $value,
|
||||
unit => $unit,
|
||||
perf_label => $metric . '_' . $stat,
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Get data for charts available on the Netdata RestAPI.
|
||||
|
||||
Example:
|
||||
perl centreon_plugins.pl --plugin=apps::monitoring::netdata::restapi::plugin
|
||||
--mode=get-chart --hostname=10.0.0.1 --chart-name='system.cpu' --filter-metric=iowait
|
||||
|
||||
More information on'https://learn.netdata.cloud/docs/agent/web/api'.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--chart-name>
|
||||
|
||||
The Netdata chart name to query
|
||||
This option is mandatory
|
||||
|
||||
=item B<--chart-period>
|
||||
|
||||
The period in seconds on which the values are calculated
|
||||
Default: 300
|
||||
|
||||
=item B<--chart-statistic>
|
||||
|
||||
The statistic calculation method used to parse the collected data.
|
||||
Can be : average, sum, min, max
|
||||
Default: average
|
||||
|
||||
=item B<--filter-metric>
|
||||
|
||||
Filter on specific chart metric.
|
||||
By default, all the metrics will be displayed
|
||||
|
||||
=item B<--warning-metric>
|
||||
|
||||
Warning threshold (global to all the collected metrics)
|
||||
|
||||
=item B<--critical-metric>
|
||||
|
||||
Critical threshold (global to all the collected metrics)
|
||||
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,179 @@
|
|||
#
|
||||
# Copyright 2020 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 apps::monitoring::netdata::restapi::mode::inodes;
|
||||
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'inodes', type => 1, cb_prefix_output => 'prefix_inodes_output', message_multiple => 'All inode partitions are ok' }
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{inodes} = [
|
||||
{ label => 'usage-prct', nlabel => 'storage.inodes.usage.percentage', set => {
|
||||
key_values => [ { name => 'prct_used' }, { name => 'display' } ],
|
||||
output_template => 'Used: %.2f %%',
|
||||
perfdatas => [
|
||||
{ label => 'prct_used', value => 'prct_used', template => '%d',
|
||||
unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' },
|
||||
],
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
sub prefix_inodes_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Inodes partition '" . $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 => {
|
||||
'chart-period:s' => { name => 'chart_period', default => '300' },
|
||||
'chart-statistics:s' => { name => 'chart_statistics', default => 'average' },
|
||||
'fs-name:s' => { name => 'fs_name' },
|
||||
'space-reservation' => { name => 'space_reservation'}
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::check_options(%options);
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $full_list = $options{custom}->list_charts();
|
||||
|
||||
foreach my $chart (values %{$full_list->{charts}}) {
|
||||
next if ($chart->{name} !~ 'disk_inodes._');
|
||||
push @{$self->{fs_list}}, $chart->{name};
|
||||
}
|
||||
|
||||
foreach my $fs (@{$self->{fs_list}}) {
|
||||
my $result = $options{custom}->get_data(
|
||||
chart => $fs,
|
||||
dimensions => 'used,avail,reserved_for_root',
|
||||
points => $self->{option_results}->{chart_point},
|
||||
after_period => $self->{option_results}->{chart_period},
|
||||
group => $self->{option_results}->{chart_statistics}
|
||||
);
|
||||
|
||||
$fs =~ s/disk_inodes.//;
|
||||
$fs =~ s/_/\//g;
|
||||
|
||||
next if (defined($self->{option_results}->{fs_name}) &&
|
||||
$self->{option_results}->{fs_name} ne '' &&
|
||||
$fs !~ /$self->{option_results}->{fs_name}/
|
||||
);
|
||||
|
||||
foreach my $fs_value (@{$result->{data}}) {
|
||||
foreach my $fs_label (@{$result->{labels}}) {
|
||||
$self->{fs}->{$fs}->{$fs_label} = shift @{$fs_value};
|
||||
}
|
||||
}
|
||||
|
||||
my $reserved_space = defined($self->{option_results}->{space_reservation}) ? $self->{fs}->{$fs}->{"reserved for root"} : '0';
|
||||
my $used = $self->{fs}->{$fs}->{used};
|
||||
my $free = $self->{fs}->{$fs}->{avail};
|
||||
my $total = $used + $free + $reserved_space;
|
||||
my $prct_used = $used * 100 / $total;
|
||||
my $prct_free = 100 - $prct_used;
|
||||
|
||||
$self->{inodes}->{$fs} = {
|
||||
display => $fs,
|
||||
used => $used,
|
||||
total => $total,
|
||||
free => $free,
|
||||
prct_used => $prct_used,
|
||||
prct_free => $prct_free
|
||||
};
|
||||
$self->{global}->{count}++;
|
||||
}
|
||||
|
||||
if (scalar(keys %{$self->{inodes}}) <= 0) {
|
||||
$self->{output}->add_option_msg(short_msg => 'Issue with disk path information (see details)');
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
};
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check disks FS inodes of *nix based servers using the Netdata agent RestAPI.
|
||||
|
||||
Example:
|
||||
perl centreon_plugins.pl --plugin=apps::monitoring::netdata::restapi::plugin
|
||||
--mode=inodes --hostname=10.0.0.1 --chart-period=300 --chart-statistics=average --warning-usage-prct=80 --critical-usage-prct=90 --verbose
|
||||
|
||||
More information on'https://learn.netdata.cloud/docs/agent/web/api'.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--chart-period>
|
||||
|
||||
The period in seconds on which the values are calculated
|
||||
Default: 300
|
||||
|
||||
=item B<--chart-statistic>
|
||||
|
||||
The statistic calculation method used to parse the collected data.
|
||||
Can be : average, sum, min, max
|
||||
Default: average
|
||||
|
||||
=item B<--fs-name>
|
||||
|
||||
Filter on one or more specific FS. Regexp can be used
|
||||
Example: --fs-name='(^/$|^/boot$)'
|
||||
|
||||
=item B<--warning-usage-prct>
|
||||
|
||||
Warning threshold on FS used Inodes (in %).
|
||||
|
||||
=item B<--critical-usage-prct>
|
||||
|
||||
Critical threshold on FS used Inodes (in %).
|
||||
|
||||
=item B<--space-reservation>
|
||||
|
||||
On specific systems, partitions can have reserved space/inodes (like ext4 for root).
|
||||
This option will consider this space in the calculation (like for the 'df' command).
|
||||
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,104 @@
|
|||
#
|
||||
# Copyright 2020 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 apps::monitoring::netdata::restapi::mode::listcharts;
|
||||
|
||||
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;
|
||||
|
||||
$options{options}->add_options(arguments => {
|
||||
'filter-chart:s' => { name => 'filter_chart' },
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $result = $options{custom}->list_charts();
|
||||
|
||||
foreach my $chart (values %{$result->{charts}}) {
|
||||
next if (defined($self->{option_results}->{filter_chart}) && $self->{option_results}->{filter_chart} ne ''
|
||||
&& $chart->{title} !~ /$self->{option_results}->{filter_chart}/);
|
||||
|
||||
$self->{output}->output_add(
|
||||
long_msg => sprintf(
|
||||
"[name = %s][title = %s][units = %s]",
|
||||
$chart->{name},
|
||||
$chart->{title},
|
||||
$chart->{units},
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$self->{output}->output_add(severity => 'OK', short_msg => 'Netdata Available Charts:');
|
||||
$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', 'title', 'units']);
|
||||
}
|
||||
|
||||
sub disco_show {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->run(%options);
|
||||
foreach my $chart (@{$self->{charts}}) {
|
||||
$self->{output}->add_disco_entry(
|
||||
name => $chart->{name},
|
||||
title => $chart->{title},
|
||||
units => $chart->{units},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
List available Netdata charts.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--filter-chart>
|
||||
|
||||
Filter on specific chart(s). Regexp can be used.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,145 @@
|
|||
#
|
||||
# Copyright 2020 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and alarm 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 apps::monitoring::netdata::restapi::mode::loadaverage;
|
||||
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
sub prefix_load_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Load average ";
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'loadaverage', type => 0, message_separator => ' - ', skipped_code => { -10 => 1 }, cb_prefix_output => 'prefix_load_output' }
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{loadaverage} = [
|
||||
{ label => 'load1', nlabel => 'system.loadaverage.1m.value', set => {
|
||||
key_values => [ { name => 'load1' } ],
|
||||
output_template => '%.2f (1m)',
|
||||
perfdatas => [
|
||||
{ label => 'load1', template => '%.2f', min => 0 }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'load5', nlabel => 'system.loadaverage.5m.value', set => {
|
||||
key_values => [ { name => 'load5' } ],
|
||||
output_template => '%.2f (5m)',
|
||||
perfdatas => [
|
||||
{ label => 'load5', template => '%.2f', min => 0 }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'load15', nlabel => 'system.loadaverage.15m.value', set => {
|
||||
key_values => [ { name => 'load15' }, { name => 'load1' }, { name => 'load5' } ],
|
||||
output_template => '%.2f (15m)',
|
||||
perfdatas => [
|
||||
{ label => 'load15', template => '%.2f', min => 0 }
|
||||
]
|
||||
}
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
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 => {
|
||||
'chart-period:s' => { name => 'chart_period', default => '300' },
|
||||
'chart-statistics:s' => { name => 'chart_statistics', default => 'average' },
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::check_options(%options);
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
my $result = $options{custom}->get_data(
|
||||
chart => 'system.load',
|
||||
points => $self->{option_results}->{chart_point},
|
||||
after_period => $self->{option_results}->{chart_period},
|
||||
group => $self->{option_results}->{chart_statistics}
|
||||
);
|
||||
foreach my $load_value (@{$result->{data}}) {
|
||||
foreach my $load_label (@{$result->{labels}}) {
|
||||
$self->{load_data}->{$load_label} = shift @{$load_value};
|
||||
}
|
||||
}
|
||||
|
||||
$self->{loadaverage} = {
|
||||
load1 => $self->{load_data}->{load1},
|
||||
load5 => $self->{load_data}->{load5},
|
||||
load15 => $self->{load_data}->{load15}
|
||||
};
|
||||
};
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check the average load of *nix based servers using the Netdata agent RestAPI.
|
||||
|
||||
Example:
|
||||
perl centreon-plugins/centreon_plugins.pl --plugin=apps::monitoring::netdata::restapi::plugin
|
||||
--mode=loadaverage --hostname=10.0.0.1 --chart-period=300 --warning-load15='4' --critical-load15='5' --verbose
|
||||
|
||||
More information on 'https://learn.netdata.cloud/docs/agent/web/api'.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--chart-period>
|
||||
|
||||
The period in seconds on which the values are calculated.
|
||||
Default: 300
|
||||
|
||||
=item B<--chart-statistic>
|
||||
|
||||
The statistic calculation method used to parse the collected data.
|
||||
Can be : average, sum, min, max.
|
||||
Default: average
|
||||
|
||||
=item B<--warning-*>
|
||||
|
||||
Warning threshold where '*' can be: load1, load5, load15
|
||||
|
||||
=item B<--critical-*>
|
||||
|
||||
Critical threshold where '*' can be: load1, load5, load15
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,219 @@
|
|||
#
|
||||
# Copyright 2020 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and alarm 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 apps::monitoring::netdata::restapi::mode::memory;
|
||||
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
sub custom_usage_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return sprintf(
|
||||
'Ram Total: %s %s Used (-buffers/cache): %s %s (%.2f%%) Free: %s %s (%.2f%%)',
|
||||
$self->{perfdata}->change_bytes(value => $self->{result_values}->{total}),
|
||||
$self->{perfdata}->change_bytes(value => $self->{result_values}->{used}),
|
||||
$self->{result_values}->{prct_used},
|
||||
$self->{perfdata}->change_bytes(value => $self->{result_values}->{free}),
|
||||
$self->{result_values}->{prct_free}
|
||||
);
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'ram', type => 0, skipped_code => { -10 => 1 } },
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{ram} = [
|
||||
{ label => 'usage', nlabel => 'memory.usage.bytes', set => {
|
||||
key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ],
|
||||
closure_custom_output => $self->can('custom_usage_output'),
|
||||
perfdatas => [
|
||||
{ label => 'used', template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1 }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'usage-free', display_ok => 0, nlabel => 'memory.free.bytes', set => {
|
||||
key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ],
|
||||
closure_custom_output => $self->can('custom_usage_output'),
|
||||
perfdatas => [
|
||||
{ label => 'free', template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1 }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'usage-prct', display_ok => 0, nlabel => 'memory.usage.percentage', set => {
|
||||
key_values => [ { name => 'prct_used' } ],
|
||||
output_template => 'Ram Used : %.2f %%',
|
||||
perfdatas => [
|
||||
{ label => 'used_prct', template => '%.2f', min => 0, max => 100, unit => '%' }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'buffer', nlabel => 'memory.buffer.bytes', set => {
|
||||
key_values => [ { name => 'buffers' } ],
|
||||
output_template => 'Buffer: %s %s',
|
||||
output_change_bytes => 1,
|
||||
perfdatas => [
|
||||
{ label => 'buffer', template => '%d', min => 0, unit => 'B' }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'cached', nlabel => 'memory.cached.bytes', set => {
|
||||
key_values => [ { name => 'cached' } ],
|
||||
output_template => 'Cached: %s %s',
|
||||
output_change_bytes => 1,
|
||||
perfdatas => [
|
||||
{ label => 'cached', template => '%d', min => 0, unit => 'B' }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'shared', nlabel => 'memory.shared.bytes', set => {
|
||||
key_values => [ { name => 'memShared' } ],
|
||||
output_template => 'Shared: %s %s',
|
||||
output_change_bytes => 1,
|
||||
perfdatas => [
|
||||
{ label => 'shared', template => '%d', min => 0, unit => 'B' }
|
||||
]
|
||||
}
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
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 => {
|
||||
'chart-period:s' => { name => 'chart_period', default => '300' },
|
||||
'chart-statistics:s' => { name => 'chart_statistics', default => 'average' },
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::check_options(%options);
|
||||
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
my $result = $options{custom}->get_data(
|
||||
chart => 'system.ram',
|
||||
points => $self->{option_results}->{chart_point},
|
||||
after_period => $self->{option_results}->{chart_period},
|
||||
group => $self->{option_results}->{chart_statistics}
|
||||
);
|
||||
foreach my $memory_value (@{$result->{data}}) {
|
||||
foreach my $memory_label (@{$result->{labels}}) {
|
||||
$self->{ram_data}->{$memory_label} = shift @{$memory_value};
|
||||
}
|
||||
}
|
||||
|
||||
my $total = $options{custom}->get_info(filter_info => 'ram_total');
|
||||
my $used = $self->{ram_data}->{used} * 1024 * 1024;
|
||||
my $free = $self->{ram_data}->{free} * 1024 * 1024;
|
||||
my $prct_used = $used * 100 / $total;
|
||||
my $prct_free = 100 - $prct_used;
|
||||
my $cached = $self->{ram_data}->{cached} * 1024 * 1024;
|
||||
my $buffers = $self->{ram_data}->{buffers} * 1024 * 1024;
|
||||
|
||||
$self->{ram} = {
|
||||
total => $total,
|
||||
used => $used,
|
||||
free => $free,
|
||||
prct_used => $prct_used,
|
||||
prct_free => $prct_free,
|
||||
cached => $cached,
|
||||
buffers => $buffers
|
||||
};
|
||||
};
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check *nix based servers memory using the Netdata agent RestAPI.
|
||||
|
||||
Example:
|
||||
perl centreon-plugins/centreon_plugins.pl --plugin=apps::monitoring::netdata::restapi::plugin
|
||||
--mode=memory --hostname=10.0.0.1 --chart-period=300 --warning-usage-prct=80 --critical-usage-prct=90 --verbose
|
||||
|
||||
More information on 'https://learn.netdata.cloud/docs/agent/web/api'.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--chart-period>
|
||||
|
||||
The period in seconds on which the values are calculated
|
||||
Default: 300
|
||||
|
||||
=item B<--chart-statistic>
|
||||
|
||||
The statistic calculation method used to parse the collected data.
|
||||
Can be : average, sum, min, max
|
||||
Default: average
|
||||
|
||||
=item B<--warning-usage>
|
||||
|
||||
Warning threshold on used memory (in B).
|
||||
|
||||
=item B<--critical-usage>
|
||||
|
||||
Critical threshold on used memory (in B)
|
||||
|
||||
=item B<--warning-usage-prct>
|
||||
|
||||
Warning threshold on used memory (in %).
|
||||
|
||||
=item B<--critical-usage-prct>
|
||||
|
||||
Critical threshold on percentage used memory (in %)
|
||||
|
||||
=item B<--warning-usage-free>
|
||||
|
||||
Warning threshold on free memory (in B).
|
||||
|
||||
=item B<--critical-usage-free>
|
||||
|
||||
Critical threshold on free memory (in B)
|
||||
|
||||
=item B<--warning-*>
|
||||
|
||||
Warning threshold (in B) on other metrics where '*' can be:
|
||||
buffer,cached,shared
|
||||
|
||||
=item B<--critical-*>
|
||||
|
||||
Critical threshold (in B) on other metrics where '*' can be:
|
||||
buffer,cached,shared
|
||||
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,178 @@
|
|||
#
|
||||
# Copyright 2020 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and alarm 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 apps::monitoring::netdata::restapi::mode::swap;
|
||||
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
sub custom_swap_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $msg = sprintf("Swap Total: %s %s Used: %s %s (%.2f%%) Free: %s %s (%.2f%%)",
|
||||
$self->{perfdata}->change_bytes(value => $self->{result_values}->{total}),
|
||||
$self->{perfdata}->change_bytes(value => $self->{result_values}->{used}),
|
||||
$self->{result_values}->{prct_used},
|
||||
$self->{perfdata}->change_bytes(value => $self->{result_values}->{free}),
|
||||
$self->{result_values}->{prct_free});
|
||||
return $msg;
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'swap', type => 0, message_separator => ' - ', skipped_code => { -10 => 1 } },
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{swap} = [
|
||||
{ label => 'usage', nlabel => 'swap.usage.bytes', set => {
|
||||
key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ],
|
||||
closure_custom_output => $self->can('custom_swap_output'),
|
||||
perfdatas => [
|
||||
{ label => 'used', value => 'used', template => '%d', min => 0, max => 'total',
|
||||
unit => 'B', cast_int => 1 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'usage-free', display_ok => 0, nlabel => 'swap.free.bytes', set => {
|
||||
key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ],
|
||||
closure_custom_output => $self->can('custom_swap_output'),
|
||||
perfdatas => [
|
||||
{ label => 'free', value => 'free', template => '%d', min => 0, max => 'total',
|
||||
unit => 'B', cast_int => 1 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'usage-prct', display_ok => 0, nlabel => 'swap.usage.percentage', set => {
|
||||
key_values => [ { name => 'prct_used' } ],
|
||||
output_template => 'Used : %.2f %%',
|
||||
perfdatas => [
|
||||
{ label => 'used_prct', value => 'prct_used', template => '%.2f', min => 0, max => 100,
|
||||
unit => '%' },
|
||||
],
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
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 => {
|
||||
'chart-period:s' => { name => 'chart_period', default => '300' },
|
||||
'chart-statistics:s' => { name => 'chart_statistics', default => 'average' },
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::check_options(%options);
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
my $result = $options{custom}->get_data(
|
||||
chart => 'system.swap',
|
||||
points => $self->{option_results}->{chart_point},
|
||||
after_period => $self->{option_results}->{chart_period},
|
||||
group => $self->{option_results}->{chart_statistics}
|
||||
);
|
||||
foreach my $swap_value (@{$result->{data}}) {
|
||||
foreach my $swap_label (@{$result->{labels}}) {
|
||||
$self->{swap_data}->{$swap_label} = shift @{$swap_value};
|
||||
}
|
||||
}
|
||||
|
||||
my $used = $self->{swap_data}->{used} * 1024 * 1024;
|
||||
my $free = $self->{swap_data}->{free} * 1024 * 1024;
|
||||
my $total = $used + $free;
|
||||
my $prct_used = $used * 100 / $total;
|
||||
my $prct_free = 100 - $prct_used;
|
||||
|
||||
$self->{swap} = {
|
||||
total => $total,
|
||||
used => $used,
|
||||
free => $free,
|
||||
prct_used => $prct_used,
|
||||
prct_free => $prct_free
|
||||
};
|
||||
};
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check *nix based servers CPU using the Netdata agent RestAPI.
|
||||
|
||||
Example:
|
||||
perl centreon-plugins/centreon_plugins.pl --plugin=apps::monitoring::netdata::restapi::plugin
|
||||
--mode=swap --hostname=10.0.0.1 --chart-period=300 --warning-usage-prct=80 --critical-usage-prct=90 --verbose
|
||||
|
||||
More information on 'https://learn.netdata.cloud/docs/agent/web/api'.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--chart-period>
|
||||
|
||||
The period in seconds on which the values are calculated
|
||||
Default: 300
|
||||
|
||||
=item B<--chart-statistic>
|
||||
|
||||
The statistic calculation method used to parse the collected data.
|
||||
Can be : average, sum, min, max
|
||||
Default: average
|
||||
|
||||
=item B<--warning-usage>
|
||||
|
||||
Warning threshold on used swap (in B).
|
||||
|
||||
=item B<--critical-usage>
|
||||
|
||||
Critical threshold on used swap (in B)
|
||||
|
||||
=item B<--warning-usage-prct>
|
||||
|
||||
Warning threshold on used swap (in %).
|
||||
|
||||
=item B<--critical-usage-prct>
|
||||
|
||||
Critical threshold on percentage used swap (in %)
|
||||
|
||||
=item B<--warning-usage-free>
|
||||
|
||||
Warning threshold on free swap (in B).
|
||||
|
||||
=item B<--critical-usage-free>
|
||||
|
||||
Critical threshold on free swap (in B)
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,181 @@
|
|||
#
|
||||
# Copyright 2020 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 apps::monitoring::netdata::restapi::mode::traffic;
|
||||
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
sub prefix_traffic_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Interface '" . $options{instance_value}->{display} . "' ";
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'interfaces', type => 1, cb_prefix_output => 'prefix_traffic_output', message_multiple => 'All interfaces are ok' }
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{interfaces} = [
|
||||
{ label => 'traffic-in', nlabel => 'network.trafficin.bitspersecond', set => {
|
||||
key_values => [ { name => 'traffic_in' }, { name => 'traffic_out' }, { name => 'display' } ],
|
||||
output_template => 'Traffic In: %.2f%s/s',
|
||||
output_change_bytes => 2,
|
||||
perfdatas => [
|
||||
{ label => 'traffic_in', value => 'traffic_in', template => '%d', min => 0, max => 'speed',
|
||||
unit => 'b/s', cast_int => 1, label_extra_instance => 1, instance_use => 'display' }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'traffic-out', nlabel => 'network.trafficin.bitspersecond', set => {
|
||||
key_values => [ { name => 'traffic_out' }, { name => 'traffic_in' }, { name => 'display' } ],
|
||||
output_template => 'Traffic Out: %.2f%s/s',
|
||||
output_change_bytes => 2,
|
||||
perfdatas => [
|
||||
{ label => 'traffic_out', value => 'traffic_out', template => '%d', min => 0, max => 'speed',
|
||||
unit => 'b/s', cast_int => 1, label_extra_instance => 1, instance_use => '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 => {
|
||||
'chart-period:s' => { name => 'chart_period', default => '300' },
|
||||
'chart-statistics:s' => { name => 'chart_statistics', default => 'average' },
|
||||
'interface-name:s' => { name => 'interface_name' },
|
||||
'speed:s' => { name => 'speed', default => '1000000000'}
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::check_options(%options);
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $full_list = $options{custom}->list_charts();
|
||||
|
||||
foreach my $chart (values %{$full_list->{charts}}) {
|
||||
next if ($chart->{name} !~ '^net\.');
|
||||
push @{$self->{interface_list}}, $chart->{name};
|
||||
}
|
||||
|
||||
foreach my $interface (@{$self->{interface_list}}) {
|
||||
my $result = $options{custom}->get_data(
|
||||
chart => $interface,
|
||||
dimensions => 'received,sent',
|
||||
points => $self->{option_results}->{chart_point},
|
||||
after_period => $self->{option_results}->{chart_period},
|
||||
group => $self->{option_results}->{chart_statistics},
|
||||
absolute => 1
|
||||
);
|
||||
|
||||
$interface =~ s/net.//;
|
||||
|
||||
next if (defined($self->{option_results}->{interface_name}) &&
|
||||
$self->{option_results}->{interface_name} ne '' &&
|
||||
$interface !~ /$self->{option_results}->{interface_name}/
|
||||
);
|
||||
|
||||
foreach my $interface_value (@{$result->{data}}) {
|
||||
foreach my $interface_label (@{$result->{labels}}) {
|
||||
$self->{interface}->{$interface}->{$interface_label} = shift @{$interface_value};
|
||||
}
|
||||
}
|
||||
|
||||
$self->{interfaces}->{$interface} = {
|
||||
display => $interface,
|
||||
traffic_in => $self->{interface}->{$interface}->{received} * 1000,
|
||||
traffic_out => $self->{interface}->{$interface}->{sent} * 1000,
|
||||
speed => $self->{option_results}->{speed}
|
||||
};
|
||||
}
|
||||
|
||||
if (scalar(keys %{$self->{interfaces}}) <= 0) {
|
||||
$self->{output}->add_option_msg(short_msg => 'No interfaces found');
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
};
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check traffic on interfaces of *nix based servers using the Netdata agent RestAPI.
|
||||
|
||||
Example:
|
||||
perl centreon_plugins.pl --plugin=apps::monitoring::netdata::restapi::plugin
|
||||
--mode=traffic --hostname=10.0.0.1 --chart-period=300 --warning-traffic-in='70000000' --critical-traffic-in='80000000' --verbose
|
||||
|
||||
More information on 'https://learn.netdata.cloud/docs/agent/web/api'.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--chart-period>
|
||||
|
||||
The period in seconds on which the values are calculated
|
||||
Default: 300
|
||||
|
||||
=item B<--chart-statistic>
|
||||
|
||||
The statistic calculation method used to parse the collected data.
|
||||
Can be : average, sum, min, max
|
||||
Default: average
|
||||
|
||||
=item B<--interface-name>
|
||||
|
||||
Filter on a specific interface. Regexp can be used.
|
||||
Example: --interface-name='^eth0$'
|
||||
|
||||
=item B<--speed>
|
||||
|
||||
Set interfaces speed in B/s.
|
||||
Default: 1000000000 (1GB/s).
|
||||
|
||||
=item B<--warning-traffic-*>
|
||||
|
||||
Warning threshold on interface traffic where '*' can be:
|
||||
in,out.
|
||||
|
||||
=item B<--critical-traffic-*>
|
||||
|
||||
Critical threshold on interface traffic where '*' can be:
|
||||
in,out.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,58 @@
|
|||
#
|
||||
# Copyright 2020 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 apps::monitoring::netdata::restapi::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}} = (
|
||||
'alarms' => 'apps::monitoring::netdata::restapi::mode::alarms',
|
||||
'cpu' => 'apps::monitoring::netdata::restapi::mode::cpu',
|
||||
'diskusage' => 'apps::monitoring::netdata::restapi::mode::diskusage',
|
||||
'get-chart' => 'apps::monitoring::netdata::restapi::mode::getchart',
|
||||
'inodes' => 'apps::monitoring::netdata::restapi::mode::inodes',
|
||||
'list-charts' => 'apps::monitoring::netdata::restapi::mode::listcharts',
|
||||
'loadaverage' => 'apps::monitoring::netdata::restapi::mode::loadaverage',
|
||||
'memory' => 'apps::monitoring::netdata::restapi::mode::memory',
|
||||
'swap' => 'apps::monitoring::netdata::restapi::mode::swap',
|
||||
'traffic' => 'apps::monitoring::netdata::restapi::mode::traffic'
|
||||
);
|
||||
|
||||
$self->{custom_modes}{restapi} = 'apps::monitoring::netdata::restapi::custom::api';
|
||||
return $self;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 PLUGIN DESCRIPTION
|
||||
|
||||
Check *nix based servers components using the Netdata agent RestAPI.
|
||||
|
||||
=cut
|
Loading…
Reference in New Issue