adjust/move prometheus perfdata + cleaning

This commit is contained in:
Colin Gagnaire 2019-06-07 16:07:27 +02:00
parent f35d452a35
commit 9e76630bd6
8 changed files with 130 additions and 110 deletions

View File

@ -99,7 +99,6 @@ sub new {
"critical-status:s" => { name => 'critical_status', default => '%{status} !~ /running/ || %{state} !~ /ready/' },
"extra-filter:s@" => { name => 'extra_filter' },
"metric-overload:s@" => { name => 'metric_overload' },
"filter-counters:s" => { name => 'filter_counters' },
});
return $self;

View File

@ -106,7 +106,6 @@ sub new {
$self->{version} = '1.0';
$options{options}->add_options(arguments => {
"filter-counters:s" => { name => 'filter_counters' },
"extra-filter:s@" => { name => 'extra_filter' },
"metric-overload:s@" => { name => 'metric_overload' },
});

View File

@ -104,7 +104,6 @@ sub new {
$self->{version} = '1.0';
$options{options}->add_options(arguments => {
"filter-counters:s" => { name => 'filter_counters' },
"extra-filter:s@" => { name => 'extra_filter' },
"metric-overload:s@" => { name => 'metric_overload' },
});

View File

@ -40,7 +40,7 @@ sub set_counters {
];
$self->{maps_counters}->{global_cpu} = [
{ label => 'node-usage', set => {
{ label => 'node-usage', nlabel => 'node.cpu.utilization.percentage', set => {
key_values => [ { name => 'node_average' } ],
output_template => '%.2f %%',
perfdatas => [
@ -51,7 +51,7 @@ sub set_counters {
},
];
$self->{maps_counters}->{cpu} = [
{ label => 'cpu-usage', set => {
{ label => 'cpu-usage', nlabel => 'core.cpu.utilization.percentage', set => {
key_values => [ { name => 'cpu_usage' }, { name => 'display' } ],
output_template => 'Usage: %.2f %%',
perfdatas => [
@ -93,14 +93,12 @@ sub new {
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"instance:s" => { name => 'instance', default => 'instance=~".*"' },
"cpu:s" => { name => 'cpu', default => 'cpu=~".*"' },
"extra-filter:s@" => { name => 'extra_filter' },
"metric-overload:s@" => { name => 'metric_overload' },
"filter-counters:s" => { name => 'filter_counters' },
});
$options{options}->add_options(arguments => {
"instance:s" => { name => 'instance', default => 'instance=~".*"' },
"cpu:s" => { name => 'cpu', default => 'cpu=~".*"' },
"extra-filter:s@" => { name => 'extra_filter' },
"metric-overload:s@" => { name => 'metric_overload' },
});
return $self;
}
@ -140,12 +138,16 @@ sub manage_selection {
$self->{nodes} = {};
my $results = $options{custom}->query_range(queries => [ '(1 - irate({__name__=~"' . $self->{metrics}->{cpu} . '",' .
'mode="idle",' .
$self->{option_results}->{instance} . ',' .
$self->{option_results}->{cpu} .
$self->{extra_filter} . '}[' . $self->{prom_step} . '])) * 100' ],
timeframe => $self->{prom_timeframe}, step => $self->{prom_step});
my $results = $options{custom}->query_range(
queries => [
'(1 - irate({__name__=~"' . $self->{metrics}->{cpu} . '",' .
'mode="idle",' .
$self->{option_results}->{instance} . ',' .
$self->{option_results}->{cpu} .
$self->{extra_filter} . '}[' . $self->{prom_step} . '])) * 100'
],
timeframe => $self->{prom_timeframe}, step => $self->{prom_step}
);
foreach my $result (@{$results}) {
my $average = $options{custom}->compute(aggregation => 'average', values => $result->{values});

View File

@ -40,7 +40,7 @@ sub set_counters {
];
$self->{maps_counters}->{global_cpu} = [
{ label => 'node-wait', set => {
{ label => 'node-wait', nlabel => 'node.cpu.wait.utilization.percentage', set => {
key_values => [ { name => 'iowait' } ],
output_template => 'Wait: %.2f %%',
perfdatas => [
@ -49,7 +49,7 @@ sub set_counters {
],
}
},
{ label => 'node-user', set => {
{ label => 'node-user', nlabel => 'node.cpu.user.utilization.percentage', set => {
key_values => [ { name => 'user' } ],
output_template => 'User: %.2f %%',
perfdatas => [
@ -58,7 +58,7 @@ sub set_counters {
],
}
},
{ label => 'node-softirq', set => {
{ label => 'node-softirq', nlabel => 'node.cpu.softirq.utilization.percentage', set => {
key_values => [ { name => 'softirq' } ],
output_template => 'Soft Irq: %.2f %%',
perfdatas => [
@ -67,7 +67,7 @@ sub set_counters {
],
}
},
{ label => 'node-interrupt', set => {
{ label => 'node-interrupt', nlabel => 'node.cpu.interrupt.utilization.percentage', set => {
key_values => [ { name => 'irq' } ],
output_template => 'Interrupt: %.2f %%',
perfdatas => [
@ -76,7 +76,7 @@ sub set_counters {
],
}
},
{ label => 'node-idle', set => {
{ label => 'node-idle', nlabel => 'node.cpu.idle.utilization.percentage', set => {
key_values => [ { name => 'idle' } ],
output_template => 'Idle: %.2f %%',
perfdatas => [
@ -85,7 +85,7 @@ sub set_counters {
],
}
},
{ label => 'node-steal', set => {
{ label => 'node-steal', nlabel => 'node.cpu.steal.utilization.percentage', set => {
key_values => [ { name => 'steal' } ],
output_template => 'Steal: %.2f %%',
perfdatas => [
@ -94,7 +94,7 @@ sub set_counters {
],
}
},
{ label => 'node-system', set => {
{ label => 'node-system', nlabel => 'node.cpu.system.utilization.percentage', set => {
key_values => [ { name => 'system' } ],
output_template => 'System: %.2f %%',
perfdatas => [
@ -103,7 +103,7 @@ sub set_counters {
],
}
},
{ label => 'node-nice', set => {
{ label => 'node-nice', nlabel => 'node.cpu.nice.utilization.percentage', set => {
key_values => [ { name => 'nice' } ],
output_template => 'Nice: %.2f %%',
perfdatas => [
@ -114,7 +114,7 @@ sub set_counters {
},
];
$self->{maps_counters}->{cpu} = [
{ label => 'cpu-wait', set => {
{ label => 'cpu-wait', nlabel => 'core.cpu.wait.utilization.percentage', set => {
key_values => [ { name => 'iowait' }, { name => 'display' } ],
output_template => 'Wait: %.2f %%',
perfdatas => [
@ -123,7 +123,7 @@ sub set_counters {
],
}
},
{ label => 'cpu-user', set => {
{ label => 'cpu-user', nlabel => 'core.cpu.user.utilization.percentage', set => {
key_values => [ { name => 'user' }, { name => 'display' } ],
output_template => 'User: %.2f %%',
perfdatas => [
@ -132,7 +132,7 @@ sub set_counters {
],
}
},
{ label => 'cpu-softirq', set => {
{ label => 'cpu-softirq', nlabel => 'core.cpu.softirq.utilization.percentage', set => {
key_values => [ { name => 'softirq' }, { name => 'display' } ],
output_template => 'Soft Irq: %.2f %%',
perfdatas => [
@ -141,7 +141,7 @@ sub set_counters {
],
}
},
{ label => 'cpu-interrupt', set => {
{ label => 'cpu-interrupt', nlabel => 'core.cpu.interrupt.utilization.percentage', set => {
key_values => [ { name => 'irq' }, { name => 'display' } ],
output_template => 'Interrupt: %.2f %%',
perfdatas => [
@ -150,7 +150,7 @@ sub set_counters {
],
}
},
{ label => 'cpu-idle', set => {
{ label => 'cpu-idle', nlabel => 'core.cpu.idle.utilization.percentage', set => {
key_values => [ { name => 'idle' }, { name => 'display' } ],
output_template => 'Idle: %.2f %%',
perfdatas => [
@ -159,7 +159,7 @@ sub set_counters {
],
}
},
{ label => 'cpu-steal', set => {
{ label => 'cpu-steal', nlabel => 'core.cpu.steal.utilization.percentage', set => {
key_values => [ { name => 'steal' }, { name => 'display' } ],
output_template => 'Steal: %.2f %%',
perfdatas => [
@ -168,7 +168,7 @@ sub set_counters {
],
}
},
{ label => 'cpu-system', set => {
{ label => 'cpu-system', nlabel => 'core.cpu.system.utilization.percentage', set => {
key_values => [ { name => 'system' }, { name => 'display' } ],
output_template => 'System: %.2f %%',
perfdatas => [
@ -177,7 +177,7 @@ sub set_counters {
],
}
},
{ label => 'cpu-nice', set => {
{ label => 'cpu-nice', nlabel => 'core.cpu.nice.utilization.percentage', set => {
key_values => [ { name => 'nice' }, { name => 'display' } ],
output_template => 'Nice: %.2f %%',
perfdatas => [
@ -219,15 +219,13 @@ sub new {
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"instance:s" => { name => 'instance', default => 'instance=~".*"' },
"cpu:s" => { name => 'cpu', default => 'cpu=~".*"' },
"type:s" => { name => 'type', default => 'mode=~".*"' },
"extra-filter:s@" => { name => 'extra_filter' },
"metric-overload:s@" => { name => 'metric_overload' },
"filter-counters:s" => { name => 'filter_counters' },
});
$options{options}->add_options(arguments => {
"instance:s" => { name => 'instance', default => 'instance=~".*"' },
"cpu:s" => { name => 'cpu', default => 'cpu=~".*"' },
"type:s" => { name => 'type', default => 'mode=~".*"' },
"extra-filter:s@" => { name => 'extra_filter' },
"metric-overload:s@" => { name => 'metric_overload' },
});
return $self;
}
@ -267,12 +265,16 @@ sub manage_selection {
$self->{nodes} = {};
my $results = $options{custom}->query_range(queries => [ '(irate({__name__=~"' . $self->{metrics}->{cpu} . '",' .
$self->{option_results}->{instance} . ',' .
$self->{option_results}->{cpu} . ',' .
$self->{option_results}->{type} .
$self->{extra_filter} . '}[' . $self->{prom_step} . '])) * 100' ],
timeframe => $self->{prom_timeframe}, step => $self->{prom_step});
my $results = $options{custom}->query_range(
queries => [
'(irate({__name__=~"' . $self->{metrics}->{cpu} . '",' .
$self->{option_results}->{instance} . ',' .
$self->{option_results}->{cpu} . ',' .
$self->{option_results}->{type} .
$self->{extra_filter} . '}[' . $self->{prom_step} . '])) * 100'
],
timeframe => $self->{prom_timeframe}, step => $self->{prom_step}
);
foreach my $result (@{$results}) {
my $average = $options{custom}->compute(aggregation => 'average', values => $result->{values});

View File

@ -33,7 +33,7 @@ sub set_counters {
];
$self->{maps_counters}->{nodes} = [
{ label => 'load1', set => {
{ label => 'load1', nlabel => 'load.1minute.count', set => {
key_values => [ { name => 'load1' }, { name => 'display' } ],
output_template => 'Load 1 minute: %.2f',
output_change_bytes => 1,
@ -43,7 +43,7 @@ sub set_counters {
],
}
},
{ label => 'load5', set => {
{ label => 'load5', nlabel => 'load.5minutes.count', set => {
key_values => [ { name => 'load5' }, { name => 'display' } ],
output_template => 'Load 5 minutes: %.2f',
output_change_bytes => 1,
@ -53,7 +53,7 @@ sub set_counters {
],
}
},
{ label => 'load15', set => {
{ label => 'load15', nlabel => 'load.15minutes.count', set => {
key_values => [ { name => 'load15' }, { name => 'display' } ],
output_template => 'Load 15 minutes: %.2f',
output_change_bytes => 1,
@ -78,13 +78,11 @@ sub new {
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"instance:s" => { name => 'instance', default => 'instance=~".*"' },
"extra-filter:s@" => { name => 'extra_filter' },
"metric-overload:s@" => { name => 'metric_overload' },
"filter-counters:s" => { name => 'filter_counters' },
});
$options{options}->add_options(arguments => {
"instance:s" => { name => 'instance', default => 'instance=~".*"' },
"extra-filter:s@" => { name => 'extra_filter' },
"metric-overload:s@" => { name => 'metric_overload' },
});
return $self;
}
@ -123,15 +121,19 @@ sub manage_selection {
$self->{nodes} = {};
my $results = $options{custom}->query(queries => [ 'label_replace({__name__=~"' . $self->{metrics}->{load1} . '",' .
$self->{option_results}->{instance} .
$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} . '",' .
$self->{option_results}->{instance} .
$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", "", "")'
]
);
foreach my $result (@{$results}) {
$self->{nodes}->{$result->{metric}->{$self->{labels}->{instance}}}->{display} = $result->{metric}->{$self->{labels}->{instance}};

View File

@ -30,19 +30,22 @@ sub custom_usage_perfdata {
my $label = 'used';
my $value_perf = $self->{result_values}->{used};
my $extra_label = '';
$extra_label = '_' . $self->{result_values}->{display} if (!defined($options{extra_instance}) || $options{extra_instance} != 0);
my %total_options = ();
if ($self->{instance_mode}->{option_results}->{units} eq '%') {
$total_options{total} = $self->{result_values}->{total};
$total_options{cast_int} = 1;
}
$self->{output}->perfdata_add(label => $label . $extra_label, unit => 'B',
value => $value_perf,
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options),
min => 0, max => $self->{result_values}->{total});
$self->{output}->perfdata_add(
label => $label, unit => 'B',
nlabel => '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}->{total},
instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef,
);
}
sub custom_usage_threshold {
@ -53,8 +56,9 @@ sub custom_usage_threshold {
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->{label}, exit_litteral => 'critical' },
{ label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]);
$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;
}
@ -100,7 +104,7 @@ sub set_counters {
closure_custom_threshold_check => $self->can('custom_usage_threshold'),
}
},
{ label => 'buffer', set => {
{ label => 'buffer', nlabel => 'buffer.usage.bytes', set => {
key_values => [ { name => 'buffer' }, { name => 'display' } ],
output_template => 'Buffer: %.2f %s',
output_change_bytes => 1,
@ -110,7 +114,7 @@ sub set_counters {
],
}
},
{ label => 'cached', set => {
{ label => 'cached', nlabel => 'cache.usage.bytes', set => {
key_values => [ { name => 'cached' }, { name => 'display' } ],
output_template => 'Cached: %.2f %s',
output_change_bytes => 1,
@ -180,18 +184,22 @@ sub manage_selection {
$self->{nodes} = {};
my $results = $options{custom}->query(queries => [ 'label_replace({__name__=~"' . $self->{metrics}->{total} . '",' .
$self->{option_results}->{instance} .
$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} . '",' .
$self->{option_results}->{instance} .
$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", "", "")'
]
);
foreach my $result (@{$results}) {
$self->{nodes}->{$result->{metric}->{$self->{labels}->{instance}}}->{display} = $result->{metric}->{$self->{labels}->{instance}};

View File

@ -28,10 +28,9 @@ use warnings;
sub custom_usage_perfdata {
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 $value_perf = $self->{result_values}->{used};
if (defined($self->{instance_mode}->{option_results}->{free})) {
$label = 'free';
$value_perf = $self->{result_values}->{free};
@ -42,11 +41,15 @@ sub custom_usage_perfdata {
$total_options{cast_int} = 1;
}
$self->{output}->perfdata_add(label => $label . $extra_label, unit => 'B',
value => $value_perf,
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options),
min => 0, max => $self->{result_values}->{total});
$self->{output}->perfdata_add(
label => $label . $extra_label, unit => 'B',
nlabel => '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}->{total}
instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef,
);
}
sub custom_usage_threshold {
@ -59,7 +62,9 @@ sub custom_usage_threshold {
$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->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]);
$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;
}
@ -193,16 +198,20 @@ sub manage_selection {
$self->{nodes} = {};
my $results = $options{custom}->query(queries => [ 'label_replace({__name__=~"' . $self->{metrics}->{free} . '",' .
$self->{option_results}->{instance} . ',' .
$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} . '",' .
$self->{option_results}->{instance} . ',' .
$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", "", "")'
]
);
foreach my $result (@{$results}) {
$self->{nodes}->{$result->{metric}->{$self->{labels}->{instance}}}->{display} = $result->{metric}->{$self->{labels}->{instance}};