From 36de9af578004be7cf07591076ebc00c63fbc1a5 Mon Sep 17 00:00:00 2001 From: qgarnier Date: Wed, 23 Feb 2022 09:17:33 +0100 Subject: [PATCH] (plugin) apps::monitoring::netdata::restapi - mode disks use family for fs-name (#3503) --- .../monitoring/netdata/restapi/mode/disks.pm | 27 +++++++++---------- .../netdata/restapi/mode/listdisks.pm | 14 +++++----- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/centreon-plugins/apps/monitoring/netdata/restapi/mode/disks.pm b/centreon-plugins/apps/monitoring/netdata/restapi/mode/disks.pm index 965e2285c..b7dac338f 100644 --- a/centreon-plugins/apps/monitoring/netdata/restapi/mode/disks.pm +++ b/centreon-plugins/apps/monitoring/netdata/restapi/mode/disks.pm @@ -115,34 +115,33 @@ sub manage_selection { foreach my $chart (values %{$full_list->{charts}}) { next if ($chart->{name} !~ 'disk_space._'); - push @{$self->{fs_list}}, $chart->{name}; + push @{$self->{fs_list}}, { name => $chart->{name}, family => $chart->{family} }; } + $self->{diskpath} = {}; foreach my $fs (@{$self->{fs_list}}) { my $result = $options{custom}->get_data( - chart => $fs, + chart => $fs->{name}, dimensions => 'used,avail,reserved_for_root', after_period => $self->{option_results}->{chart_period}, group => $self->{option_results}->{chart_statistics} ); - $fs =~ s/disk_space.//; - $fs =~ s/_/\//g; + my $family = $fs->{family}; - next if (defined($self->{option_results}->{fs_name}) && - $self->{option_results}->{fs_name} ne '' && - $fs !~ /$self->{option_results}->{fs_name}/ - ); + next if (defined($self->{option_results}->{fs_name}) && $self->{option_results}->{fs_name} ne '' && + $family !~ /$self->{option_results}->{fs_name}/); + my $metrics = {}; foreach my $fs_value (@{$result->{data}}) { foreach my $fs_label (@{$result->{labels}}) { - $self->{fs}->{$fs}->{$fs_label} = shift @{$fs_value}; + $metrics->{$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 $reserved_space = defined($self->{option_results}->{space_reservation}) ? $metrics->{'reserved for root'} * (1024 ** 3) : 0; + my $used = $metrics->{used} * (1024 ** 3); + my $free = $metrics->{avail} * (1024 ** 3); my $total = $used + $free + $reserved_space; my $prct_used = $used * 100 / $total; my $prct_free = 100 - $prct_used; @@ -153,8 +152,8 @@ sub manage_selection { $prct_free = 0; } - $self->{diskpath}->{$fs} = { - display => $fs, + $self->{diskpath}->{$family} = { + display => $family, used => $used, total => $total, free => $free, diff --git a/centreon-plugins/apps/monitoring/netdata/restapi/mode/listdisks.pm b/centreon-plugins/apps/monitoring/netdata/restapi/mode/listdisks.pm index 32525ce6f..8e7d6cf50 100644 --- a/centreon-plugins/apps/monitoring/netdata/restapi/mode/listdisks.pm +++ b/centreon-plugins/apps/monitoring/netdata/restapi/mode/listdisks.pm @@ -45,14 +45,12 @@ sub run { foreach my $chart (values %{$full_list->{charts}}) { next if ($chart->{name} !~ 'disk_space._'); - push @{$self->{fs_list}}, $chart->{name}; - $chart->{name} =~s/disk_space.//; - $chart->{name} =~ s/_/\//g; + $self->{output}->output_add( long_msg => sprintf( - "[name = %s][title = %s]", - $chart->{name}, - $chart->{title}, + "[name: %s][title: %s]", + $chart->{family}, + $chart->{title} ) ); } @@ -74,8 +72,8 @@ sub disco_show { $self->run(%options); foreach my $fs (@{$self->{fs_list}}) { $self->{output}->add_disco_entry( - name => $fs->{name}, - status => $fs->{title}, + name => $fs->{family}, + status => $fs->{title} ); } }