adjust/move prometheus perfdata + cleaning

This commit is contained in:
Colin Gagnaire 2019-06-07 17:35:01 +02:00
parent ea6e1fe34d
commit 2d9067455a
6 changed files with 153 additions and 125 deletions

View File

@ -34,7 +34,7 @@ sub set_counters {
];
$self->{maps_counters}->{containers} = [
{ label => 'usage', set => {
{ label => 'usage', nlabel => 'container.cpu.utilization.percentage', set => {
key_values => [ { name => 'usage' }, { name => 'container' }, { name => 'pod' }, { name => 'perf' } ],
output_template => 'Usage: %.2f %%',
perfdatas => [
@ -44,7 +44,7 @@ sub set_counters {
],
}
},
{ label => 'throttled', set => {
{ label => 'throttled', nlabel => 'container.cpu.throttled.percentage', set => {
key_values => [ { name => 'throttled' }, { name => 'container' }, { name => 'pod' }, { name => 'perf' } ],
output_template => 'Throttled: %.2f %%',
perfdatas => [
@ -69,15 +69,13 @@ sub new {
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"cpu-attribute:s" => { name => 'cpu_attribute', default => 'cpu="total"' },
"container:s" => { name => 'container', default => 'container_name!~".*POD.*"' },
"pod:s" => { name => 'pod', default => 'pod_name=~".*"' },
"extra-filter:s@" => { name => 'extra_filter' },
"metric-overload:s@" => { name => 'metric_overload' },
"filter-counters:s" => { name => 'filter_counters' },
});
$options{options}->add_options(arguments => {
"cpu-attribute:s" => { name => 'cpu_attribute', default => 'cpu="total"' },
"container:s" => { name => 'container', default => 'container_name!~".*POD.*"' },
"pod:s" => { name => 'pod', default => 'pod_name=~".*"' },
"extra-filter:s@" => { name => 'extra_filter' },
"metric-overload:s@" => { name => 'metric_overload' },
});
return $self;
}
@ -118,16 +116,21 @@ sub manage_selection {
$self->{containers} = {};
my $results = $options{custom}->query_range(queries => [ 'label_replace((irate({__name__=~"' . $self->{metrics}->{usage} . '",' .
$self->{option_results}->{cpu_attribute} . ',' .
$self->{option_results}->{container} . ',' .
$self->{option_results}->{pod} .
$self->{extra_filter} . '}[' . $self->{prom_step} . '])) * 100, "__name__", "usage", "", "")',
'label_replace((irate({__name__=~"' . $self->{metrics}->{throttled} . '",' .
$self->{option_results}->{container} . ',' .
$self->{option_results}->{pod} .
$self->{extra_filter} . '}[' . $self->{prom_step} . '])) * 100, "__name__", "throttled", "", "")' ],
timeframe => $self->{prom_timeframe}, step => $self->{prom_step});
my $results = $options{custom}->query_range(
queries => [
'label_replace((irate({__name__=~"' . $self->{metrics}->{usage} . '",' .
$self->{option_results}->{cpu_attribute} . ',' .
$self->{option_results}->{container} . ',' .
$self->{option_results}->{pod} .
$self->{extra_filter} . '}[' . $self->{prom_step} . '])) * 100, "__name__", "usage", "", "")',
'label_replace((irate({__name__=~"' . $self->{metrics}->{throttled} . '",' .
$self->{option_results}->{container} . ',' .
$self->{option_results}->{pod} .
$self->{extra_filter} . '}[' . $self->{prom_step} . '])) * 100, "__name__", "throttled", "", "")'
],
timeframe => $self->{prom_timeframe},
step => $self->{prom_step}
);
foreach my $result (@{$results}) {
next if (!defined($result->{metric}->{$self->{labels}->{pod}}) || !defined($result->{metric}->{$self->{labels}->{container}}));

View File

@ -29,11 +29,12 @@ sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'containers', type => 1, cb_prefix_output => 'prefix_containers_output', message_multiple => 'All containers load are ok' },
{ name => 'containers', type => 1, cb_prefix_output => 'prefix_containers_output',
message_multiple => 'All containers load are ok' },
];
$self->{maps_counters}->{containers} = [
{ label => 'load', set => {
{ label => 'load', nlabel => 'container.load.count', set => {
key_values => [ { name => 'load' }, { name => 'container' }, { name => 'pod' }, { name => 'perf' } ],
output_template => 'Load: %.2f',
output_change_bytes => 1,
@ -58,13 +59,12 @@ sub new {
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"container:s" => { name => 'container', default => 'container_name!~".*POD.*"' },
"pod:s" => { name => 'pod', default => 'pod_name=~".*"' },
"extra-filter:s@" => { name => 'extra_filter' },
"metric-overload:s@" => { name => 'metric_overload' },
});
$options{options}->add_options(arguments => {
"container:s" => { name => 'container', default => 'container_name!~".*POD.*"' },
"pod:s" => { name => 'pod', default => 'pod_name=~".*"' },
"extra-filter:s@" => { name => 'extra_filter' },
"metric-overload:s@" => { name => 'metric_overload' },
});
return $self;
}
@ -74,7 +74,7 @@ sub check_options {
$self->SUPER::check_options(%options);
$self->{metrics} = {
'load' => '^container_cpu_load_average_10s$',
'load' => '^container_cpu_load_average_10s$',
};
foreach my $metric (@{$self->{option_results}->{metric_overload}}) {
next if ($metric !~ /(.*),(.*)/);
@ -104,11 +104,16 @@ sub manage_selection {
$self->{containers} = {};
my $results = $options{custom}->query_range(queries => [ 'label_replace({__name__=~"' . $self->{metrics}->{load} . '",' .
$self->{option_results}->{container} . ',' .
$self->{option_results}->{pod} .
$self->{extra_filter} . '}, "__name__", "load", "", "")' ],
timeframe => $self->{prom_timeframe}, step => $self->{prom_step});
my $results = $options{custom}->query_range(
queries => [
'label_replace({__name__=~"' . $self->{metrics}->{load} . '",' .
$self->{option_results}->{container} . ',' .
$self->{option_results}->{pod} .
$self->{extra_filter} . '}, "__name__", "load", "", "")'
],
timeframe => $self->{prom_timeframe},
step => $self->{prom_step}
);
foreach my $result (@{$results}) {
next if (!defined($result->{metric}->{$self->{labels}->{pod}}) || !defined($result->{metric}->{$self->{labels}->{container}}));

View File

@ -30,19 +30,22 @@ sub custom_usage_perfdata {
my $label = $self->{result_values}->{perfdata};
my $value_perf = $self->{result_values}->{used};
my $extra_label = '';
$extra_label = '_' . $self->{result_values}->{perf} if (!defined($options{extra_instance}) || $options{extra_instance} != 0);
my %total_options = ();
if ($self->{result_values}->{total} > 0 && $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->{result_values}->{label}, %total_options),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{result_values}->{label}, %total_options),
min => 0, max => $total_options{total});
$self->{output}->perfdata_add(
label => $label, unit => 'B',
nlabel => 'memory.' . $label . '.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 {
@ -54,8 +57,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->{result_values}->{label}, exit_litteral => 'critical' },
{ label => 'warning-'. $self->{result_values}->{label}, exit_litteral => 'warning' } ]);
$exit = $self->{perfdata}->threshold_check(value => $threshold_value,
threshold => [ { label => 'critical-' . $self->{result_values}->{thlabel}, exit_litteral => 'critical' },
{ label => 'warning-'. $self->{result_values}->{thlabel}, exit_litteral => 'warning' } ]);
return $exit;
}
@ -97,7 +101,8 @@ sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'containers', type => 1, cb_prefix_output => 'prefix_containers_output', message_multiple => 'All containers memory usage are ok' },
{ name => 'containers', type => 1, cb_prefix_output => 'prefix_containers_output',
message_multiple => 'All containers memory usage are ok' },
];
$self->{maps_counters}->{containers} = [
@ -121,7 +126,7 @@ sub set_counters {
closure_custom_threshold_check => $self->can('custom_usage_threshold'),
}
},
{ label => 'cache', set => {
{ label => 'cache', nlabel => 'cache.usage.bytes', set => {
key_values => [ { name => 'cache' }, { name => 'container' }, { name => 'pod' }, { name => 'perf' } ],
output_template => 'Cache: %.2f %s',
output_change_bytes => 1,
@ -131,7 +136,7 @@ sub set_counters {
],
}
},
{ label => 'rss', set => {
{ label => 'rss', nlabel => 'rss.usage.bytes', set => {
key_values => [ { name => 'rss' }, { name => 'container' }, { name => 'pod' }, { name => 'perf' } ],
output_template => 'Rss: %.2f %s',
output_change_bytes => 1,
@ -141,7 +146,7 @@ sub set_counters {
],
}
},
{ label => 'swap', set => {
{ label => 'swap', nlabel => 'swap.usage.bytes', set => {
key_values => [ { name => 'swap' }, { name => 'container' }, { name => 'pod' }, { name => 'perf' } ],
output_template => 'Swap: %.2f %s',
output_change_bytes => 1,
@ -167,12 +172,11 @@ sub new {
$self->{version} = '1.0';
$options{options}->add_options(arguments => {
"container:s" => { name => 'container', default => 'container_name!~".*POD.*"' },
"pod:s" => { name => 'pod', default => 'pod_name=~".*"' },
"extra-filter:s@" => { name => 'extra_filter' },
"units:s" => { name => 'units', default => '%' },
"metric-overload:s@" => { name => 'metric_overload' },
"filter-counters:s" => { name => 'filter_counters' },
"container:s" => { name => 'container', default => 'container_name!~".*POD.*"' },
"pod:s" => { name => 'pod', default => 'pod_name=~".*"' },
"extra-filter:s@" => { name => 'extra_filter' },
"units:s" => { name => 'units', default => '%' },
"metric-overload:s@" => { name => 'metric_overload' },
});
return $self;
@ -215,30 +219,34 @@ sub manage_selection {
$self->{containers} = {};
my $results = $options{custom}->query(queries => [ 'label_replace({__name__=~"' . $self->{metrics}->{usage} . '",' .
$self->{option_results}->{container} . ',' .
$self->{option_results}->{pod} .
$self->{extra_filter} . '}, "__name__", "usage", "", "")',
'label_replace({__name__=~"' . $self->{metrics}->{limits} . '",' .
$self->{option_results}->{container} . ',' .
$self->{option_results}->{pod} .
$self->{extra_filter} . '}, "__name__", "limits", "", "")',
'label_replace({__name__=~"' . $self->{metrics}->{working} . '",' .
$self->{option_results}->{container} . ',' .
$self->{option_results}->{pod} .
$self->{extra_filter} . '}, "__name__", "working", "", "")',
'label_replace({__name__=~"' . $self->{metrics}->{cache} . '",' .
$self->{option_results}->{container} . ',' .
$self->{option_results}->{pod} .
$self->{extra_filter} . '}, "__name__", "cache", "", "")',
'label_replace({__name__=~"' . $self->{metrics}->{rss} . '",' .
$self->{option_results}->{container} . ',' .
$self->{option_results}->{pod} .
$self->{extra_filter} . '}, "__name__", "rss", "", "")',
'label_replace({__name__=~"' . $self->{metrics}->{swap} . '",' .
$self->{option_results}->{container} . ',' .
$self->{option_results}->{pod} .
$self->{extra_filter} . '}, "__name__", "swap", "", "")' ]);
my $results = $options{custom}->query(
queries => [
'label_replace({__name__=~"' . $self->{metrics}->{usage} . '",' .
$self->{option_results}->{container} . ',' .
$self->{option_results}->{pod} .
$self->{extra_filter} . '}, "__name__", "usage", "", "")',
'label_replace({__name__=~"' . $self->{metrics}->{limits} . '",' .
$self->{option_results}->{container} . ',' .
$self->{option_results}->{pod} .
$self->{extra_filter} . '}, "__name__", "limits", "", "")',
'label_replace({__name__=~"' . $self->{metrics}->{working} . '",' .
$self->{option_results}->{container} . ',' .
$self->{option_results}->{pod} .
$self->{extra_filter} . '}, "__name__", "working", "", "")',
'label_replace({__name__=~"' . $self->{metrics}->{cache} . '",' .
$self->{option_results}->{container} . ',' .
$self->{option_results}->{pod} .
$self->{extra_filter} . '}, "__name__", "cache", "", "")',
'label_replace({__name__=~"' . $self->{metrics}->{rss} . '",' .
$self->{option_results}->{container} . ',' .
$self->{option_results}->{pod} .
$self->{extra_filter} . '}, "__name__", "rss", "", "")',
'label_replace({__name__=~"' . $self->{metrics}->{swap} . '",' .
$self->{option_results}->{container} . ',' .
$self->{option_results}->{pod} .
$self->{extra_filter} . '}, "__name__", "swap", "", "")'
]
);
foreach my $result (@{$results}) {
next if (!defined($result->{metric}->{$self->{labels}->{pod}}) || !defined($result->{metric}->{$self->{labels}->{container}}));

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, unit => 'B',
nlabel => 'storage.space.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;
}
@ -148,13 +153,13 @@ sub new {
$self->{version} = '1.0';
$options{options}->add_options(arguments => {
"container:s" => { name => 'container', default => 'container_name!~".*POD.*"' },
"pod:s" => { name => 'pod', default => 'pod_name=~".*"' },
"device:s" => { name => 'device', default => 'device=~".*"' },
"extra-filter:s@" => { name => 'extra_filter' },
"units:s" => { name => 'units', default => '%' },
"free" => { name => 'free' },
"metric-overload:s@" => { name => 'metric_overload' },
"container:s" => { name => 'container', default => 'container_name!~".*POD.*"' },
"pod:s" => { name => 'pod', default => 'pod_name=~".*"' },
"device:s" => { name => 'device', default => 'device=~".*"' },
"extra-filter:s@" => { name => 'extra_filter' },
"units:s" => { name => 'units', default => '%' },
"free" => { name => 'free' },
"metric-overload:s@" => { name => 'metric_overload' },
});
return $self;
@ -193,16 +198,20 @@ sub manage_selection {
$self->{containers} = {};
my $results = $options{custom}->query(queries => [ 'label_replace({__name__=~"' . $self->{metrics}->{used} . '",' .
$self->{option_results}->{container} . ',' .
$self->{option_results}->{pod} . ',' .
$self->{option_results}->{device} .
$self->{extra_filter} . '}, "__name__", "used", "", "")',
'label_replace({__name__=~"' . $self->{metrics}->{limit} . '",' .
$self->{option_results}->{container} . ',' .
$self->{option_results}->{pod} . ',' .
$self->{option_results}->{device} .
$self->{extra_filter} . '}, "__name__", "limit", "", "")' ]);
my $results = $options{custom}->query(
queries => [
'label_replace({__name__=~"' . $self->{metrics}->{used} . '",' .
$self->{option_results}->{container} . ',' .
$self->{option_results}->{pod} . ',' .
$self->{option_results}->{device} .
$self->{extra_filter} . '}, "__name__", "used", "", "")',
'label_replace({__name__=~"' . $self->{metrics}->{limit} . '",' .
$self->{option_results}->{container} . ',' .
$self->{option_results}->{pod} . ',' .
$self->{option_results}->{device} .
$self->{extra_filter} . '}, "__name__", "limit", "", "")'
]
);
foreach my $result (@{$results}) {
next if (!defined($result->{metric}->{$self->{labels}->{pod}}) || !defined($result->{metric}->{$self->{labels}->{container}}));

View File

@ -30,11 +30,11 @@ sub set_counters {
$self->{maps_counters_type} = [
{ name => 'containers', type => 1, cb_prefix_output => 'prefix_containers_output',
message_multiple => 'All containers tasks states are ok', skipped_code => { -10 => 1 } },
message_multiple => 'All containers tasks states are ok', skipped_code => { -10 => 1 } },
];
$self->{maps_counters}->{containers} = [
{ label => 'sleeping', set => {
{ label => 'sleeping', nlabel => 'tasks.sleeping.count', set => {
key_values => [ { name => 'sleeping' }, { name => 'container' }, { name => 'pod' }, { name => 'perf' } ],
output_template => 'Sleeping: %d',
output_change_bytes => 1,
@ -44,7 +44,7 @@ sub set_counters {
],
}
},
{ label => 'running', set => {
{ label => 'running', nlabel => 'tasks.running.count', set => {
key_values => [ { name => 'running' }, { name => 'container' }, { name => 'pod' }, { name => 'perf' } ],
output_template => 'Running: %d',
output_change_bytes => 1,
@ -54,7 +54,7 @@ sub set_counters {
],
}
},
{ label => 'stopped', set => {
{ label => 'stopped', nlabel => 'tasks.stopped.count', set => {
key_values => [ { name => 'stopped' }, { name => 'container' }, { name => 'pod' }, { name => 'perf' } ],
output_template => 'Stopped: %d',
output_change_bytes => 1,
@ -64,7 +64,7 @@ sub set_counters {
],
}
},
{ label => 'uninterruptible', set => {
{ label => 'uninterruptible', nlabel => 'tasks.uninterruptible.count', set => {
key_values => [ { name => 'uninterruptible' }, { name => 'container' }, { name => 'pod' }, { name => 'perf' } ],
output_template => 'Uninterruptible: %d',
output_change_bytes => 1,
@ -74,7 +74,7 @@ sub set_counters {
],
}
},
{ label => 'iowaiting', set => {
{ label => 'iowaiting', nlabel => 'tasks.iowaiting.count', set => {
key_values => [ { name => 'iowaiting' }, { name => 'container' }, { name => 'pod' }, { name => 'perf' } ],
output_template => 'Iowaiting: %d',
output_change_bytes => 1,
@ -99,14 +99,13 @@ sub new {
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"container:s" => { name => 'container', default => 'container_name!~".*POD.*"' },
"pod:s" => { name => 'pod', default => 'pod_name=~".*"' },
"state:s" => { name => 'state', default => 'state=~".*"' },
"extra-filter:s@" => { name => 'extra_filter' },
"metric-overload:s@" => { name => 'metric_overload' },
});
$options{options}->add_options(arguments => {
"container:s" => { name => 'container', default => 'container_name!~".*POD.*"' },
"pod:s" => { name => 'pod', default => 'pod_name=~".*"' },
"state:s" => { name => 'state', default => 'state=~".*"' },
"extra-filter:s@" => { name => 'extra_filter' },
"metric-overload:s@" => { name => 'metric_overload' },
});
return $self;
}
@ -143,11 +142,15 @@ sub manage_selection {
$self->{containers} = {};
my $results = $options{custom}->query(queries => [ 'label_replace({__name__=~"' . $self->{metrics}->{tasks_state} . '",' .
$self->{option_results}->{container} . ',' .
$self->{option_results}->{pod} . ',' .
$self->{option_results}->{state} .
$self->{extra_filter} . '}, "__name__", "tasks_state", "", "")' ]);
my $results = $options{custom}->query(
queries => [
'label_replace({__name__=~"' . $self->{metrics}->{tasks_state} . '",' .
$self->{option_results}->{container} . ',' .
$self->{option_results}->{pod} . ',' .
$self->{option_results}->{state} .
$self->{extra_filter} . '}, "__name__", "tasks_state", "", "")'
]
);
foreach my $result (@{$results}) {
next if (!defined($result->{metric}->{$self->{labels}->{pod}}) || !defined($result->{metric}->{$self->{labels}->{container}}));

View File

@ -42,8 +42,8 @@ sub custom_usage_perfdata {
}
$self->{output}->perfdata_add(
label => $label . $extra_label, unit => 'B',
nlabel => 'memory.usage.bytes',
label => $label, unit => 'B',
nlabel => 'storage.space.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),