enh nodeexporter filtering (#1201)

This commit is contained in:
Colin Gagnaire 2018-10-29 13:21:48 +01:00 committed by GitHub
parent 93a41ca33e
commit eb9691b4ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 184 additions and 108 deletions

View File

@ -80,7 +80,8 @@ sub new {
$self->{version} = '1.0'; $self->{version} = '1.0';
$options{options}->add_options(arguments => $options{options}->add_options(arguments =>
{ {
"node:s" => { name => 'node', default => '.*' }, "instance:s" => { name => 'instance', default => 'instance=~".*"' },
"cpu:s" => { name => 'cpu', default => 'cpu=~".*"' },
"extra-filter:s@" => { name => 'extra_filter' }, "extra-filter:s@" => { name => 'extra_filter' },
"metric-overload:s@" => { name => 'metric_overload' }, "metric-overload:s@" => { name => 'metric_overload' },
}); });
@ -95,12 +96,25 @@ sub check_options {
$self->{metrics} = { $self->{metrics} = {
'cpu' => "^node_cpu.*", 'cpu' => "^node_cpu.*",
}; };
foreach my $metric (@{$self->{option_results}->{metric_overload}}) { foreach my $metric (@{$self->{option_results}->{metric_overload}}) {
next if ($metric !~ /(.*),(.*)/); next if ($metric !~ /(.*),(.*)/);
$self->{metrics}->{$1} = $2 if (defined($self->{metrics}->{$1})); $self->{metrics}->{$1} = $2 if (defined($self->{metrics}->{$1}));
} }
$self->{labels} = {};
foreach my $label (('instance', 'cpu')) {
if ($self->{option_results}->{$label} !~ /^(\w+)[!~=]+\".*\"$/) {
$self->{output}->add_option_msg(short_msg => "Need to specify --" . $label . " option as a PromQL filter.");
$self->{output}->option_exit();
}
$self->{labels}->{$label} = $1;
}
$self->{extra_filter} = '';
foreach my $filter (@{$self->{option_results}->{extra_filter}}) {
$self->{extra_filter} .= ',' . $filter;
}
$self->{prom_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 900; $self->{prom_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 900;
$self->{prom_step} = defined($self->{option_results}->{step}) ? $self->{option_results}->{step} : "1m"; $self->{prom_step} = defined($self->{option_results}->{step}) ? $self->{option_results}->{step} : "1m";
} }
@ -111,22 +125,20 @@ sub manage_selection {
$self->{nodes} = {}; $self->{nodes} = {};
$self->{cpu} = {}; $self->{cpu} = {};
my $extra_filter = ''; my $results = $options{custom}->query_range(queries => [ '(1 - irate({__name__=~"' . $self->{metrics}->{cpu} . '",' .
foreach my $filter (@{$self->{option_results}->{extra_filter}}) { 'mode="idle",' .
$extra_filter .= ',' . $filter; $self->{option_results}->{instance} . ',' .
} $self->{option_results}->{cpu} .
$self->{extra_filter} . '}[1m])) * 100' ],
my $results = $options{custom}->query_range(queries => [ '(1 - irate({__name__=~"' . $self->{metrics}->{cpu} . '",mode="idle",instance=~"' . $self->{option_results}->{node} .
'"' . $extra_filter . '}[1m])) * 100' ],
timeframe => $self->{prom_timeframe}, step => $self->{prom_step}); timeframe => $self->{prom_timeframe}, step => $self->{prom_step});
foreach my $metric (@{$results}) { foreach my $result (@{$results}) {
my $average = $options{custom}->compute(aggregation => 'average', values => $metric->{values}); my $average = $options{custom}->compute(aggregation => 'average', values => $result->{values});
$self->{nodes}->{$metric->{metric}->{instance}}->{display} = $metric->{metric}->{instance}; $self->{nodes}->{$result->{metric}->{$self->{labels}->{instance}}}->{display} = $result->{metric}->{$self->{labels}->{instance}};
$self->{nodes}->{$metric->{metric}->{instance}}->{average} += $average; $self->{nodes}->{$result->{metric}->{$self->{labels}->{instance}}}->{average} += $average;
$self->{nodes}->{$metric->{metric}->{instance}}->{cpu}->{$metric->{metric}->{cpu}}->{multi} = $metric->{metric}->{instance}; $self->{nodes}->{$result->{metric}->{$self->{labels}->{instance}}}->{cpu}->{$result->{metric}->{$self->{labels}->{cpu}}}->{multi} = $result->{metric}->{$self->{labels}->{instance}};
$self->{nodes}->{$metric->{metric}->{instance}}->{cpu}->{$metric->{metric}->{cpu}}->{display} = $metric->{metric}->{cpu}; $self->{nodes}->{$result->{metric}->{$self->{labels}->{instance}}}->{cpu}->{$result->{metric}->{$self->{labels}->{cpu}}}->{display} = $result->{metric}->{$self->{labels}->{cpu}};
$self->{nodes}->{$metric->{metric}->{instance}}->{cpu}->{$metric->{metric}->{cpu}}->{average} = $average; $self->{nodes}->{$result->{metric}->{$self->{labels}->{instance}}}->{cpu}->{$result->{metric}->{$self->{labels}->{cpu}}}->{average} = $average;
} }
foreach my $node (keys %{$self->{nodes}}) { foreach my $node (keys %{$self->{nodes}}) {
@ -149,9 +161,13 @@ Check CPU usage for nodes and each of their cores.
=over 8 =over 8
=item B<--node> =item B<--instance>
Filter on a specific node (Must be a regexp, Default: '.*') Filter on a specific instance (Must be a PromQL filter, Default: 'instance=~".*"')
=item B<--cpu>
Filter on a specific cpu (Must be a PromQL filter, Default: 'cpu=~".*"')
=item B<--warning-*> =item B<--warning-*>

View File

@ -29,8 +29,10 @@ sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{maps_counters_type} = [ $self->{maps_counters_type} = [
{ name => 'nodes', type => 3, cb_prefix_output => 'prefix_nodes_output', message_multiple => 'All nodes CPU usage are ok', { name => 'nodes', type => 3, cb_prefix_output => 'prefix_nodes_output',
counters => [ { name => 'cpu', type => 1, cb_prefix_output => 'prefix_cpu_output', message_multiple => 'All CPU usage are ok' } ] }, message_multiple => 'All nodes CPU usage are ok', skipped_code => { -10 => 1 },
counters => [ { name => 'cpu', type => 1, cb_prefix_output => 'prefix_cpu_output',
message_multiple => 'All CPU usage are ok', skipped_code => { -10 => 1 } } ] },
]; ];
$self->{maps_counters}->{nodes} = [ $self->{maps_counters}->{nodes} = [
@ -219,7 +221,9 @@ sub new {
$self->{version} = '1.0'; $self->{version} = '1.0';
$options{options}->add_options(arguments => $options{options}->add_options(arguments =>
{ {
"node:s" => { name => 'node', default => '.*' }, "instance:s" => { name => 'instance', default => 'instance=~".*"' },
"cpu:s" => { name => 'cpu', default => 'cpu=~".*"' },
"type:s" => { name => 'type', default => 'mode=~".*"' },
"extra-filter:s@" => { name => 'extra_filter' }, "extra-filter:s@" => { name => 'extra_filter' },
"metric-overload:s@" => { name => 'metric_overload' }, "metric-overload:s@" => { name => 'metric_overload' },
}); });
@ -234,12 +238,25 @@ sub check_options {
$self->{metrics} = { $self->{metrics} = {
'cpu' => "^node_cpu.*", 'cpu' => "^node_cpu.*",
}; };
foreach my $metric (@{$self->{option_results}->{metric_overload}}) { foreach my $metric (@{$self->{option_results}->{metric_overload}}) {
next if ($metric !~ /(.*),(.*)/); next if ($metric !~ /(.*),(.*)/);
$self->{metrics}->{$1} = $2 if (defined($self->{metrics}->{$1})); $self->{metrics}->{$1} = $2 if (defined($self->{metrics}->{$1}));
} }
$self->{labels} = {};
foreach my $label (('instance', 'cpu', 'type')) {
if ($self->{option_results}->{$label} !~ /^(\w+)[!~=]+\".*\"$/) {
$self->{output}->add_option_msg(short_msg => "Need to specify --" . $label . " option as a PromQL filter.");
$self->{output}->option_exit();
}
$self->{labels}->{$label} = $1;
}
$self->{extra_filter} = '';
foreach my $filter (@{$self->{option_results}->{extra_filter}}) {
$self->{extra_filter} .= ',' . $filter;
}
$self->{prom_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 900; $self->{prom_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 900;
$self->{prom_step} = defined($self->{option_results}->{step}) ? $self->{option_results}->{step} : "1m"; $self->{prom_step} = defined($self->{option_results}->{step}) ? $self->{option_results}->{step} : "1m";
} }
@ -248,23 +265,21 @@ sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{nodes} = {}; $self->{nodes} = {};
my $extra_filter = '';
foreach my $filter (@{$self->{option_results}->{extra_filter}}) {
$extra_filter .= ',' . $filter;
}
my $results = $options{custom}->query_range(queries => [ '(irate({__name__=~"' . $self->{metrics}->{cpu} . '",instance=~"' . $self->{option_results}->{node} . my $results = $options{custom}->query_range(queries => [ '(irate({__name__=~"' . $self->{metrics}->{cpu} . '",' .
'"' . $extra_filter . '}[1m])) * 100' ], $self->{option_results}->{instance} . ',' .
$self->{option_results}->{cpu} . ',' .
$self->{option_results}->{type} .
$self->{extra_filter} . '}[1m])) * 100' ],
timeframe => $self->{prom_timeframe}, step => $self->{prom_step}); timeframe => $self->{prom_timeframe}, step => $self->{prom_step});
foreach my $metric (@{$results}) { foreach my $result (@{$results}) {
my $average = $options{custom}->compute(aggregation => 'average', values => $metric->{values}); my $average = $options{custom}->compute(aggregation => 'average', values => $result->{values});
$self->{nodes}->{$metric->{metric}->{instance}}->{display} = $metric->{metric}->{instance}; $self->{nodes}->{$result->{metric}->{$self->{labels}->{instance}}}->{display} = $result->{metric}->{$self->{labels}->{instance}};
$self->{nodes}->{$metric->{metric}->{instance}}->{$metric->{metric}->{mode}} += $average; $self->{nodes}->{$result->{metric}->{$self->{labels}->{instance}}}->{$result->{metric}->{$self->{labels}->{type}}} += $average;
$self->{nodes}->{$metric->{metric}->{instance}}->{cpu}->{$metric->{metric}->{cpu}}->{multi} = $metric->{metric}->{instance}; $self->{nodes}->{$result->{metric}->{$self->{labels}->{instance}}}->{cpu}->{$result->{metric}->{$self->{labels}->{cpu}}}->{multi} = $result->{metric}->{$self->{labels}->{instance}};
$self->{nodes}->{$metric->{metric}->{instance}}->{cpu}->{$metric->{metric}->{cpu}}->{display} = $metric->{metric}->{cpu}; $self->{nodes}->{$result->{metric}->{$self->{labels}->{instance}}}->{cpu}->{$result->{metric}->{$self->{labels}->{cpu}}}->{display} = $result->{metric}->{$self->{labels}->{cpu}};
$self->{nodes}->{$metric->{metric}->{instance}}->{cpu}->{$metric->{metric}->{cpu}}->{$metric->{metric}->{mode}} = $average; $self->{nodes}->{$result->{metric}->{$self->{labels}->{instance}}}->{cpu}->{$result->{metric}->{$self->{labels}->{cpu}}}->{$result->{metric}->{$self->{labels}->{type}}} = $average;
} }
foreach my $node (keys %{$self->{nodes}}) { foreach my $node (keys %{$self->{nodes}}) {
@ -290,9 +305,17 @@ Check CPU detailed usage for nodes and each of their cores.
=over 8 =over 8
=item B<--node> =item B<--instance>
Filter on a specific node (Must be a regexp, Default: '.*') Filter on a specific instance (Must be a PromQL filter, Default: 'instance=~".*"')
=item B<--cpu>
Filter on a specific cpu (Must be a PromQL filter, Default: 'cpu=~".*"')
=item B<--type>
Filter on a specific type (Must be a PromQL filter, Default: 'mode=~".*"')
=item B<--warning-*> =item B<--warning-*>

View File

@ -80,7 +80,7 @@ sub new {
$self->{version} = '1.0'; $self->{version} = '1.0';
$options{options}->add_options(arguments => $options{options}->add_options(arguments =>
{ {
"node:s" => { name => 'node', default => '.*' }, "instance:s" => { name => 'instance', default => 'instance=~".*"' },
"extra-filter:s@" => { name => 'extra_filter' }, "extra-filter:s@" => { name => 'extra_filter' },
"metric-overload:s@" => { name => 'metric_overload' }, "metric-overload:s@" => { name => 'metric_overload' },
}); });
@ -97,11 +97,24 @@ sub check_options {
'load5' => '^node_load5$', 'load5' => '^node_load5$',
'load15' => '^node_load15$', 'load15' => '^node_load15$',
}; };
foreach my $metric (@{$self->{option_results}->{metric_overload}}) { foreach my $metric (@{$self->{option_results}->{metric_overload}}) {
next if ($metric !~ /(.*),(.*)/); next if ($metric !~ /(.*),(.*)/);
$self->{metrics}->{$1} = $2 if (defined($self->{metrics}->{$1})); $self->{metrics}->{$1} = $2 if (defined($self->{metrics}->{$1}));
} }
$self->{labels} = {};
foreach my $label (('instance')) {
if ($self->{option_results}->{$label} !~ /^(\w+)[!~=]+\".*\"$/) {
$self->{output}->add_option_msg(short_msg => "Need to specify --" . $label . " option as a PromQL filter.");
$self->{output}->option_exit();
}
$self->{labels}->{$label} = $1;
}
$self->{extra_filter} = '';
foreach my $filter (@{$self->{option_results}->{extra_filter}}) {
$self->{extra_filter} .= ',' . $filter;
}
} }
sub manage_selection { sub manage_selection {
@ -109,21 +122,19 @@ sub manage_selection {
$self->{nodes} = {}; $self->{nodes} = {};
my $extra_filter = ''; my $results = $options{custom}->query(queries => [ 'label_replace({__name__=~"' . $self->{metrics}->{load1} . '",' .
foreach my $filter (@{$self->{option_results}->{extra_filter}}) { $self->{option_results}->{instance} .
$extra_filter .= ',' . $filter; $self->{extra_filter} . '}, "__name__", "load1", "", "")',
} 'label_replace({__name__=~"' . $self->{metrics}->{load5} . '",' .
$self->{option_results}->{instance} .
$self->{extra_filter} . '}, "__name__", "load5", "", "")',
'label_replace({__name__=~"' . $self->{metrics}->{load15} . '",' .
$self->{option_results}->{instance} .
$self->{extra_filter} . '}, "__name__", "load15", "", "")' ]);
my $results = $options{custom}->query(queries => [ 'label_replace({__name__=~"' . $self->{metrics}->{load1} . '",instance=~"' . $self->{option_results}->{node} . foreach my $result (@{$results}) {
'"' . $extra_filter . '}, "__name__", "load1", "", "")', $self->{nodes}->{$result->{metric}->{$self->{labels}->{instance}}}->{display} = $result->{metric}->{$self->{labels}->{instance}};
'label_replace({__name__=~"' . $self->{metrics}->{load5} . '",instance=~"' . $self->{option_results}->{node} . $self->{nodes}->{$result->{metric}->{$self->{labels}->{instance}}}->{$result->{metric}->{__name__}} = ${$result->{value}}[1];
'"' . $extra_filter . '}, "__name__", "load5", "", "")',
'label_replace({__name__=~"' . $self->{metrics}->{load15} . '",instance=~"' . $self->{option_results}->{node} .
'"' . $extra_filter . '}, "__name__", "load15", "", "")' ]);
foreach my $metric (@{$results}) {
$self->{nodes}->{$metric->{metric}->{instance}}->{display} = $metric->{metric}->{instance};
$self->{nodes}->{$metric->{metric}->{instance}}->{$metric->{metric}->{__name__}} = ${$metric->{value}}[1];
} }
if (scalar(keys %{$self->{nodes}}) <= 0) { if (scalar(keys %{$self->{nodes}}) <= 0) {
@ -142,9 +153,9 @@ Check nodes load.
=over 8 =over 8
=item B<--node> =item B<--instance>
Filter on a specific node (Must be a regexp, Default: '.*') Filter on a specific instance (Must be a PromQL filter, Default: 'instance=~".*"')
=item B<--warning-*> =item B<--warning-*>

View File

@ -139,9 +139,9 @@ sub new {
$self->{version} = '1.0'; $self->{version} = '1.0';
$options{options}->add_options(arguments => $options{options}->add_options(arguments =>
{ {
"node:s" => { name => 'node', default => '.*' }, "instance:s" => { name => 'instance', default => 'instance=~".*"' },
"extra-filter:s@" => { name => 'extra_filter' },
"units:s" => { name => 'units', default => '%' }, "units:s" => { name => 'units', default => '%' },
"extra-filter:s@" => { name => 'extra_filter' },
"metric-overload:s@" => { name => 'metric_overload' }, "metric-overload:s@" => { name => 'metric_overload' },
}); });
@ -158,11 +158,24 @@ sub check_options {
'cached' => "^node_memory_Cached.*", 'cached' => "^node_memory_Cached.*",
'buffer' => "^node_memory_Buffers.*", 'buffer' => "^node_memory_Buffers.*",
}; };
foreach my $metric (@{$self->{option_results}->{metric_overload}}) { foreach my $metric (@{$self->{option_results}->{metric_overload}}) {
next if ($metric !~ /(.*),(.*)/); next if ($metric !~ /(.*),(.*)/);
$self->{metrics}->{$1} = $2 if (defined($self->{metrics}->{$1})); $self->{metrics}->{$1} = $2 if (defined($self->{metrics}->{$1}));
} }
$self->{labels} = {};
foreach my $label (('instance')) {
if ($self->{option_results}->{$label} !~ /^(\w+)[!~=]+\".*\"$/) {
$self->{output}->add_option_msg(short_msg => "Need to specify --" . $label . " option as a PromQL filter.");
$self->{output}->option_exit();
}
$self->{labels}->{$label} = $1;
}
$self->{extra_filter} = '';
foreach my $filter (@{$self->{option_results}->{extra_filter}}) {
$self->{extra_filter} .= ',' . $filter;
}
$instance_mode = $self; $instance_mode = $self;
} }
@ -172,23 +185,22 @@ sub manage_selection {
$self->{nodes} = {}; $self->{nodes} = {};
my $extra_filter = ''; my $results = $options{custom}->query(queries => [ 'label_replace({__name__=~"' . $self->{metrics}->{total} . '",' .
foreach my $filter (@{$self->{option_results}->{extra_filter}}) { $self->{option_results}->{instance} .
$extra_filter .= ',' . $filter; $self->{extra_filter} . '}, "__name__", "total", "", "")',
} 'label_replace({__name__=~"' . $self->{metrics}->{available} . '",' .
$self->{option_results}->{instance} .
$self->{extra_filter} . '}, "__name__", "available", "", "")',
'label_replace({__name__=~"' . $self->{metrics}->{cached} . '",' .
$self->{option_results}->{instance} .
$self->{extra_filter} . '}, "__name__", "cached", "", "")',
'label_replace({__name__=~"' . $self->{metrics}->{buffer} . '",' .
$self->{option_results}->{instance} .
$self->{extra_filter} . '}, "__name__", "buffer", "", "")' ]);
my $results = $options{custom}->query(queries => [ 'label_replace({__name__=~"' . $self->{metrics}->{total} . '",instance=~"' . $self->{option_results}->{node} . foreach my $result (@{$results}) {
'"' . $extra_filter . '}, "__name__", "total", "", "")', $self->{nodes}->{$result->{metric}->{$self->{labels}->{instance}}}->{display} = $result->{metric}->{$self->{labels}->{instance}};
'label_replace({__name__=~"' . $self->{metrics}->{available} . '",instance=~"' . $self->{option_results}->{node} . $self->{nodes}->{$result->{metric}->{$self->{labels}->{instance}}}->{$result->{metric}->{__name__}} = ${$result->{value}}[1];
'"' . $extra_filter . '}, "__name__", "available", "", "")',
'label_replace({__name__=~"' . $self->{metrics}->{cached} . '",instance=~"' . $self->{option_results}->{node} .
'"' . $extra_filter . '}, "__name__", "cached", "", "")',
'label_replace({__name__=~"' . $self->{metrics}->{buffer} . '",instance=~"' . $self->{option_results}->{node} .
'"' . $extra_filter . '}, "__name__", "buffer", "", "")' ]);
foreach my $metric (@{$results}) {
$self->{nodes}->{$metric->{metric}->{instance}}->{display} = $metric->{metric}->{instance};
$self->{nodes}->{$metric->{metric}->{instance}}->{$metric->{metric}->{__name__}} = ${$metric->{value}}[1];
} }
if (scalar(keys %{$self->{nodes}}) <= 0) { if (scalar(keys %{$self->{nodes}}) <= 0) {
@ -207,9 +219,9 @@ Check memory usage.
=over 8 =over 8
=item B<--node> =item B<--instance>
Filter on a specific node (Must be a regexp, Default: '.*') Filter on a specific instance (Must be a PromQL filter, Default: 'instance=~".*"')
=item B<--warning-*> =item B<--warning-*>
@ -221,6 +233,10 @@ Can be: 'usage', 'buffer', 'cached'.
Threshold critical. Threshold critical.
Can be: 'usage', 'buffer', 'cached'. Can be: 'usage', 'buffer', 'cached'.
=item B<--units>
Units of thresholds (Default: '%') ('%', 'B').
=item B<--extra-filter> =item B<--extra-filter>
Add a PromQL filter (Can be multiple) Add a PromQL filter (Can be multiple)

View File

@ -140,12 +140,12 @@ sub new {
$self->{version} = '1.0'; $self->{version} = '1.0';
$options{options}->add_options(arguments => $options{options}->add_options(arguments =>
{ {
"node:s" => { name => 'node', default => '.*' }, "instance:s" => { name => 'instance', default => 'instance=~".*"' },
"storage:s" => { name => 'storage', default => '.*' }, "mountpoint:s" => { name => 'mountpoint', default => 'mountpoint=~".*"' },
"exclude-storage-type:s" => { name => 'exclude_storage_type', default => 'rootfs|tmpfs' }, "fstype:s" => { name => 'fstype', default => 'fstype=~"overlay"' },
"extra-filter:s@" => { name => 'extra_filter' },
"units:s" => { name => 'units', default => '%' }, "units:s" => { name => 'units', default => '%' },
"free" => { name => 'free' }, "free" => { name => 'free' },
"extra-filter:s@" => { name => 'extra_filter' },
"metric-overload:s@" => { name => 'metric_overload' }, "metric-overload:s@" => { name => 'metric_overload' },
}); });
@ -160,11 +160,24 @@ sub check_options {
'free' => "^node_filesystem_free.*", 'free' => "^node_filesystem_free.*",
'size' => "^node_filesystem_size.*", 'size' => "^node_filesystem_size.*",
}; };
foreach my $metric (@{$self->{option_results}->{metric_overload}}) { foreach my $metric (@{$self->{option_results}->{metric_overload}}) {
next if ($metric !~ /(.*),(.*)/); next if ($metric !~ /(.*),(.*)/);
$self->{metrics}->{$1} = $2 if (defined($self->{metrics}->{$1})); $self->{metrics}->{$1} = $2 if (defined($self->{metrics}->{$1}));
} }
$self->{labels} = {};
foreach my $label (('instance', 'mountpoint', 'fstype')) {
if ($self->{option_results}->{$label} !~ /^(\w+)[!~=]+\".*\"$/) {
$self->{output}->add_option_msg(short_msg => "Need to specify --" . $label . " option as a PromQL filter.");
$self->{output}->option_exit();
}
$self->{labels}->{$label} = $1;
}
$self->{extra_filter} = '';
foreach my $filter (@{$self->{option_results}->{extra_filter}}) {
$self->{extra_filter} .= ',' . $filter;
}
$instance_mode = $self; $instance_mode = $self;
} }
@ -174,25 +187,22 @@ sub manage_selection {
$self->{nodes} = {}; $self->{nodes} = {};
my $extra_filter = ''; my $results = $options{custom}->query(queries => [ 'label_replace({__name__=~"' . $self->{metrics}->{free} . '",' .
foreach my $filter (@{$self->{option_results}->{extra_filter}}) { $self->{option_results}->{instance} . ',' .
$extra_filter .= ',' . $filter; $self->{option_results}->{mountpoint} . ',' .
} $self->{option_results}->{fstype} .
$self->{extra_filter} . '}, "__name__", "free", "", "")',
'label_replace({__name__=~"' . $self->{metrics}->{size} . '",' .
$self->{option_results}->{instance} . ',' .
$self->{option_results}->{mountpoint} . ',' .
$self->{option_results}->{fstype} .
$self->{extra_filter} . '}, "__name__", "size", "", "")' ]);
my $results = $options{custom}->query(queries => [ 'label_replace({__name__=~"' . $self->{metrics}->{free} . '",instance=~"' . $self->{option_results}->{node} . foreach my $result (@{$results}) {
'",mountpoint=~"' . $self->{option_results}->{storage} . $self->{nodes}->{$result->{metric}->{$self->{labels}->{instance}}}->{display} = $result->{metric}->{$self->{labels}->{instance}};
'",fstype!~"' . $self->{option_results}->{exclude_storage_type} . $self->{nodes}->{$result->{metric}->{$self->{labels}->{instance}}}->{storage}->{$result->{metric}->{mountpoint}}->{multi} = $result->{metric}->{$self->{labels}->{instance}};
'"' . $extra_filter . '}, "__name__", "free", "", "")', $self->{nodes}->{$result->{metric}->{$self->{labels}->{instance}}}->{storage}->{$result->{metric}->{mountpoint}}->{display} = $result->{metric}->{$self->{labels}->{mountpoint}};
'label_replace({__name__=~"' . $self->{metrics}->{size} . '",instance=~"' . $self->{option_results}->{node} . $self->{nodes}->{$result->{metric}->{$self->{labels}->{instance}}}->{storage}->{$result->{metric}->{mountpoint}}->{$result->{metric}->{__name__}} = ${$result->{value}}[1];
'",mountpoint=~"' . $self->{option_results}->{storage} .
'",fstype!~"' . $self->{option_results}->{exclude_storage_type} .
'"' . $extra_filter . '}, "__name__", "size", "", "")' ]);
foreach my $metric (@{$results}) {
$self->{nodes}->{$metric->{metric}->{instance}}->{display} = $metric->{metric}->{instance};
$self->{nodes}->{$metric->{metric}->{instance}}->{storage}->{$metric->{metric}->{mountpoint}}->{multi} = $metric->{metric}->{instance};
$self->{nodes}->{$metric->{metric}->{instance}}->{storage}->{$metric->{metric}->{mountpoint}}->{display} = $metric->{metric}->{mountpoint};
$self->{nodes}->{$metric->{metric}->{instance}}->{storage}->{$metric->{metric}->{mountpoint}}->{$metric->{metric}->{__name__}} = ${$metric->{value}}[1];
} }
if (scalar(keys %{$self->{nodes}}) <= 0) { if (scalar(keys %{$self->{nodes}}) <= 0) {
@ -207,21 +217,21 @@ __END__
=head1 MODE =head1 MODE
Check CPU usage for nodes and each of their cores. Check storages usage.
=over 8 =over 8
=item B<--node> =item B<--instance>
Filter on a specific node (Must be a regexp, Default: '.*') Filter on a specific instance (Must be a PromQL filter, Default: 'instance=~".*"')
=item B<--storage> =item B<--mountpoint>
Filter on a specific storage (Must be a regexp, Default: '.*') Filter on a specific mountpoint (Must be a PromQL filter, Default: 'mountpoint=~".*"')
=item B<--exclude-storage-type> =item B<--fstype>
Exclude storage types (Must be a regexp, Default: 'rootfs|tmpfs') Filter on a specific fstype (Must be a PromQL filter, Default: 'fstype=~"overlay"')
=item B<--units> =item B<--units>