adapt nodeexporter to new counter template

This commit is contained in:
Colin Gagnaire 2019-02-04 14:30:38 +01:00
parent e8c24e795d
commit 844ba7d589
3 changed files with 117 additions and 95 deletions

View File

@ -29,47 +29,62 @@ 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_node_output', cb_long_output => 'node_long_output',
counters => [ { name => 'cpu', type => 1, cb_prefix_output => 'prefix_cpu_output', message_multiple => 'All CPU usage are ok' } ] }, message_multiple => 'All nodes usage are ok', indent_long_output => ' ',
group => [
{ name => 'global_cpu', cb_prefix_output => 'prefix_global_cpu_output', type => 0, skipped_code => { -10 => 1 } },
{ name => 'cpu', display_long => 1, cb_prefix_output => 'prefix_cpu_output',
message_multiple => 'All CPUs usage are ok', type => 1, skipped_code => { -10 => 1 } },
]
}
]; ];
$self->{maps_counters}->{nodes} = [ $self->{maps_counters}->{global_cpu} = [
{ label => 'node-usage', set => { { label => 'node-usage', set => {
key_values => [ { name => 'average' }, { name => 'display' } ], key_values => [ { name => 'node_average' } ],
output_template => 'usage %.2f %%', output_template => '%.2f %%',
perfdatas => [ perfdatas => [
{ label => 'node', value => 'average_absolute', template => '%.2f', { label => 'node', value => 'node_average_absolute', template => '%.2f', unit => '%',
min => 0, max => 100, unit => '%', min => 0, max => 100, label_extra_instance => 1 },
label_extra_instance => 1, instance_use => 'display_absolute' },
], ],
} }
}, },
]; ];
$self->{maps_counters}->{cpu} = [ $self->{maps_counters}->{cpu} = [
{ label => 'cpu-usage', set => { { label => 'cpu-usage', set => {
key_values => [ { name => 'average' }, { name => 'multi' }, { name => 'display' } ], key_values => [ { name => 'cpu_usage' }, { name => 'display' } ],
output_template => 'usage %.2f %%', output_template => 'Usage: %.2f %%',
perfdatas => [ perfdatas => [
{ label => 'cpu', value => 'average_absolute', template => '%.2f', { label => 'cpu', value => 'cpu_usage_absolute', template => '%.2f', unit => '%',
min => 0, max => 100, unit => '%', min => 0, max => 100, label_extra_instance => 1 },
label_multi_instances => 1, multi_use => 'multi_absolute',
label_extra_instance => 1, instance_use => 'display_absolute' },
], ],
} }
}, },
]; ];
} }
sub prefix_nodes_output { sub prefix_node_output {
my ($self, %options) = @_; my ($self, %options) = @_;
return "Node '" . $options{instance_value}->{display} . "' "; return "Node '" . $options{instance_value}->{display} . "' ";
} }
sub node_long_output {
my ($self, %options) = @_;
return "Checking node '" . $options{instance_value}->{display} . "'";
}
sub prefix_global_cpu_output {
my ($self, %options) = @_;
return "CPU Average Usage: ";
}
sub prefix_cpu_output { sub prefix_cpu_output {
my ($self, %options) = @_; my ($self, %options) = @_;
return "Node '" . $options{instance_value}->{multi} . "' " . "Cpu '" . $options{instance_value}->{display} . "' "; return "CPU '" . $options{instance_value}->{display} . "' ";
} }
sub new { sub new {
@ -123,7 +138,6 @@ sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{nodes} = {}; $self->{nodes} = {};
$self->{cpu} = {};
my $results = $options{custom}->query_range(queries => [ '(1 - irate({__name__=~"' . $self->{metrics}->{cpu} . '",' . my $results = $options{custom}->query_range(queries => [ '(1 - irate({__name__=~"' . $self->{metrics}->{cpu} . '",' .
'mode="idle",' . 'mode="idle",' .
@ -134,15 +148,14 @@ sub manage_selection {
foreach my $result (@{$results}) { foreach my $result (@{$results}) {
my $average = $options{custom}->compute(aggregation => 'average', values => $result->{values}); my $average = $options{custom}->compute(aggregation => 'average', values => $result->{values});
$self->{nodes}->{$result->{metric}->{$self->{labels}->{instance}}}->{display} = $result->{metric}->{$self->{labels}->{instance}}; $self->{nodes}->{$result->{metric}->{$self->{labels}->{instance}}}->{display} = $result->{metric}->{$self->{labels}->{instance}},
$self->{nodes}->{$result->{metric}->{$self->{labels}->{instance}}}->{average} += $average; $self->{nodes}->{$result->{metric}->{$self->{labels}->{instance}}}->{global_cpu}->{node_average} += $average;
$self->{nodes}->{$result->{metric}->{$self->{labels}->{instance}}}->{cpu}->{$result->{metric}->{$self->{labels}->{cpu}}}->{multi} = $result->{metric}->{$self->{labels}->{instance}};
$self->{nodes}->{$result->{metric}->{$self->{labels}->{instance}}}->{cpu}->{$result->{metric}->{$self->{labels}->{cpu}}}->{display} = $result->{metric}->{$self->{labels}->{cpu}}; $self->{nodes}->{$result->{metric}->{$self->{labels}->{instance}}}->{cpu}->{$result->{metric}->{$self->{labels}->{cpu}}}->{display} = $result->{metric}->{$self->{labels}->{cpu}};
$self->{nodes}->{$result->{metric}->{$self->{labels}->{instance}}}->{cpu}->{$result->{metric}->{$self->{labels}->{cpu}}}->{average} = $average; $self->{nodes}->{$result->{metric}->{$self->{labels}->{instance}}}->{cpu}->{$result->{metric}->{$self->{labels}->{cpu}}}->{cpu_usage} = $average;
} }
foreach my $node (keys %{$self->{nodes}}) { foreach my $node (keys %{$self->{nodes}}) {
$self->{nodes}->{$node}->{average} /= scalar(keys %{$self->{nodes}->{$node}->{cpu}}); $self->{nodes}->{$node}->{global_cpu}->{node_average} /= scalar(keys %{$self->{nodes}->{$node}->{cpu}});
} }
if (scalar(keys %{$self->{nodes}}) <= 0) { if (scalar(keys %{$self->{nodes}}) <= 0) {

View File

@ -29,188 +29,188 @@ 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', { name => 'nodes', type => 3, cb_prefix_output => 'prefix_node_output', cb_long_output => 'node_long_output',
message_multiple => 'All nodes CPU usage are ok', skipped_code => { -10 => 1 }, message_multiple => 'All nodes usage are ok', indent_long_output => ' ',
counters => [ { name => 'cpu', type => 1, cb_prefix_output => 'prefix_cpu_output', group => [
message_multiple => 'All CPU usage are ok', skipped_code => { -10 => 1 } } ] }, { name => 'global_cpu', cb_prefix_output => 'prefix_global_cpu_output', type => 0, skipped_code => { -10 => 1 } },
{ name => 'cpu', display_long => 1, cb_prefix_output => 'prefix_cpu_output',
message_multiple => 'All CPUs usage are ok', type => 1, skipped_code => { -10 => 1 } },
]
}
]; ];
$self->{maps_counters}->{nodes} = [ $self->{maps_counters}->{global_cpu} = [
{ label => 'node-wait', set => { { label => 'node-wait', set => {
key_values => [ { name => 'iowait' }, { name => 'display' } ], key_values => [ { name => 'iowait' } ],
output_template => 'Wait: %.2f %%', output_template => 'Wait: %.2f %%',
perfdatas => [ perfdatas => [
{ label => 'wait', value => 'iowait_absolute', template => '%.2f', { label => 'wait', value => 'iowait_absolute', template => '%.2f',
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' }, min => 0, max => 100, unit => '%', label_extra_instance => 1 },
], ],
} }
}, },
{ label => 'node-user', set => { { label => 'node-user', set => {
key_values => [ { name => 'user' }, { name => 'display' } ], key_values => [ { name => 'user' } ],
output_template => 'User: %.2f %%', output_template => 'User: %.2f %%',
perfdatas => [ perfdatas => [
{ label => 'user', value => 'user_absolute', template => '%.2f', { label => 'user', value => 'user_absolute', template => '%.2f',
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' }, min => 0, max => 100, unit => '%', label_extra_instance => 1 },
], ],
} }
}, },
{ label => 'node-softirq', set => { { label => 'node-softirq', set => {
key_values => [ { name => 'softirq' }, { name => 'display' } ], key_values => [ { name => 'softirq' } ],
output_template => 'Soft Irq: %.2f %%', output_template => 'Soft Irq: %.2f %%',
perfdatas => [ perfdatas => [
{ label => 'softirq', value => 'softirq_absolute', template => '%.2f', { label => 'softirq', value => 'softirq_absolute', template => '%.2f',
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' }, min => 0, max => 100, unit => '%', label_extra_instance => 1 },
], ],
} }
}, },
{ label => 'node-interrupt', set => { { label => 'node-interrupt', set => {
key_values => [ { name => 'irq' }, { name => 'display' } ], key_values => [ { name => 'irq' } ],
output_template => 'Interrupt: %.2f %%', output_template => 'Interrupt: %.2f %%',
perfdatas => [ perfdatas => [
{ label => 'interrupt', value => 'irq_absolute', template => '%.2f', { label => 'interrupt', value => 'irq_absolute', template => '%.2f',
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' }, min => 0, max => 100, unit => '%', label_extra_instance => 1 },
], ],
} }
}, },
{ label => 'node-idle', set => { { label => 'node-idle', set => {
key_values => [ { name => 'idle' }, { name => 'display' } ], key_values => [ { name => 'idle' } ],
output_template => 'Idle: %.2f %%', output_template => 'Idle: %.2f %%',
perfdatas => [ perfdatas => [
{ label => 'idle', value => 'idle_absolute', template => '%.2f', { label => 'idle', value => 'idle_absolute', template => '%.2f',
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' }, min => 0, max => 100, unit => '%', label_extra_instance => 1 },
], ],
} }
}, },
{ label => 'node-steal', set => { { label => 'node-steal', set => {
key_values => [ { name => 'steal' }, { name => 'display' } ], key_values => [ { name => 'steal' } ],
output_template => 'Steal: %.2f %%', output_template => 'Steal: %.2f %%',
perfdatas => [ perfdatas => [
{ label => 'steal', value => 'steal_absolute', template => '%.2f', { label => 'steal', value => 'steal_absolute', template => '%.2f',
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' }, min => 0, max => 100, unit => '%', label_extra_instance => 1 },
], ],
} }
}, },
{ label => 'node-system', set => { { label => 'node-system', set => {
key_values => [ { name => 'system' }, { name => 'display' } ], key_values => [ { name => 'system' } ],
output_template => 'System: %.2f %%', output_template => 'System: %.2f %%',
perfdatas => [ perfdatas => [
{ label => 'system', value => 'system_absolute', template => '%.2f', { label => 'system', value => 'system_absolute', template => '%.2f',
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' }, min => 0, max => 100, unit => '%', label_extra_instance => 1 },
], ],
} }
}, },
{ label => 'node-nice', set => { { label => 'node-nice', set => {
key_values => [ { name => 'nice' }, { name => 'display' } ], key_values => [ { name => 'nice' } ],
output_template => 'Nice: %.2f %%', output_template => 'Nice: %.2f %%',
perfdatas => [ perfdatas => [
{ label => 'nice', value => 'nice_absolute', template => '%.2f', { label => 'nice', value => 'nice_absolute', template => '%.2f',
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' }, min => 0, max => 100, unit => '%', label_extra_instance => 1 },
], ],
} }
}, },
]; ];
$self->{maps_counters}->{cpu} = [ $self->{maps_counters}->{cpu} = [
{ label => 'cpu-wait', set => { { label => 'cpu-wait', set => {
key_values => [ { name => 'iowait' }, { name => 'multi' }, { name => 'display' } ], key_values => [ { name => 'iowait' }, { name => 'display' } ],
output_template => 'Wait: %.2f %%', output_template => 'Wait: %.2f %%',
perfdatas => [ perfdatas => [
{ label => 'wait', value => 'iowait_absolute', template => '%.2f', { label => 'wait', value => 'iowait_absolute', template => '%.2f',
min => 0, max => 100, unit => '%', min => 0, max => 100, unit => '%', label_extra_instance => 1 },
label_multi_instances => 1, multi_use => 'multi_absolute',
label_extra_instance => 1, instance_use => 'display_absolute' },
], ],
} }
}, },
{ label => 'cpu-user', set => { { label => 'cpu-user', set => {
key_values => [ { name => 'user' }, { name => 'multi' }, { name => 'display' } ], key_values => [ { name => 'user' }, { name => 'display' } ],
output_template => 'User: %.2f %%', output_template => 'User: %.2f %%',
perfdatas => [ perfdatas => [
{ label => 'user', value => 'user_absolute', template => '%.2f', { label => 'user', value => 'user_absolute', template => '%.2f',
min => 0, max => 100, unit => '%', min => 0, max => 100, unit => '%', label_extra_instance => 1 },
label_multi_instances => 1, multi_use => 'multi_absolute',
label_extra_instance => 1, instance_use => 'display_absolute' },
], ],
} }
}, },
{ label => 'cpu-softirq', set => { { label => 'cpu-softirq', set => {
key_values => [ { name => 'softirq' }, { name => 'multi' }, { name => 'display' } ], key_values => [ { name => 'softirq' }, { name => 'display' } ],
output_template => 'Soft Irq: %.2f %%', output_template => 'Soft Irq: %.2f %%',
perfdatas => [ perfdatas => [
{ label => 'softirq', value => 'softirq_absolute', template => '%.2f', { label => 'softirq', value => 'softirq_absolute', template => '%.2f',
min => 0, max => 100, unit => '%', min => 0, max => 100, unit => '%', label_extra_instance => 1 },
label_multi_instances => 1, multi_use => 'multi_absolute',
label_extra_instance => 1, instance_use => 'display_absolute' },
], ],
} }
}, },
{ label => 'cpu-interrupt', set => { { label => 'cpu-interrupt', set => {
key_values => [ { name => 'irq' }, { name => 'multi' }, { name => 'display' } ], key_values => [ { name => 'irq' }, { name => 'display' } ],
output_template => 'Interrupt: %.2f %%', output_template => 'Interrupt: %.2f %%',
perfdatas => [ perfdatas => [
{ label => 'interrupt', value => 'irq_absolute', template => '%.2f', { label => 'interrupt', value => 'irq_absolute', template => '%.2f',
min => 0, max => 100, unit => '%', min => 0, max => 100, unit => '%', label_extra_instance => 1 },
label_multi_instances => 1, multi_use => 'multi_absolute',
label_extra_instance => 1, instance_use => 'display_absolute' },
], ],
} }
}, },
{ label => 'cpu-idle', set => { { label => 'cpu-idle', set => {
key_values => [ { name => 'idle' }, { name => 'multi' }, { name => 'display' } ], key_values => [ { name => 'idle' }, { name => 'display' } ],
output_template => 'Idle: %.2f %%', output_template => 'Idle: %.2f %%',
perfdatas => [ perfdatas => [
{ label => 'idle', value => 'idle_absolute', template => '%.2f', { label => 'idle', value => 'idle_absolute', template => '%.2f',
min => 0, max => 100, unit => '%', min => 0, max => 100, unit => '%', label_extra_instance => 1 },
label_multi_instances => 1, multi_use => 'multi_absolute',
label_extra_instance => 1, instance_use => 'display_absolute' },
], ],
} }
}, },
{ label => 'cpu-steal', set => { { label => 'cpu-steal', set => {
key_values => [ { name => 'steal' }, { name => 'multi' }, { name => 'display' } ], key_values => [ { name => 'steal' }, { name => 'display' } ],
output_template => 'Steal: %.2f %%', output_template => 'Steal: %.2f %%',
perfdatas => [ perfdatas => [
{ label => 'steal', value => 'steal_absolute', template => '%.2f', { label => 'steal', value => 'steal_absolute', template => '%.2f',
min => 0, max => 100, unit => '%', min => 0, max => 100, unit => '%', label_extra_instance => 1 },
label_multi_instances => 1, multi_use => 'multi_absolute',
label_extra_instance => 1, instance_use => 'display_absolute' },
], ],
} }
}, },
{ label => 'cpu-system', set => { { label => 'cpu-system', set => {
key_values => [ { name => 'system' }, { name => 'multi' }, { name => 'display' } ], key_values => [ { name => 'system' }, { name => 'display' } ],
output_template => 'System: %.2f %%', output_template => 'System: %.2f %%',
perfdatas => [ perfdatas => [
{ label => 'system', value => 'system_absolute', template => '%.2f', { label => 'system', value => 'system_absolute', template => '%.2f',
min => 0, max => 100, unit => '%', min => 0, max => 100, unit => '%', label_extra_instance => 1 },
label_multi_instances => 1, multi_use => 'multi_absolute',
label_extra_instance => 1, instance_use => 'display_absolute' },
], ],
} }
}, },
{ label => 'cpu-nice', set => { { label => 'cpu-nice', set => {
key_values => [ { name => 'nice' }, { name => 'multi' }, { name => 'display' } ], key_values => [ { name => 'nice' }, { name => 'display' } ],
output_template => 'Nice: %.2f %%', output_template => 'Nice: %.2f %%',
perfdatas => [ perfdatas => [
{ label => 'nice', value => 'nice_absolute', template => '%.2f', { label => 'nice', value => 'nice_absolute', template => '%.2f',
min => 0, max => 100, unit => '%', min => 0, max => 100, unit => '%', label_extra_instance => 1 },
label_multi_instances => 1, multi_use => 'multi_absolute',
label_extra_instance => 1, instance_use => 'display_absolute' },
], ],
} }
}, },
]; ];
} }
sub prefix_nodes_output { sub prefix_node_output {
my ($self, %options) = @_; my ($self, %options) = @_;
return "Node '" . $options{instance_value}->{display} . "' "; return "Node '" . $options{instance_value}->{display} . "' ";
} }
sub node_long_output {
my ($self, %options) = @_;
return "Checking node '" . $options{instance_value}->{display} . "'";
}
sub prefix_global_cpu_output {
my ($self, %options) = @_;
return "CPU Average ";
}
sub prefix_cpu_output { sub prefix_cpu_output {
my ($self, %options) = @_; my ($self, %options) = @_;
return "Node '" . $options{instance_value}->{multi} . "' " . "Cpu '" . $options{instance_value}->{display} . "' "; return "CPU '" . $options{instance_value}->{display} . "' ";
} }
sub new { sub new {
@ -276,16 +276,15 @@ sub manage_selection {
foreach my $result (@{$results}) { foreach my $result (@{$results}) {
my $average = $options{custom}->compute(aggregation => 'average', values => $result->{values}); my $average = $options{custom}->compute(aggregation => 'average', values => $result->{values});
$self->{nodes}->{$result->{metric}->{$self->{labels}->{instance}}}->{display} = $result->{metric}->{$self->{labels}->{instance}}; $self->{nodes}->{$result->{metric}->{$self->{labels}->{instance}}}->{display} = $result->{metric}->{$self->{labels}->{instance}};
$self->{nodes}->{$result->{metric}->{$self->{labels}->{instance}}}->{$result->{metric}->{$self->{labels}->{type}}} += $average; $self->{nodes}->{$result->{metric}->{$self->{labels}->{instance}}}->{global_cpu}->{$result->{metric}->{$self->{labels}->{type}}} += $average;
$self->{nodes}->{$result->{metric}->{$self->{labels}->{instance}}}->{cpu}->{$result->{metric}->{$self->{labels}->{cpu}}}->{multi} = $result->{metric}->{$self->{labels}->{instance}};
$self->{nodes}->{$result->{metric}->{$self->{labels}->{instance}}}->{cpu}->{$result->{metric}->{$self->{labels}->{cpu}}}->{display} = $result->{metric}->{$self->{labels}->{cpu}}; $self->{nodes}->{$result->{metric}->{$self->{labels}->{instance}}}->{cpu}->{$result->{metric}->{$self->{labels}->{cpu}}}->{display} = $result->{metric}->{$self->{labels}->{cpu}};
$self->{nodes}->{$result->{metric}->{$self->{labels}->{instance}}}->{cpu}->{$result->{metric}->{$self->{labels}->{cpu}}}->{$result->{metric}->{$self->{labels}->{type}}} = $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}}) {
foreach my $metric (keys %{$self->{nodes}->{$node}}) { foreach my $metric (keys %{$self->{nodes}->{$node}->{global_cpu}}) {
next if ($metric =~ /cpu|display/); next if ($metric =~ /cpu|display/);
$self->{nodes}->{$node}->{$metric} /= scalar(keys %{$self->{nodes}->{$node}->{cpu}}); $self->{nodes}->{$node}->{global_cpu}->{$metric} /= scalar(keys %{$self->{nodes}->{$node}->{cpu}});
} }
} }

View File

@ -30,15 +30,14 @@ my $instance_mode;
sub custom_usage_perfdata { sub custom_usage_perfdata {
my ($self, %options) = @_; my ($self, %options) = @_;
my $extra_label = '';
$extra_label = '_' . $self->{result_values}->{label} if (!defined($options{extra_instance}) || $options{extra_instance} != 0);
my $label = 'used'; my $label = 'used';
my $value_perf = $self->{result_values}->{used}; my $value_perf = $self->{result_values}->{used};
if (defined($instance_mode->{option_results}->{free})) { if (defined($instance_mode->{option_results}->{free})) {
$label = 'free'; $label = 'free';
$value_perf = $self->{result_values}->{free}; $value_perf = $self->{result_values}->{free};
} }
my $extra_label = '';
$extra_label = '_' . $self->{result_values}->{multi} if (!defined($options{extra_instance}) || $options{extra_instance} != 0);
$extra_label .= '_' . $self->{result_values}->{display} if (!defined($options{extra_instance_lvl2}) || $options{extra_instance_lvl2} != 0);
my %total_options = (); my %total_options = ();
if ($instance_mode->{option_results}->{units} eq '%') { if ($instance_mode->{option_results}->{units} eq '%') {
$total_options{total} = $self->{result_values}->{total}; $total_options{total} = $self->{result_values}->{total};
@ -82,8 +81,8 @@ sub custom_usage_output {
sub custom_usage_calc { sub custom_usage_calc {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{result_values}->{label} = $self->{instance};
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
$self->{result_values}->{multi} = $options{new_datas}->{$self->{instance} . '_multi'};
$self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_size'}; $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_size'};
$self->{result_values}->{free} = $options{new_datas}->{$self->{instance} . '_free'}; $self->{result_values}->{free} = $options{new_datas}->{$self->{instance} . '_free'};
$self->{result_values}->{used} = $self->{result_values}->{total} - $self->{result_values}->{free}; $self->{result_values}->{used} = $self->{result_values}->{total} - $self->{result_values}->{free};
@ -104,32 +103,44 @@ 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 storages usage are ok', { name => 'nodes', type => 3, cb_prefix_output => 'prefix_node_output', cb_long_output => 'node_long_output',
counters => [ { name => 'storage', type => 1, cb_prefix_output => 'prefix_storage_output', message_multiple => 'All storages usage are ok' } ] }, message_multiple => 'All nodes storages usage are ok', indent_long_output => ' ',
group => [
{ name => 'storage', display_long => 1, cb_prefix_output => 'prefix_storage_output',
message_multiple => 'All storages usage are ok', type => 1, skipped_code => { -10 => 1 } },
]
}
]; ];
$self->{maps_counters}->{storage} = [ $self->{maps_counters}->{storage} = [
{ label => 'usage', set => { { label => 'usage', set => {
key_values => [ { name => 'free' }, { name => 'size' }, { name => 'multi' }, { name => 'display' } ], key_values => [ { name => 'free' }, { name => 'size' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_usage_calc'), closure_custom_calc => $self->can('custom_usage_calc'),
closure_custom_output => $self->can('custom_usage_output'), closure_custom_output => $self->can('custom_usage_output'),
closure_custom_perfdata => $self->can('custom_usage_perfdata'), closure_custom_perfdata => $self->can('custom_usage_perfdata'),
closure_custom_threshold_check => $self->can('custom_usage_threshold'), closure_custom_threshold_check => $self->can('custom_usage_threshold'),
label_extra_instance => 1, instance_use => 'display'
} }
}, },
]; ];
} }
sub prefix_nodes_output { sub prefix_node_output {
my ($self, %options) = @_; my ($self, %options) = @_;
return "Node '" . $options{instance_value}->{display} . "'"; return "Node '" . $options{instance_value}->{display} . "' ";
}
sub node_long_output {
my ($self, %options) = @_;
return "Checking node '" . $options{instance_value}->{display} . "'";
} }
sub prefix_storage_output { sub prefix_storage_output {
my ($self, %options) = @_; my ($self, %options) = @_;
return "Node '" . $options{instance_value}->{multi} . "' Storage '" . $options{instance_value}->{display} . "' "; return "Storage '" . $options{instance_value}->{display} . "' ";
} }
sub new { sub new {
@ -200,7 +211,6 @@ sub manage_selection {
foreach my $result (@{$results}) { foreach my $result (@{$results}) {
$self->{nodes}->{$result->{metric}->{$self->{labels}->{instance}}}->{display} = $result->{metric}->{$self->{labels}->{instance}}; $self->{nodes}->{$result->{metric}->{$self->{labels}->{instance}}}->{display} = $result->{metric}->{$self->{labels}->{instance}};
$self->{nodes}->{$result->{metric}->{$self->{labels}->{instance}}}->{storage}->{$result->{metric}->{mountpoint}}->{multi} = $result->{metric}->{$self->{labels}->{instance}};
$self->{nodes}->{$result->{metric}->{$self->{labels}->{instance}}}->{storage}->{$result->{metric}->{mountpoint}}->{display} = $result->{metric}->{$self->{labels}->{mountpoint}}; $self->{nodes}->{$result->{metric}->{$self->{labels}->{instance}}}->{storage}->{$result->{metric}->{mountpoint}}->{display} = $result->{metric}->{$self->{labels}->{mountpoint}};
$self->{nodes}->{$result->{metric}->{$self->{labels}->{instance}}}->{storage}->{$result->{metric}->{mountpoint}}->{$result->{metric}->{__name__}} = ${$result->{value}}[1]; $self->{nodes}->{$result->{metric}->{$self->{labels}->{instance}}}->{storage}->{$result->{metric}->{mountpoint}}->{$result->{metric}->{__name__}} = ${$result->{value}}[1];
} }