(plugin) apps::monitoring::nodeexporter::windows - adding windows node exporter plugin (#3799)

* adding windows node exporter plugin

* adding paging for memory

* apply suggestion

* adding service mode draft

* applying suggestion for default threshold

* Update apps/monitoring/nodeexporter/windows/mode/cpu.pm

Co-authored-by: Simon Bomm <sbomm@centreon.com>

* Update apps/monitoring/nodeexporter/windows/mode/listinterfaces.pm

Co-authored-by: Simon Bomm <sbomm@centreon.com>

* Update apps/monitoring/nodeexporter/windows/mode/liststorages.pm

Co-authored-by: Simon Bomm <sbomm@centreon.com>

* Update apps/monitoring/nodeexporter/windows/mode/liststorages.pm

Co-authored-by: Simon Bomm <sbomm@centreon.com>

* Update apps/monitoring/nodeexporter/windows/mode/services.pm

Co-authored-by: Simon Bomm <sbomm@centreon.com>

* Update apps/monitoring/nodeexporter/windows/mode/traffic.pm

Co-authored-by: Simon Bomm <sbomm@centreon.com>

* apply suggestions

* apply suggestion again

* Update apps/monitoring/nodeexporter/windows/mode/services.pm

Co-authored-by: Simon Bomm <sbomm@centreon.com>

* Update apps/monitoring/nodeexporter/windows/mode/services.pm

Co-authored-by: Simon Bomm <sbomm@centreon.com>

* Update apps/monitoring/nodeexporter/windows/mode/services.pm

Co-authored-by: Simon Bomm <sbomm@centreon.com>

* Update apps/monitoring/nodeexporter/windows/mode/storage.pm

Co-authored-by: Simon Bomm <sbomm@centreon.com>

* Update apps/monitoring/nodeexporter/windows/mode/traffic.pm

Co-authored-by: Simon Bomm <sbomm@centreon.com>

* Update apps/monitoring/nodeexporter/windows/mode/traffic.pm

Co-authored-by: Simon Bomm <sbomm@centreon.com>

* modify output brackets

Co-authored-by: Simon Bomm <sbomm@centreon.com>
This commit is contained in:
lchrdn 2022-08-02 15:43:25 +02:00 committed by GitHub
parent 7300b0e439
commit 11b79f6488
8 changed files with 1260 additions and 0 deletions

View File

@ -0,0 +1,216 @@
#
# Copyright 2022 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::nodeexporter::windows::mode::cpu;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
use centreon::plugins::statefile;
use centreon::common::monitoring::openmetrics::scrape;
sub custom_usage_calc {
my ($self, %options) = @_;
my $delta_total = $options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref}} - $options{old_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref} };
$self->{result_values}->{used_delta} = 100 * $delta_total / $options{delta_time};
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
return 0;
}
sub custom_usage_idle_calc {
my ($self, %options) = @_;
my $delta_total = $options{new_datas}->{node_cpu_avg_idle_avg} - $options{old_datas}->{node_cpu_avg_idle_avg};
$self->{result_values}->{idle_avg_delta} = 100 - ( 100 * $delta_total / $options{delta_time} );
return 0;
}
sub prefix_node_cpu_avg_output {
my ($self, %options) = @_;
return $self->{node_cpu_avg}->{count} . " CPU(s) average usage is ";
}
sub prefix_node_cpu_output {
my ($self, %options) = @_;
return "CPU '" . $options{instance_value}->{display} . "' ";
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'node_cpu_avg', type => 0, cb_prefix_output => 'prefix_node_cpu_avg_output' },
{ name => 'node_cpu', type => 1, cb_prefix_output => 'prefix_node_cpu_output', message_multiple => 'All CPU types are ok' }
];
$self->{maps_counters}->{node_cpu_avg} = [
{ label => 'average', nlabel => 'cpu.utilization.percentage', set => {
key_values => [ { name => 'idle_avg', diff => 1 } , { name => 'count'} ],
closure_custom_calc => $self->can('custom_usage_idle_calc'),
output_template => '%.2f %%',
output_template => 'average usage : %.2f %%', output_use => 'idle_avg_delta', threshold_use => 'idle_avg_delta',
perfdatas => [
{ label => 'average', value => 'idle_avg_delta', template => '%.2f',
min => 0, max => 100, unit => '%' },
],
}
},
];
$self->{maps_counters}->{node_cpu} = [
{
label => 'idle', nlabel => 'node.cpu.idle.utilization.percentage', set => {
key_values => [ { name => 'idle' , diff => 1 }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_usage_calc'), closure_custom_calc_extra_options => { label_ref => 'idle' },
output_template => 'idle usage : %.2f %%', output_use => 'used_delta', threshold_use => 'used_delta',
perfdatas => [
{ label => 'windows_cpu_time_total_idle', value => 'used_delta', template => '%.2f',
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display' },
],
}
},
{
label => 'dpc', nlabel => 'node.cpu.dpc.utilization.percentage', set => {
key_values => [ { name => 'dpc', diff => 1 }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_usage_calc'), closure_custom_calc_extra_options => { label_ref => 'dpc' },
output_template => 'dpc usage : %.2f %%', output_use => 'used_delta', threshold_use => 'used_delta',
perfdatas => [
{ label => 'windows_cpu_time_total_dpc', value => 'used_delta', template => '%.2f',
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display' },
],
}
},
{
label => 'interrupt', nlabel => 'node.cpu.interrupt.utilization.percentage', set => {
key_values => [ { name => 'interrupt', diff => 1 }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_usage_calc'), closure_custom_calc_extra_options => { label_ref => 'interrupt' },
output_template => 'interrupt usage : %.2f %%', output_use => 'used_delta', threshold_use => 'used_delta',
perfdatas => [
{ label => 'windows_cpu_time_total_interrupt', value => 'used_delta', template => '%.2f',
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display' },
],
}
},
{
label => 'privileged', nlabel => 'node.cpu.privileged.utilization.percentage', set => {
key_values => [ { name => 'privileged', diff => 1 }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_usage_calc'), closure_custom_calc_extra_options => { label_ref => 'privileged' },
output_template => 'privileged usage : %.2f %%', output_use => 'used_delta', threshold_use => 'used_delta',
perfdatas => [
{ label => 'windows_cpu_time_total_privileged', value => 'used_delta', template => '%.2f',
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display' },
],
}
},
{
label => 'user', nlabel => 'node.cpu.user.utilization.percentage', set => {
key_values => [ { name => 'user', diff => 1 }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_usage_calc'), closure_custom_calc_extra_options => { label_ref => 'user' },
output_template => 'user usage : %.2f %%', output_use => 'used_delta', threshold_use => 'used_delta',
perfdatas => [
{ label => 'windows_cpu_time_total_user', value => 'used_delta', 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, statefile => 1, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => { });
return $self;
}
sub manage_selection {
my ($self, %options) = @_;
my $raw_metrics = centreon::common::monitoring::openmetrics::scrape::parse(%options, strip_chars => "[\"']");
$self->{cache_name} = 'windows_nodeexporter' . $options{custom}->get_uuid() . '_' . $self->{mode} . '_' . md5_hex('all');
$self->{node_cpu} = {};
my $cpu_number;
my $cpu_idle;
my $avg_cpu_idle;
foreach my $metric (keys %{$raw_metrics}) {
next if ($metric !~ /windows_cpu_time_total/i);
foreach my $data (@{$raw_metrics->{$metric}->{data}}) {
foreach my $cpu_index ($data->{dimensions}->{core}){
$self->{node_cpu}->{$cpu_index}->{$data->{dimensions}->{mode}} = $data->{value};
$self->{node_cpu}->{$cpu_index}->{display} = $data->{dimensions}->{core};
$cpu_idle += $data->{value} if ($data->{dimensions}->{mode} =~ /idle/i);
}
}
}
$cpu_number = keys %{$self->{node_cpu}};
$avg_cpu_idle = $cpu_idle / $cpu_number;
$self->{node_cpu_avg}->{idle_avg} = $avg_cpu_idle;
$self->{node_cpu_avg}->{count} = $cpu_number;
if (scalar(keys %{$self->{node_cpu}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No entry found.");
$self->{output}->option_exit();
}
}
1;
__END__
=head1 MODE
Check CPU based on node exporter metrics.
=over 8
=item B<--warning-*>
Threshold warning.
Can be: 'average', 'idle', 'dpc', 'user', 'interrupt', 'privileged'
=item B<--critical-*>
Threshold critical.
Can be: 'average', 'idle', 'dpc', 'user', 'interrupt', 'privileged'
=back
=cut

View File

@ -0,0 +1,101 @@
#
# Copyright 2022 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::nodeexporter::windows::mode::listinterfaces;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::common::monitoring::openmetrics::scrape;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$options{options}->add_options(arguments => { });
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
}
sub manage_selection {
my ($self, %options) = @_;
my $raw_metrics = centreon::common::monitoring::openmetrics::scrape::parse(%options, strip_chars => "[\"']");
foreach my $metric (keys %{$raw_metrics}) {
next if ($metric ne "windows_net_bytes_received_total" );
foreach my $data (@{$raw_metrics->{$metric}->{data}}) {
$self->{interfaces}->{$data->{dimensions}->{nic}}->{name} = $data->{dimensions}->{nic};
}
}
}
sub run {
my ($self, %options) = @_;
$self->manage_selection(%options);
foreach my $interface (sort keys %{$self->{interfaces}}) {
$self->{output}->output_add(long_msg => '[name = ' . $interface . "]"
);
}
$self->{output}->output_add(severity => 'OK',
short_msg => 'List Interfaces:');
$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 $interface (sort keys %{$self->{interfaces}}) {
$self->{output}->add_disco_entry(
name => $self->{interfaces}->{$interface}->{name}
);
}
}
1;
__END__
=head1 MODE
List interfaces
=over 8
=back
=cut

View File

@ -0,0 +1,100 @@
#
# Copyright 2022 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::nodeexporter::windows::mode::liststorages;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::common::monitoring::openmetrics::scrape;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$options{options}->add_options(arguments => { });
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
}
sub manage_selection {
my ($self, %options) = @_;
my $raw_metrics = centreon::common::monitoring::openmetrics::scrape::parse(%options, strip_chars => "[\"']");
foreach my $metric (keys %{$raw_metrics}) {
next if ($metric ne "windows_logical_disk_free_bytes" );
foreach my $data (@{$raw_metrics->{$metric}->{data}}) {
$self->{storages}->{$data->{dimensions}->{volume}}->{name} = $data->{dimensions}->{volume};
}
}
}
sub run {
my ($self, %options) = @_;
$self->manage_selection(%options);
foreach my $storage (sort keys %{$self->{storages}}) {
$self->{output}->output_add(long_msg => '[volume = ' . $storage . "]");
}
$self->{output}->output_add(severity => 'OK',
short_msg => 'List Storages:');
$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 $storage (sort keys %{$self->{storages}}) {
$self->{output}->add_disco_entry(
name => $self->{storages}->{$storage}->{name}
);
}
}
1;
__END__
=head1 MODE
List storages
=over 8
=back
=cut

View File

@ -0,0 +1,244 @@
#
# Copyright 2022 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::nodeexporter::windows::mode::memory;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::common::monitoring::openmetrics::scrape;
# memory usage calculation
sub custom_usage_perfdata {
my ($self, %options) = @_;
my $label = 'used';
my $value_perf = $self->{result_values}->{used};
my %total_options = ();
if ($self->{instance_mode}->{option_results}->{units} eq '%') {
$total_options{total} = $self->{result_values}->{windows_os_virtual_memory_bytes};
$total_options{cast_int} = 1;
}
$self->{output}->perfdata_add(
label => $label, unit => 'B',
nlabel => 'node.memory.usage.bytes',
value => $value_perf,
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, %total_options),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}, %total_options),
min => 0, max => $self->{result_values}->{windows_os_virtual_memory_bytes},
);
}
sub custom_usage_threshold {
my ($self, %options) = @_;
my ($exit, $threshold_value);
$threshold_value = $self->{result_values}->{used};
if ($self->{instance_mode}->{option_results}->{units} eq '%') {
$threshold_value = $self->{result_values}->{prct_used};
}
$exit = $self->{perfdata}->threshold_check(value => $threshold_value,
threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' },
{ label => 'warning-'. $self->{thlabel}, exit_litteral => 'warning' } ]);
return $exit;
}
sub custom_usage_output {
my ($self, %options) = @_;
my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{windows_os_virtual_memory_bytes});
my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
my $msg = sprintf("Ram Total: %s, Used: %s (%.2f%%)",
$total_size_value . " " . $total_size_unit,
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used});
return $msg;
}
sub custom_usage_calc {
my ($self, %options) = @_;
$self->{result_values}->{windows_os_virtual_memory_bytes} = $options{new_datas}->{node_memory_windows_os_virtual_memory_bytes};
$self->{result_values}->{windows_os_virtual_memory_free_bytes} = $options{new_datas}->{node_memory_windows_os_virtual_memory_free_bytes};
$self->{result_values}->{used} = $self->{result_values}->{windows_os_virtual_memory_bytes} - $self->{result_values}->{windows_os_virtual_memory_free_bytes};
$self->{result_values}->{prct_used} = ($self->{result_values}->{windows_os_virtual_memory_bytes} > 0) ? $self->{result_values}->{used} * 100 / $self->{result_values}->{windows_os_virtual_memory_bytes} : 0;
return 0;
}
# paging usage calculation
sub custom_paging_usage_perfdata {
my ($self, %options) = @_;
my $label = 'used';
my $value_perf = $self->{result_values}->{used};
my %total_options = ();
if ($self->{instance_mode}->{option_results}->{units} eq '%') {
$total_options{total} = $self->{result_values}->{windows_os_paging_limit_bytes};
$total_options{cast_int} = 1;
}
$self->{output}->perfdata_add(
label => $label, unit => 'B',
nlabel => 'node.paging.usage.bytes',
value => $value_perf,
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, %total_options),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}, %total_options),
min => 0, max => $self->{result_values}->{windows_os_paging_limit_bytes},
);
}
sub custom_paging_usage_threshold {
my ($self, %options) = @_;
my ($exit, $threshold_value);
$threshold_value = $self->{result_values}->{used};
if ($self->{instance_mode}->{option_results}->{units} eq '%') {
$threshold_value = $self->{result_values}->{prct_used};
}
$exit = $self->{perfdata}->threshold_check(value => $threshold_value,
threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' },
{ label => 'warning-'. $self->{thlabel}, exit_litteral => 'warning' } ]);
return $exit;
}
sub custom_paging_usage_output {
my ($self, %options) = @_;
my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{windows_os_paging_limit_bytes});
my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
my $msg = sprintf("Paging Total size: %s, Used: %s (%.2f%%)",
$total_size_value . " " . $total_size_unit,
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used});
return $msg;
}
sub custom_paging_usage_calc {
my ($self, %options) = @_;
$self->{result_values}->{windows_os_paging_limit_bytes} = $options{new_datas}->{node_memory_windows_os_paging_limit_bytes};
$self->{result_values}->{windows_os_paging_free_bytes} = $options{new_datas}->{node_memory_windows_os_paging_free_bytes};
$self->{result_values}->{used} = $self->{result_values}->{windows_os_paging_limit_bytes} - $self->{result_values}->{windows_os_paging_free_bytes};
$self->{result_values}->{prct_used} = ($self->{result_values}->{windows_os_paging_limit_bytes} > 0) ? $self->{result_values}->{used} * 100 / $self->{result_values}->{windows_os_paging_limit_bytes} : 0;
return 0;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'node_memory', type => 0, message_multiple => 'All memory types are ok' }
];
$self->{maps_counters}->{node_memory} = [
{ label => 'usage', set => {
key_values => [ { name => 'windows_os_virtual_memory_bytes' }, { name => 'windows_os_virtual_memory_free_bytes' }],
closure_custom_calc => $self->can('custom_usage_calc'),
closure_custom_output => $self->can('custom_usage_output'),
closure_custom_perfdata => $self->can('custom_usage_perfdata'),
closure_custom_threshold_check => $self->can('custom_usage_threshold'),
}
},
{
label => 'paging', nlabel => 'node.memory.pages.bytes', set => {
key_values => [ { name => 'windows_os_paging_limit_bytes' }, { name => 'windows_os_paging_free_bytes' } ],
closure_custom_calc => $self->can('custom_paging_usage_calc'),
closure_custom_output => $self->can('custom_paging_usage_output'),
closure_custom_perfdata => $self->can('custom_paging_usage_perfdata'),
closure_custom_threshold_check => $self->can('custom_paging_usage_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 => {
"units:s" => { name => 'units', default => '%' },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
}
sub manage_selection {
my ($self, %options) = @_;
my $raw_metrics = centreon::common::monitoring::openmetrics::scrape::parse(%options, strip_chars => "[\"']");
foreach my $metric (keys %{$raw_metrics}) {
next if ($metric !~ /windows_os_virtual_memory_free_bytes|windows_os_virtual_memory_bytes|windows_os_paging_free_bytes|windows_os_paging_limit_bytes/i);
$self->{node_memory}->{$metric} = $raw_metrics->{$metric}->{data}[0]->{value};
}
if (scalar(keys %{$self->{node_memory}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No entry found.");
$self->{output}->option_exit();
}
}
1;
__END__
=head1 MODE
Check memory based on node exporter metrics.
=over 8
=item B<--units>
Units of thresholds. Can be : '%', 'B'
Default: '%'
=item B<--warning-usage>
Warning threshlod.
=item B<--critical-usage>
Critical threshlod.
=item B<--warning-paging>
Warning threshlod.
=item B<--critical-paging>
Critical threshlod.
=back
=cut

View File

@ -0,0 +1,132 @@
#
# Copyright 2022 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::nodeexporter::windows::mode::services;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::common::monitoring::openmetrics::scrape;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
sub custom_state_output {
my ($self, %options) = @_;
my $msg = "Service : '" . $self->{result_values}->{display} . "' [state: '" . $self->{result_values}->{status} . "']" . " [start_mode: '" . $self->{result_values}->{start_mode} . "']";
return $msg;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'service', type => 1, message_multiple => 'All services are OK' }
];
$self->{maps_counters}->{service} = [
{ label => 'status', type => 2,
critical_default => '%{start_mode} =~ /auto/ && %{status} !~ /^running$/',
set => { key_values => [ { name => 'status' }, { name => 'start_mode' }, { name => 'display' } ],
closure_custom_output => $self->can('custom_state_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold_ng,
}
},
];
}
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 => {
"service:s" => { name => 'service' }
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
}
sub manage_selection {
my ($self, %options) = @_;
$self->{service} = {};
my $raw_metrics = centreon::common::monitoring::openmetrics::scrape::parse(%options, strip_chars => "[\"']");
foreach my $metric (keys %{$raw_metrics}) {
next if ($metric !~ /windows_service_state|windows_service_start_mode/i);
foreach my $data (@{$raw_metrics->{$metric}->{data}}) {
next if (defined($self->{option_results}->{service}) && $data->{dimensions}->{name} !~ /$self->{option_results}->{service}/i );
if ($metric =~ /windows_service_state/ && $data->{value} == 1){
$self->{service}->{$data->{dimensions}->{name}} = {
display => $data->{dimensions}->{name},
status => $data->{dimensions}->{state}
};
}
if ($metric =~ /windows_service_start_mode/ && $data->{value} == 1){
$self->{service}->{$data->{dimensions}->{name}}->{start_mode} = $data->{dimensions}->{start_mode};
}
}
}
if (scalar(keys %{$self->{service}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No service found.");
$self->{output}->option_exit();
}
}
1;
__END__
=head1 MODE
Check Windows services.
=over 8
=item B<--service>
Specify which service to monitor. Can be a regex.
Default: all services are monitored.
=item B<--warning-status>
Set warning threshold for status (Default: '').
Can used special variables like: %{status}, %{start_mode}
=item B<--critical-status>
Set critical threshold for status (Default: '%{start_mode} =~ /auto/ && %{status} !~ /^running$/').
Can used special variables like: %{status}, %{start_mode}
=back
=cut

View File

@ -0,0 +1,206 @@
#
# Copyright 2022 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::nodeexporter::windows::mode::storage;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::common::monitoring::openmetrics::scrape;
sub custom_usage_perfdata {
my ($self, %options) = @_;
my $value_perf = $self->{result_values}->{used};
my %total_options = ();
if ($self->{instance_mode}->{option_results}->{units} eq '%') {
$total_options{total} = $self->{result_values}->{windows_logical_disk_size_bytes};
$total_options{cast_int} = 1;
}
$self->{output}->perfdata_add(
label => 'used', unit => 'B',
nlabel => 'node.storage.space.free.bytes',
value => $value_perf,
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, %total_options),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}, %total_options),
min => 0, max => $self->{result_values}->{windows_logical_disk_size_bytes},
instances => $self->{result_values}->{display}
);
}
sub custom_usage_threshold {
my ($self, %options) = @_;
my ($exit, $threshold_value);
$threshold_value = $self->{result_values}->{used};
if ($self->{instance_mode}->{option_results}->{units} eq '%') {
$threshold_value = $self->{result_values}->{prct_used};
$threshold_value = $self->{result_values}->{prct_free} if (defined($self->{instance_mode}->{option_results}->{free}));
}
$exit = $self->{perfdata}->threshold_check(
value => $threshold_value,
threshold => [
{ label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' },
{ label => 'warning-'. $self->{thlabel}, exit_litteral => 'warning' }
]
);
return $exit;
}
sub custom_usage_output {
my ($self, %options) = @_;
my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{windows_logical_disk_size_bytes});
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}->{windows_logical_disk_free_bytes});
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 custom_usage_calc {
my ($self, %options) = @_;
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
$self->{result_values}->{windows_logical_disk_size_bytes} = $options{new_datas}->{$self->{instance} . '_windows_logical_disk_size_bytes'};
$self->{result_values}->{windows_logical_disk_free_bytes} = $options{new_datas}->{$self->{instance} . '_windows_logical_disk_free_bytes'};
$self->{result_values}->{used} = $self->{result_values}->{windows_logical_disk_size_bytes} - $self->{result_values}->{windows_logical_disk_free_bytes};
$self->{result_values}->{prct_used} = ($self->{result_values}->{windows_logical_disk_size_bytes} > 0) ? $self->{result_values}->{used} * 100 / $self->{result_values}->{windows_logical_disk_size_bytes} : 0;
$self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used};
# limit to 100. Better output.
if ($self->{result_values}->{prct_used} > 100) {
$self->{result_values}->{windows_logical_disk_free_bytes} = 0;
$self->{result_values}->{prct_used} = 100;
$self->{result_values}->{prct_free} = 0;
}
return 0;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'node_storage', type => 1, message_multiple => 'All memory types are ok', display_long => 1, cb_prefix_output => 'prefix_storage_output', }
];
$self->{maps_counters}->{node_storage} = [
{ label => 'usage', set => {
key_values => [ { name => 'windows_logical_disk_free_bytes' }, { name => 'windows_logical_disk_size_bytes' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_usage_calc'),
closure_custom_output => $self->can('custom_usage_output'),
closure_custom_perfdata => $self->can('custom_usage_perfdata'),
closure_custom_threshold_check => $self->can('custom_usage_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 => {
"storage:s" => { name => 'storage' },
"units:s" => { name => 'units', default => '%' }
});
return $self;
}
sub prefix_storage_output {
my ($self, %options) = @_;
return "Storage '" . $options{instance_value}->{display} . "' ";
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
}
sub manage_selection {
my ($self, %options) = @_;
my $raw_metrics = centreon::common::monitoring::openmetrics::scrape::parse(%options, strip_chars => "[\"']");
foreach my $metric (keys %{$raw_metrics}) {
next if ($metric !~ /windows_logical_disk_free_bytes|windows_logical_disk_size_bytes/i );
foreach my $data (@{$raw_metrics->{$metric}->{data}}) {
next if (defined($self->{option_results}->{storage}) && $data->{dimensions}->{volume} !~ /$self->{option_results}->{storage}/i);
foreach my $volume ($data->{dimensions}->{volume}) {
$self->{node_storage}->{$volume}->{$metric} = $data->{value};
$self->{node_storage}->{$volume}->{display} = $volume;
}
}
}
if (scalar(keys %{$self->{node_storage}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No disk found.");
$self->{output}->option_exit();
}
}
1;
__END__
=head1 MODE
Check storage based on node exporter metrics.
=over 8
=item B<--storage>
Specify which disk to monitor. Can be a regex.
Default: all disks are monitored.
=item B<--units>
Units of thresholds. Can be : '%', 'B'
Default: '%'
=item B<--warning-usage>
Threshold warning.
=item B<--critical-usage>
Threshold critical.
=back
=cut

View File

@ -0,0 +1,206 @@
#
# Copyright 2022 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::nodeexporter::windows::mode::traffic;
use base qw(centreon::plugins::templates::counter);
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
use centreon::plugins::statefile;
use centreon::common::monitoring::openmetrics::scrape;
sub prefix_interface_output {
my ($self, %options) = @_;
return sprintf(
"interface %s ",
$options{instance_value}->{display}
);
}
sub custom_usage_bandwidth_calc {
my ($self, %options) = @_;
my $delta_time = $options{new_datas}->{bandwidth_windows_net_bytes_total} - $options{old_datas}->{bandwidth_windows_net_bytes_total};
my $bandwidth_usage = 0;
if ($options{old_datas}->{bandwidth_windows_net_current_bandwidth_bytes} > 0){
my $bandwidth_usage = ($delta_time / $options{old_datas}->{bandwidth_windows_net_current_bandwidth_bytes}) * 100;
}
$self->{result_values}->{bandwitdh_avg} = $bandwidth_usage;
return 0;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'bandwidth', type => 0 },
{ name => 'traffic', type => 1, message_multiple => 'All interfaces are OK. ', cb_prefix_output => 'prefix_interface_output'}
];
$self->{maps_counters}->{bandwidth} = [
{ label => 'bandwidth-usage', nlabel => 'node.bandwidth.usage', display_ok => 0, set => {
key_values => [ { name => 'windows_net_current_bandwidth_bytes', diff => 1 }, { name => 'windows_net_bytes_total' } ],
closure_custom_calc => $self->can('custom_usage_bandwidth_calc'),
output_template => '%.2f %%',
output_template => 'Average bandwidth usage : %.2f %%', output_use => 'bandwitdh_avg', threshold_use => 'bandwitdh_avg',
perfdatas => [
{ template => '%.2f', value => 'bandwitdh_avg', min => 0, max => 100, unit => '%' },
],
}
},
];
$self->{maps_counters}->{traffic} = [
{ label => 'packets-in', nlabel => 'node.packets.in.count', display_ok => 0, set => {
key_values => [ { name => 'windows_net_packets_received_total', diff => 1 }, { name => 'display' } ],
output_template => 'packets in: %s',
perfdatas => [
{ template => '%s', min => 0, label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'packets-out', nlabel => 'node.packets.out.count', display_ok => 0, set => {
key_values => [ { name => 'windows_net_packets_sent_total', diff => 1 }, { name => 'display' } ],
output_template => 'packets out: %s',
perfdatas => [
{ template => '%s', min => 0, label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'packets-error-in', nlabel => 'node.packets.in.error.count', display_ok => 0, set => {
key_values => [ { name => 'windows_net_packets_received_errors_total', diff => 1 }, { name => 'display' } ],
output_template => 'packets error in: %s',
perfdatas => [
{ template => '%s', min => 0, label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'packets-error-out', nlabel => 'node.packets.out.error.count', display_ok => 0, set => {
key_values => [ { name => 'windows_net_packets_outbound_errors_total', diff => 1 }, { name => 'display' } ],
output_template => 'packets error out: %s',
perfdatas => [
{ template => '%s', min => 0, label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'traffic-in', nlabel => 'node.traffic.in.bitspersecond', set => {
key_values => [ { name => 'windows_net_bytes_received_total', per_second => 1 }, { name => 'display' } ],
output_template => 'traffic in: %.2f %s/s',
output_change_bytes => 2,
perfdatas => [
{ template => '%.2f', unit => 'b/s', min => 0, label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'traffic-out', nlabel => 'node.traffic.out.bitspersecond', set => {
key_values => [ { name => 'windows_net_bytes_sent_total', per_second => 1 }, { name => 'display' } ],
output_template => 'traffic out: %.2f %s/s',
output_change_bytes => 2,
perfdatas => [
{ template => '%.2f', unit => 'b/s', min => 0, label_extra_instance => 1, instance_use => 'display' }
]
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1, statefile => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
"interface:s" => { name => 'interface' },
});
return $self;
}
sub manage_selection {
my ($self, %options) = @_;
my $raw_metrics = centreon::common::monitoring::openmetrics::scrape::parse(%options, strip_chars => "[\"']");
$self->{cache_name} = 'windows_nodeexporter' . $options{custom}->get_uuid() . '_' . $self->{mode} . '_' .
(defined($self->{option_results}->{interface}) ? md5_hex($self->{option_results}->{interface}) : md5_hex('all'));
my $traffic_metrics;
$self->{interface} = {};
foreach my $metric (keys %{$raw_metrics}) {
next if ($metric !~ /windows_net_packets_received_total|windows_net_packets_sent_total|windows_net_bytes_received_total|windows_net_bytes_sent_total|windows_net_packets_received_errors_total|windows_net_packets_outbound_errors_total|windows_net_bytes_total|windows_net_current_bandwidth_bytes/i );
foreach my $data (@{$raw_metrics->{$metric}->{data}}) {
next if (defined($self->{option_results}->{interface}) && $data->{dimensions}->{nic} !~ /$self->{option_results}->{interface}/i);
$self->{traffic}->{$data->{dimensions}->{nic}}->{$metric} = $data->{value} ;
$self->{traffic}->{$data->{dimensions}->{nic}}->{display} = $data->{dimensions}->{nic} ;
if ($metric =~ /windows_net_bytes_total|windows_net_current_bandwidth_bytes/){
$self->{bandwidth}->{$metric} = $data->{value};
}
}
}
if (scalar(keys %{$self->{traffic}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No interface found.");
$self->{output}->option_exit();
}
}
1;
__END__
=head1 MODE
=item B<--interface>
Specify which interface to monitor. Can be a regex.
Default: all interfaces are monitored.
=item B<--warning-*>
Warning thresholds.
Can be: 'traffic-in', 'traffic-out',
'packets-in', 'packets-out',
'bandwidth-usage'
=item B<--critical-*>
Critical thresholds.
Can be: 'traffic-in', 'traffic-out',
'packets-in', 'packets-out',
'bandwidth-usage'
=back
=cut

View File

@ -0,0 +1,55 @@
#
# Copyright 2022 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::nodeexporter::windows::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, force_new_perfdata => 1);
bless $self, $class;
$self->{version} = '0.1';
%{$self->{modes}} = (
'cpu' => 'apps::monitoring::nodeexporter::windows::mode::cpu',
'list-interfaces' => 'apps::monitoring::nodeexporter::windows::mode::listinterfaces',
'list-storages' => 'apps::monitoring::nodeexporter::windows::mode::liststorages',
'memory' => 'apps::monitoring::nodeexporter::windows::mode::memory',
'services' => 'apps::monitoring::nodeexporter::windows::mode::services',
'storage' => 'apps::monitoring::nodeexporter::windows::mode::storage',
'traffic' => 'apps::monitoring::nodeexporter::windows::mode::traffic'
);
$self->{custom_modes}{web} = 'centreon::common::monitoring::openmetrics::custom::web';
return $self;
}
1;
__END__
=head1 PLUGIN DESCRIPTION
Check Windows OS-based host metrics based on node exporter's metrics.
=cut