enh kubernetes filtering (#1200)

This commit is contained in:
Colin Gagnaire 2018-10-29 11:16:30 +01:00 committed by GitHub
parent 1fd84b2802
commit 93a41ca33e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 393 additions and 222 deletions

View File

@ -148,6 +148,20 @@ sub check_options {
$self->{metrics}->{$1} = $2 if (defined($self->{metrics}->{$1}));
}
$self->{labels} = {};
foreach my $label (('container', 'pod')) {
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;
$self->change_macros();
}
@ -167,51 +181,47 @@ sub manage_selection {
$self->{containers} = {};
my $extra_filter = '';
foreach my $filter (@{$self->{option_results}->{extra_filter}}) {
$extra_filter .= ',' . $filter;
}
my $results = $options{custom}->query(queries => [ 'label_replace({__name__=~"' . $self->{metrics}->{ready} . '",' .
$self->{option_results}->{container} . ',' .
$self->{option_results}->{pod} .
$extra_filter . '}, "__name__", "ready", "", "")',
$self->{extra_filter} . '}, "__name__", "ready", "", "")',
'label_replace({__name__=~"' . $self->{metrics}->{running} . '",' .
$self->{option_results}->{container} . ',' .
$self->{option_results}->{pod} .
$extra_filter . '}, "__name__", "running", "", "")',
$self->{extra_filter} . '}, "__name__", "running", "", "")',
'label_replace({__name__=~"' . $self->{metrics}->{terminated} . '",' .
$self->{option_results}->{container} . ',' .
$self->{option_results}->{pod} .
$extra_filter . '}, "__name__", "terminated", "", "")',
$self->{extra_filter} . '}, "__name__", "terminated", "", "")',
'label_replace({__name__=~"' . $self->{metrics}->{terminated_reason} . '",' .
$self->{option_results}->{container} . ',' .
$self->{option_results}->{pod} .
$extra_filter . '}, "__name__", "terminated_reason", "", "")',
$self->{extra_filter} . '}, "__name__", "terminated_reason", "", "")',
'label_replace({__name__=~"' . $self->{metrics}->{waiting} . '",' .
$self->{option_results}->{container} . ',' .
$self->{option_results}->{pod} .
$extra_filter . '}, "__name__", "waiting", "", "")',
$self->{extra_filter} . '}, "__name__", "waiting", "", "")',
'label_replace({__name__=~"' . $self->{metrics}->{waiting_reason} . '",' .
$self->{option_results}->{container} . ',' .
$self->{option_results}->{pod} .
$extra_filter . '}, "__name__", "waiting_reason", "", "")',
$self->{extra_filter} . '}, "__name__", "waiting_reason", "", "")',
'label_replace({__name__=~"' . $self->{metrics}->{restarts} . '",' .
$self->{option_results}->{container} . ',' .
$self->{option_results}->{pod} .
$extra_filter . '}, "__name__", "restarts", "", "")' ]);
$self->{extra_filter} . '}, "__name__", "restarts", "", "")' ]);
foreach my $metric (@{$results}) {
$self->{containers}->{$metric->{metric}->{pod} . "-" . $metric->{metric}->{container}}->{container} = $metric->{metric}->{container};
$self->{containers}->{$metric->{metric}->{pod} . "-" . $metric->{metric}->{container}}->{pod} = $metric->{metric}->{pod};
$self->{containers}->{$metric->{metric}->{pod} . "-" . $metric->{metric}->{container}}->{perf} = $metric->{metric}->{pod} . "_" . $metric->{metric}->{container};
$self->{containers}->{$metric->{metric}->{pod} . "-" . $metric->{metric}->{container}}->{restarts} = ${$metric->{value}}[1] if ($metric->{metric}->{__name__} =~ /restarts/);
$self->{containers}->{$metric->{metric}->{pod} . "-" . $metric->{metric}->{container}}->{state} = ${$metric->{value}}[1] if ($metric->{metric}->{__name__} =~ /ready/);
$self->{containers}->{$metric->{metric}->{pod} . "-" . $metric->{metric}->{container}}->{status} = $metric->{metric}->{__name__} if ($metric->{metric}->{__name__} =~ /running|terminated|waiting/ && ${$metric->{value}}[1] == 1);
$self->{containers}->{$metric->{metric}->{pod} . "-" . $metric->{metric}->{container}}->{reason} = "";
$self->{containers}->{$metric->{metric}->{pod} . "-" . $metric->{metric}->{container}}->{reason} = $metric->{metric}->{reason} if ($metric->{metric}->{__name__} =~ /reason/ && ${$metric->{value}}[1] == 1);
foreach my $result (@{$results}) {
next if (!defined($result->{metric}->{$self->{labels}->{pod}}) || !defined($result->{metric}->{$self->{labels}->{container}}));
$self->{containers}->{$result->{metric}->{$self->{labels}->{pod}} . "_" . $result->{metric}->{$self->{labels}->{container}}}->{container} = $result->{metric}->{$self->{labels}->{container}};
$self->{containers}->{$result->{metric}->{$self->{labels}->{pod}} . "_" . $result->{metric}->{$self->{labels}->{container}}}->{pod} = $result->{metric}->{$self->{labels}->{pod}};
$self->{containers}->{$result->{metric}->{$self->{labels}->{pod}} . "_" . $result->{metric}->{$self->{labels}->{container}}}->{perf} = $result->{metric}->{$self->{labels}->{pod}} . "_" . $result->{metric}->{$self->{labels}->{container}};
$self->{containers}->{$result->{metric}->{$self->{labels}->{pod}} . "_" . $result->{metric}->{$self->{labels}->{container}}}->{restarts} = ${$result->{value}}[1] if ($result->{metric}->{__name__} =~ /restarts/);
$self->{containers}->{$result->{metric}->{$self->{labels}->{pod}} . "_" . $result->{metric}->{$self->{labels}->{container}}}->{state} = ${$result->{value}}[1] if ($result->{metric}->{__name__} =~ /ready/);
$self->{containers}->{$result->{metric}->{$self->{labels}->{pod}} . "_" . $result->{metric}->{$self->{labels}->{container}}}->{status} = $result->{metric}->{__name__} if ($result->{metric}->{__name__} =~ /running|terminated|waiting/ && ${$result->{value}}[1] == 1);
$self->{containers}->{$result->{metric}->{$self->{labels}->{pod}} . "_" . $result->{metric}->{$self->{labels}->{container}}}->{reason} = "";
$self->{containers}->{$result->{metric}->{$self->{labels}->{pod}} . "_" . $result->{metric}->{$self->{labels}->{container}}}->{reason} = $result->{metric}->{reason} if ($result->{metric}->{__name__} =~ /reason/ && ${$result->{value}}[1] == 1);
}
if (scalar(keys %{$self->{containers}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No containers found.");
$self->{output}->option_exit();

View File

@ -78,7 +78,7 @@ sub custom_status_threshold {
sub custom_status_output {
my ($self, %options) = @_;
return sprintf("nodes desired : %s, current : %s, available : %s, unavailable : %s, up-to-date : %s, ready : %s, misscheduled : %s",
return sprintf("Nodes Desired : %s, Current : %s, Available : %s, Unavailable : %s, Up-to-date : %s, Ready : %s, Misscheduled : %s",
$self->{result_values}->{desired},
$self->{result_values}->{current},
$self->{result_values}->{available},
@ -107,7 +107,8 @@ sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'daemonsets', type => 1, cb_prefix_output => 'prefix_daemonset_output', message_multiple => 'All daemonsets status are ok', skipped_code => { -11 => 1 } },
{ name => 'daemonsets', type => 1, cb_prefix_output => 'prefix_daemonset_output',
message_multiple => 'All daemonsets status are ok', skipped_code => { -11 => 1 } },
];
$self->{maps_counters}->{daemonsets} = [
@ -138,7 +139,7 @@ sub new {
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"daemonset:s" => { name => 'daemonset', default => '.*' },
"daemonset:s" => { name => 'daemonset', default => 'daemonset=~".*"' },
"warning-status:s" => { name => 'warning_status', default => '%{up_to_date} < %{desired}' },
"critical-status:s" => { name => 'critical_status', default => '%{available} < %{desired}' },
"extra-filter:s@" => { name => 'extra_filter' },
@ -166,6 +167,20 @@ sub check_options {
$self->{metrics}->{$1} = $2 if (defined($self->{metrics}->{$1}));
}
$self->{labels} = {};
foreach my $label (('daemonset')) {
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;
$self->change_macros();
}
@ -185,36 +200,31 @@ sub manage_selection {
$self->{daemonsets} = {};
my $extra_filter = '';
foreach my $filter (@{$self->{option_results}->{extra_filter}}) {
$extra_filter .= ',' . $filter;
}
my $results = $options{custom}->query(queries => [ 'label_replace({__name__=~"' . $self->{metrics}->{desired} . '",' .
$self->{option_results}->{daemonset} .
$self->{extra_filter} . '}, "__name__", "desired", "", "")',
'label_replace({__name__=~"' . $self->{metrics}->{current} . '",' .
$self->{option_results}->{daemonset} .
$self->{extra_filter} . '}, "__name__", "current", "", "")',
'label_replace({__name__=~"' . $self->{metrics}->{available} . '",' .
$self->{option_results}->{daemonset} .
$self->{extra_filter} . '}, "__name__", "available", "", "")',
'label_replace({__name__=~"' . $self->{metrics}->{unavailable} . '",' .
$self->{option_results}->{daemonset} .
$self->{extra_filter} . '}, "__name__", "unavailable", "", "")',
'label_replace({__name__=~"' . $self->{metrics}->{up_to_date} . '",' .
$self->{option_results}->{daemonset} .
$self->{extra_filter} . '}, "__name__", "up_to_date", "", "")',
'label_replace({__name__=~"' . $self->{metrics}->{ready} . '",' .
$self->{option_results}->{daemonset} .
$self->{extra_filter} . '}, "__name__", "ready", "", "")',
'label_replace({__name__=~"' . $self->{metrics}->{misscheduled} . '",' .
$self->{option_results}->{daemonset} .
$self->{extra_filter} . '}, "__name__", "misscheduled", "", "")' ]);
my $results = $options{custom}->query(queries => [ 'label_replace({__name__=~"' . $self->{metrics}->{desired} . '",
daemonset=~"' . $self->{option_results}->{daemonset} .
'"' . $extra_filter . '}, "__name__", "desired", "", "")',
'label_replace({__name__=~"' . $self->{metrics}->{current} . '",
daemonset=~"' . $self->{option_results}->{daemonset} .
'"' . $extra_filter . '}, "__name__", "current", "", "")',
'label_replace({__name__=~"' . $self->{metrics}->{available} . '",
daemonset=~"' . $self->{option_results}->{daemonset} .
'"' . $extra_filter . '}, "__name__", "available", "", "")',
'label_replace({__name__=~"' . $self->{metrics}->{unavailable} . '",
daemonset=~"' . $self->{option_results}->{daemonset} .
'"' . $extra_filter . '}, "__name__", "unavailable", "", "")',
'label_replace({__name__=~"' . $self->{metrics}->{up_to_date} . '",
daemonset=~"' . $self->{option_results}->{daemonset} .
'"' . $extra_filter . '}, "__name__", "up_to_date", "", "")',
'label_replace({__name__=~"' . $self->{metrics}->{ready} . '",
daemonset=~"' . $self->{option_results}->{daemonset} .
'"' . $extra_filter . '}, "__name__", "ready", "", "")',
'label_replace({__name__=~"' . $self->{metrics}->{misscheduled} . '",
daemonset=~"' . $self->{option_results}->{daemonset} .
'"' . $extra_filter . '}, "__name__", "misscheduled", "", "")' ]);
foreach my $metric (@{$results}) {
$self->{daemonsets}->{$metric->{metric}->{daemonset}}->{display} = $metric->{metric}->{daemonset};
$self->{daemonsets}->{$metric->{metric}->{daemonset}}->{$metric->{metric}->{__name__}} = ${$metric->{value}}[1];
foreach my $result (@{$results}) {
$self->{daemonsets}->{$result->{metric}->{$self->{labels}->{daemonset}}}->{display} = $result->{metric}->{$self->{labels}->{daemonset}};
$self->{daemonsets}->{$result->{metric}->{$self->{labels}->{daemonset}}}->{$result->{metric}->{__name__}} = ${$result->{value}}[1];
}
if (scalar(keys %{$self->{daemonsets}}) <= 0) {
@ -235,7 +245,7 @@ Check daemonset status.
=item B<--daemonset>
Filter on a specific daemonset (Must be a regexp, Default: '.*')
Filter on a specific daemonset (Must be a PromQL filter, Default: 'daemonset=~".*"')
=item B<--warning-status>

View File

@ -74,7 +74,7 @@ sub custom_status_threshold {
sub custom_status_output {
my ($self, %options) = @_;
return sprintf("replicas desired : %s, current : %s, available : %s, unavailable : %s, up-to-date : %s",
return sprintf("Replicas Desired : %s, Current : %s, Available : %s, Unavailable : %s, Up-to-date : %s",
$self->{result_values}->{desired},
$self->{result_values}->{current},
$self->{result_values}->{available},
@ -99,7 +99,8 @@ sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'deployments', type => 1, cb_prefix_output => 'prefix_deployment_output', message_multiple => 'All deployments status are ok', skipped_code => { -11 => 1 } },
{ name => 'deployments', type => 1, cb_prefix_output => 'prefix_deployment_output',
message_multiple => 'All deployments status are ok', skipped_code => { -11 => 1 } },
];
$self->{maps_counters}->{deployments} = [
@ -129,7 +130,7 @@ sub new {
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"deployment:s" => { name => 'deployment', default => '.*' },
"deployment:s" => { name => 'deployment', default => 'deployment=~".*"' },
"warning-status:s" => { name => 'warning_status', default => '%{up_to_date} < %{desired}' },
"critical-status:s" => { name => 'critical_status', default => '%{available} < %{desired}' },
"extra-filter:s@" => { name => 'extra_filter' },
@ -155,6 +156,20 @@ sub check_options {
$self->{metrics}->{$1} = $2 if (defined($self->{metrics}->{$1}));
}
$self->{labels} = {};
foreach my $label (('deployment')) {
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;
$self->change_macros();
}
@ -174,30 +189,25 @@ sub manage_selection {
$self->{deployments} = {};
my $extra_filter = '';
foreach my $filter (@{$self->{option_results}->{extra_filter}}) {
$extra_filter .= ',' . $filter;
}
my $results = $options{custom}->query(queries => [ 'label_replace({__name__=~"' . $self->{metrics}->{desired} . '",' .
$self->{option_results}->{deployment} .
$self->{extra_filter} . '}, "__name__", "desired", "", "")',
'label_replace({__name__=~"' . $self->{metrics}->{current} . '",' .
$self->{option_results}->{deployment} .
$self->{extra_filter} . '}, "__name__", "current", "", "")',
'label_replace({__name__=~"' . $self->{metrics}->{available} . '",' .
$self->{option_results}->{deployment} .
$self->{extra_filter} . '}, "__name__", "available", "", "")',
'label_replace({__name__=~"' . $self->{metrics}->{unavailable} . '",' .
$self->{option_results}->{deployment} .
$self->{extra_filter} . '}, "__name__", "unavailable", "", "")',
'label_replace({__name__=~"' . $self->{metrics}->{up_to_date} . '",' .
$self->{option_results}->{deployment} .
$self->{extra_filter} . '}, "__name__", "up_to_date", "", "")' ]);
my $results = $options{custom}->query(queries => [ 'label_replace({__name__=~"' . $self->{metrics}->{desired} . '",
deployment=~"' . $self->{option_results}->{deployment} .
'"' . $extra_filter . '}, "__name__", "desired", "", "")',
'label_replace({__name__=~"' . $self->{metrics}->{current} . '",
deployment=~"' . $self->{option_results}->{deployment} .
'"' . $extra_filter . '}, "__name__", "current", "", "")',
'label_replace({__name__=~"' . $self->{metrics}->{available} . '",
deployment=~"' . $self->{option_results}->{deployment} .
'"' . $extra_filter . '}, "__name__", "available", "", "")',
'label_replace({__name__=~"' . $self->{metrics}->{unavailable} . '",
deployment=~"' . $self->{option_results}->{deployment} .
'"' . $extra_filter . '}, "__name__", "unavailable", "", "")',
'label_replace({__name__=~"' . $self->{metrics}->{up_to_date} . '",
deployment=~"' . $self->{option_results}->{deployment} .
'"' . $extra_filter . '}, "__name__", "up_to_date", "", "")' ]);
foreach my $metric (@{$results}) {
$self->{deployments}->{$metric->{metric}->{deployment}}->{display} = $metric->{metric}->{deployment};
$self->{deployments}->{$metric->{metric}->{deployment}}->{$metric->{metric}->{__name__}} = ${$metric->{value}}[1];
foreach my $result (@{$results}) {
$self->{deployments}->{$result->{metric}->{$self->{labels}->{deployment}}}->{display} = $result->{metric}->{$self->{labels}->{deployment}};
$self->{deployments}->{$result->{metric}->{$self->{labels}->{deployment}}}->{$result->{metric}->{__name__}} = ${$result->{value}}[1];
}
if (scalar(keys %{$self->{deployments}}) <= 0) {
@ -218,7 +228,7 @@ Check deployment status.
=item B<--deployment>
Filter on a specific deployment (Must be a regexp, Default: '.*')
Filter on a specific deployment (Must be a PromQL filter, Default: 'deployment=~".*"')
=item B<--warning-status>

View File

@ -33,7 +33,10 @@ sub new {
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"filter-name:s" => { name => 'filter_name' },
"container:s" => { name => 'container', default => 'container=~".*"' },
"pod:s" => { name => 'pod', default => 'pod=~".*"' },
"namespace:s" => { name => 'namespace', default => 'namespace=~".*"' },
"image:s" => { name => 'image', default => 'image=~".*"' },
"extra-filter:s@" => { name => 'extra_filter' },
"metric-overload:s@" => { name => 'metric_overload' },
});
@ -52,17 +55,30 @@ sub check_options {
next if ($metric !~ /(.*),(.*)/);
$self->{metrics}->{$1} = $2 if (defined($self->{metrics}->{$1}));
}
$self->{labels} = {};
foreach my $label (('container', 'pod', 'namespace', 'image')) {
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 {
my ($self, %options) = @_;
my $extra_filter = '';
foreach my $filter (@{$self->{option_results}->{extra_filter}}) {
$extra_filter .= ',' . $filter;
}
$self->{containers} = $options{custom}->query(queries => [ '{__name__=~"' . $self->{metrics}->{info} . '"' . $extra_filter . '}' ]);
$self->{containers} = $options{custom}->query(queries => [ '{__name__=~"' . $self->{metrics}->{info} . '",' .
$self->{option_results}->{container} . ',' .
$self->{option_results}->{pod} . ',' .
$self->{option_results}->{namespace} .
$self->{extra_filter} . '}' ]);
}
sub run {
@ -70,13 +86,11 @@ sub run {
$self->manage_selection(%options);
foreach my $container (@{$self->{containers}}) {
next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne ''
&& $container->{metric}->{container} !~ /$self->{option_results}->{filter_name}/);
$self->{output}->output_add(long_msg => sprintf("[container = %s][container_id = %s][pod = %s][image = %s]",
$container->{metric}->{container}, $container->{metric}->{container_id}, $container->{metric}->{pod},
$container->{metric}->{image}));
$self->{output}->output_add(long_msg => sprintf("[container = %s][pod = %s][namespace = %s][image = %s]",
$container->{metric}->{$self->{labels}->{container}}, $container->{metric}->{$self->{labels}->{pod}},
$container->{metric}->{$self->{labels}->{namespace}}, $container->{metric}->{$self->{labels}->{image}}));
}
$self->{output}->output_add(severity => 'OK',
short_msg => 'List containers:');
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
@ -86,7 +100,7 @@ sub run {
sub disco_format {
my ($self, %options) = @_;
$self->{output}->add_disco_format(elements => ['container', 'container_id', 'pod', 'image']);
$self->{output}->add_disco_format(elements => ['container', 'pod', 'namespace', 'image']);
}
sub disco_show {
@ -95,10 +109,10 @@ sub disco_show {
$self->manage_selection(%options);
foreach my $container (@{$self->{containers}}) {
$self->{output}->add_disco_entry(
container => $container->{metric}->{container},
container_id => $container->{metric}->{container_id},
pod => $container->{metric}->{pod},
image => $container->{metric}->{image},
container => $container->{metric}->{$self->{labels}->{container}},
pod => $container->{metric}->{$self->{labels}->{pod}},
namespace => $container->{metric}->{$self->{labels}->{namespace}},
image => $container->{metric}->{$self->{labels}->{image}},
);
}
}
@ -113,9 +127,21 @@ List containers.
=over 8
=item B<--filter-name>
=item B<--container>
Filter container name (Can be a regexp).
Filter on a specific container (Must be a PromQL filter, Default: 'container_name=~".*"')
=item B<--pod>
Filter on a specific pod (Must be a PromQL filter, Default: 'pod_name=~".*"')
=item B<--namespace>
Filter on a specific namespace (Must be a PromQL filter, Default: 'namespace=~".*"')
=item B<--image>
Filter on a specific image (Must be a PromQL filter, Default: 'image=~".*"')
=item B<--extra-filter>
@ -125,7 +151,7 @@ Example : --extra-filter='name=~".*pretty.*"'
=item B<--metric-overload>
Overload default metrics name (Can be multiple, metric can be 'labels')
Overload default metrics name (Can be multiple, metric can be 'info')
Example : --metric-overload='metric,^my_metric_name$'

View File

@ -33,7 +33,8 @@ sub new {
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"filter-name:s" => { name => 'filter_name' },
"daemonset:s" => { name => 'daemonset', default => 'daemonset=~".*"' },
"namespace:s" => { name => 'namespace', default => 'namespace=~".*"' },
"extra-filter:s@" => { name => 'extra_filter' },
"metric-overload:s@" => { name => 'metric_overload' },
});
@ -52,17 +53,29 @@ sub check_options {
next if ($metric !~ /(.*),(.*)/);
$self->{metrics}->{$1} = $2 if (defined($self->{metrics}->{$1}));
}
$self->{labels} = {};
foreach my $label (('daemonset', 'namespace')) {
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 {
my ($self, %options) = @_;
my $extra_filter = '';
foreach my $filter (@{$self->{option_results}->{extra_filter}}) {
$extra_filter .= ',' . $filter;
}
$self->{daemonsets} = $options{custom}->query(queries => [ '{__name__=~"' . $self->{metrics}->{created} . '"' . $extra_filter . '}' ]);
$self->{daemonsets} = $options{custom}->query(queries => [ '{__name__=~"' . $self->{metrics}->{created} . '",' .
$self->{option_results}->{daemonset} . ',' .
$self->{option_results}->{namespace} .
$self->{extra_filter} . '}' ]);
}
sub run {
@ -70,10 +83,8 @@ sub run {
$self->manage_selection(%options);
foreach my $daemonset (@{$self->{daemonsets}}) {
next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne ''
&& $daemonset->{metric}->{daemonset} !~ /$self->{option_results}->{filter_name}/);
$self->{output}->output_add(long_msg => sprintf("[daemonset = %s][namespace = %s]",
$daemonset->{metric}->{daemonset}, $daemonset->{metric}->{namespace}));
$daemonset->{metric}->{$self->{labels}->{daemonset}}, $daemonset->{metric}->{$self->{labels}->{namespace}}));
}
$self->{output}->output_add(severity => 'OK',
@ -94,8 +105,8 @@ sub disco_show {
$self->manage_selection(%options);
foreach my $daemonset (@{$self->{daemonsets}}) {
$self->{output}->add_disco_entry(
daemonset => $daemonset->{metric}->{daemonset},
namespace => $daemonset->{metric}->{namespace},
daemonset => $daemonset->{metric}->{$self->{labels}->{daemonset}},
namespace => $daemonset->{metric}->{$self->{labels}->{namespace}},
);
}
}
@ -110,9 +121,13 @@ List daemonsets.
=over 8
=item B<--filter-name>
=item B<--daemonset>
Filter daemonset name (Can be a regexp).
Filter on a specific daemonset (Must be a PromQL filter, Default: 'daemonset=~".*"')
=item B<--namespace>
Filter on a specific namespace (Must be a PromQL filter, Default: 'namespace=~".*"')
=item B<--extra-filter>
@ -122,7 +137,7 @@ Example : --extra-filter='name=~".*pretty.*"'
=item B<--metric-overload>
Overload default metrics name (Can be multiple, metric can be 'labels')
Overload default metrics name (Can be multiple, metric can be 'created')
Example : --metric-overload='metric,^my_metric_name$'

View File

@ -33,7 +33,7 @@ sub new {
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"filter-name:s" => { name => 'filter_name' },
"deployment:s" => { name => 'deployment', default => 'deployment=~".*"' },
"extra-filter:s@" => { name => 'extra_filter' },
"metric-overload:s@" => { name => 'metric_overload' },
});
@ -52,17 +52,28 @@ sub check_options {
next if ($metric !~ /(.*),(.*)/);
$self->{metrics}->{$1} = $2 if (defined($self->{metrics}->{$1}));
}
$self->{labels} = {};
foreach my $label (('deployment')) {
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 {
my ($self, %options) = @_;
my $extra_filter = '';
foreach my $filter (@{$self->{option_results}->{extra_filter}}) {
$extra_filter .= ',' . $filter;
}
$self->{deployments} = $options{custom}->query(queries => [ '{__name__=~"' . $self->{metrics}->{labels} . '"' . $extra_filter . '}' ]);
$self->{deployments} = $options{custom}->query(queries => [ '{__name__=~"' . $self->{metrics}->{labels} . '",' .
$self->{option_results}->{deployment} .
$self->{extra_filter} . '}' ]);
}
sub run {
@ -70,9 +81,8 @@ sub run {
$self->manage_selection(%options);
foreach my $deployment (@{$self->{deployments}}) {
next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne ''
&& $deployment->{metric}->{deployment} !~ /$self->{option_results}->{filter_name}/);
$self->{output}->output_add(long_msg => sprintf("[deployment = %s]", $deployment->{metric}->{deployment}));
$self->{output}->output_add(long_msg => sprintf("[deployment = %s]",
$deployment->{metric}->{$self->{labels}->{deployment}}));
}
$self->{output}->output_add(severity => 'OK',
@ -93,7 +103,7 @@ sub disco_show {
$self->manage_selection(%options);
foreach my $deployment (@{$self->{deployments}}) {
$self->{output}->add_disco_entry(
deployment => $deployment->{metric}->{deployment},
deployment => $deployment->{metric}->{$self->{labels}->{deployment}},
);
}
}
@ -108,9 +118,9 @@ List deployments.
=over 8
=item B<--filter-name>
=item B<--deployment>
Filter deployment name (Can be a regexp).
Filter on a specific deployment (Must be a PromQL filter, Default: 'deployment=~".*"')
=item B<--extra-filter>

View File

@ -33,7 +33,7 @@ sub new {
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"filter-name:s" => { name => 'filter_name' },
"namespace:s" => { name => 'namespace', default => 'namespace=~".*"' },
"extra-filter:s@" => { name => 'extra_filter' },
"metric-overload:s@" => { name => 'metric_overload' },
});
@ -52,17 +52,28 @@ sub check_options {
next if ($metric !~ /(.*),(.*)/);
$self->{metrics}->{$1} = $2 if (defined($self->{metrics}->{$1}));
}
$self->{labels} = {};
foreach my $label (('namespace')) {
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 {
my ($self, %options) = @_;
my $extra_filter = '';
foreach my $filter (@{$self->{option_results}->{extra_filter}}) {
$extra_filter .= ',' . $filter;
}
$self->{namespaces} = $options{custom}->query(queries => [ '{__name__=~"' . $self->{metrics}->{labels} . '"' . $extra_filter . '}' ]);
$self->{namespaces} = $options{custom}->query(queries => [ '{__name__=~"' . $self->{metrics}->{labels} . '",' .
$self->{option_results}->{namespace} .
$self->{extra_filter} . '}' ]);
}
sub run {
@ -70,9 +81,8 @@ sub run {
$self->manage_selection(%options);
foreach my $namespace (@{$self->{namespaces}}) {
next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne ''
&& $namespace->{metric}->{namespace} !~ /$self->{option_results}->{filter_name}/);
$self->{output}->output_add(long_msg => sprintf("[namespace = %s]", $namespace->{metric}->{namespace}));
$self->{output}->output_add(long_msg => sprintf("[namespace = %s]",
$namespace->{metric}->{$self->{labels}->{namespace}}));
}
$self->{output}->output_add(severity => 'OK',
@ -93,7 +103,7 @@ sub disco_show {
$self->manage_selection(%options);
foreach my $namespace (@{$self->{namespaces}}) {
$self->{output}->add_disco_entry(
namespace => $namespace->{metric}->{namespace},
namespace => $namespace->{metric}->{$self->{labels}->{namespace}},
);
}
}
@ -108,9 +118,9 @@ List namespaces.
=over 8
=item B<--filter-name>
=item B<--namespace>
Filter namespace name (Can be a regexp).
Filter on a specific namespace (Must be a PromQL filter, Default: 'namespace=~".*"')
=item B<--extra-filter>
@ -120,7 +130,7 @@ Example : --extra-filter='name=~".*pretty.*"'
=item B<--metric-overload>
Overload default metrics name (Can be multiple, metric can be 'status')
Overload default metrics name (Can be multiple, metric can be 'labels')
Example : --metric-overload='metric,^my_metric_name$'

View File

@ -33,9 +33,14 @@ sub new {
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"filter-name:s" => { name => 'filter_name' },
"extra-filter:s@" => { name => 'extra_filter' },
"metric-overload:s@" => { name => 'metric_overload' },
"node:s" => { name => 'node', default => 'node=~".*"' },
"os-image:s" => { name => 'os_image', default => 'os_image=~".*"' },
"kubelet-version:s" => { name => 'kubelet_version', default => 'kubelet_version=~".*"' },
"kubeproxy-version:s" => { name => 'kubeproxy_version', default => 'kubeproxy_version=~".*"' },
"kernel-version:s" => { name => 'kernel_version', default => 'kernel_version=~".*"' },
"container-runtime-version:s" => { name => 'container_runtime_version', default => 'container_runtime_version=~".*"' },
"extra-filter:s@" => { name => 'extra_filter' },
"metric-overload:s@" => { name => 'metric_overload' },
});
return $self;
@ -52,17 +57,33 @@ sub check_options {
next if ($metric !~ /(.*),(.*)/);
$self->{metrics}->{$1} = $2 if (defined($self->{metrics}->{$1}));
}
$self->{labels} = {};
foreach my $label (('node', 'os_image', 'kubelet_version', 'kubeproxy_version', 'kernel_version', 'container_runtime_version')) {
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 {
my ($self, %options) = @_;
my $extra_filter = '';
foreach my $filter (@{$self->{option_results}->{extra_filter}}) {
$extra_filter .= ',' . $filter;
}
$self->{nodes} = $options{custom}->query(queries => [ '{__name__=~"' . $self->{metrics}->{info} . '"' . $extra_filter . '}' ]);
$self->{nodes} = $options{custom}->query(queries => [ '{__name__=~"' . $self->{metrics}->{info} . '",' .
$self->{option_results}->{node} . ',' .
$self->{option_results}->{os_image} . ',' .
$self->{option_results}->{kubelet_version} . ',' .
$self->{option_results}->{kubeproxy_version} . ',' .
$self->{option_results}->{kernel_version} . ',' .
$self->{option_results}->{container_runtime_version} .
$self->{extra_filter} . '}' ]);
}
sub run {
@ -70,12 +91,11 @@ sub run {
$self->manage_selection(%options);
foreach my $node (@{$self->{nodes}}) {
next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne ''
&& $node->{metric}->{node} !~ /$self->{option_results}->{filter_name}/);
$self->{output}->output_add(long_msg => sprintf("[node = %s][os_image = %s][kubelet_version = %s][kubeproxy_version = %s]" .
"[kernel_version = %s][container_runtime_version = %s]",
$node->{metric}->{node}, $node->{metric}->{os_image}, $node->{metric}->{kubelet_version},
$node->{metric}->{kubeproxy_version}, $node->{metric}->{kernel_version}, $node->{metric}->{container_runtime_version}));
$node->{metric}->{$self->{labels}->{node}}, $node->{metric}->{$self->{labels}->{os_image}},
$node->{metric}->{$self->{labels}->{kubelet_version}}, $node->{metric}->{$self->{labels}->{kubeproxy_version}},
$node->{metric}->{$self->{labels}->{kernel_version}}, $node->{metric}->{$self->{labels}->{container_runtime_version}}));
}
$self->{output}->output_add(severity => 'OK',
@ -97,12 +117,12 @@ sub disco_show {
$self->manage_selection(%options);
foreach my $node (@{$self->{nodes}}) {
$self->{output}->add_disco_entry(
node => $node->{metric}->{node},
os_image => $node->{metric}->{os_image},
kubelet_version => $node->{metric}->{kubelet_version},
kubeproxy_version => $node->{metric}->{kubeproxy_version},
kernel_version => $node->{metric}->{kernel_version},
container_runtime_version => $node->{metric}->{container_runtime_version},
node => $node->{metric}->{$self->{labels}->{node}},
os_image => $node->{metric}->{$self->{labels}->{os_image}},
kubelet_version => $node->{metric}->{$self->{labels}->{kubelet_version}},
kubeproxy_version => $node->{metric}->{$self->{labels}->{kubeproxy_version}},
kernel_version => $node->{metric}->{$self->{labels}->{kernel_version}},
container_runtime_version => $node->{metric}->{$self->{labels}->{container_runtime_version}},
);
}
}
@ -117,9 +137,29 @@ List nodes.
=over 8
=item B<--filter-name>
=item B<--node>
Filter node name (Can be a regexp).
Filter on a specific node (Must be a PromQL filter, Default: 'node=~".*"')
=item B<--os-image>
Filter on a specific os image (Must be a PromQL filter, Default: 'os_image=~".*"')
=item B<--kubelet-version>
Filter on a specific kubelet version (Must be a PromQL filter, Default: 'kubelet_version=~".*"')
=item B<--kubeproxy-version>
Filter on a specific kubeproxy version (Must be a PromQL filter, Default: 'kubeproxy_version=~".*"')
=item B<--kernel-version>
Filter on a specific kernel version (Must be a PromQL filter, Default: 'kernel_version=~".*"')
=item B<--container-runtime-version>
Filter on a specific container runtime version (Must be a PromQL filter, Default: 'container_runtime_version=~".*"')
=item B<--extra-filter>
@ -129,7 +169,7 @@ Example : --extra-filter='name=~".*pretty.*"'
=item B<--metric-overload>
Overload default metrics name (Can be multiple, metric can be 'labels')
Overload default metrics name (Can be multiple, metric can be 'info')
Example : --metric-overload='metric,^my_metric_name$'

View File

@ -33,7 +33,8 @@ sub new {
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"filter-name:s" => { name => 'filter_name' },
"service:s" => { name => 'service', default => 'service=~".*"' },
"cluster-ip:s" => { name => 'cluster_ip', default => 'cluster_ip=~".*"' },
"extra-filter:s@" => { name => 'extra_filter' },
"metric-overload:s@" => { name => 'metric_overload' },
});
@ -52,17 +53,29 @@ sub check_options {
next if ($metric !~ /(.*),(.*)/);
$self->{metrics}->{$1} = $2 if (defined($self->{metrics}->{$1}));
}
$self->{labels} = {};
foreach my $label (('service', 'cluster_ip')) {
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 {
my ($self, %options) = @_;
my $extra_filter = '';
foreach my $filter (@{$self->{option_results}->{extra_filter}}) {
$extra_filter .= ',' . $filter;
}
$self->{services} = $options{custom}->query(queries => [ '{__name__=~"' . $self->{metrics}->{info} . '"' . $extra_filter . '}' ]);
$self->{services} = $options{custom}->query(queries => [ '{__name__=~"' . $self->{metrics}->{info} . '",' .
$self->{option_results}->{service} . ',' .
$self->{option_results}->{cluster_ip} .
$self->{extra_filter} . '}' ]);
}
sub run {
@ -70,10 +83,8 @@ sub run {
$self->manage_selection(%options);
foreach my $service (@{$self->{services}}) {
next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne ''
&& $service->{metric}->{service} !~ /$self->{option_results}->{filter_name}/);
$self->{output}->output_add(long_msg => sprintf("[service = %s][cluster_ip = %s]",
$service->{metric}->{service}, $service->{metric}->{cluster_ip}));
$service->{metric}->{$self->{labels}->{service}}, $service->{metric}->{$self->{labels}->{cluster_ip}}));
}
$self->{output}->output_add(severity => 'OK',
@ -94,8 +105,8 @@ sub disco_show {
$self->manage_selection(%options);
foreach my $service (@{$self->{services}}) {
$self->{output}->add_disco_entry(
service => $service->{metric}->{service},
cluster_ip => $service->{metric}->{cluster_ip},
service => $service->{metric}->{$self->{labels}->{service}},
cluster_ip => $service->{metric}->{$self->{labels}->{cluster_ip}},
);
}
}
@ -110,9 +121,13 @@ List services.
=over 8
=item B<--filter-name>
=item B<--service>
Filter service name (Can be a regexp).
Filter on a specific service (Must be a PromQL filter, Default: 'service=~".*"')
=item B<--cluster-ip>
Filter on a specific cluster ip (Must be a PromQL filter, Default: 'cluster_ip=~".*"')
=item B<--extra-filter>
@ -122,7 +137,7 @@ Example : --extra-filter='name=~".*pretty.*"'
=item B<--metric-overload>
Overload default metrics name (Can be multiple, metric can be 'labels')
Overload default metrics name (Can be multiple, metric can be 'info')
Example : --metric-overload='metric,^my_metric_name$'

View File

@ -132,7 +132,8 @@ sub new {
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"namespace:s" => { name => 'namespace', default => '.*' },
"namespace:s" => { name => 'namespace', default => 'namespace=~".*"' },
"phase:s" => { name => 'phase', default => 'phase=~".*"' },
"warning-status:s" => { name => 'warning_status' },
"critical-status:s" => { name => 'critical_status', default => '%{phase} !~ /Active/' },
"extra-filter:s@" => { name => 'extra_filter' },
@ -154,6 +155,20 @@ sub check_options {
$self->{metrics}->{$1} = $2 if (defined($self->{metrics}->{$1}));
}
$self->{labels} = {};
foreach my $label (('namespace', 'phase')) {
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;
$self->change_macros();
}
@ -174,20 +189,16 @@ sub manage_selection {
$self->{global} = { active => 0, terminating => 0 };
$self->{namespaces} = {};
my $extra_filter = '';
foreach my $filter (@{$self->{option_results}->{extra_filter}}) {
$extra_filter .= ',' . $filter;
my $results = $options{custom}->query(queries => [ '{__name__=~"' . $self->{metrics}->{status} . '",' .
$self->{option_results}->{namespace} .
$self->{extra_filter} . '}' ]);
foreach my $result (@{$results}) {
$self->{namespaces}->{$result->{metric}->{$self->{labels}->{namespace}}}->{display} = $result->{metric}->{$self->{labels}->{namespace}};
$self->{namespaces}->{$result->{metric}->{$self->{labels}->{namespace}}}->{$self->{labels}->{phase}} = $result->{metric}->{$self->{labels}->{phase}} if (${$result->{value}}[1] == 1);
$self->{global}->{lc($result->{metric}->{$self->{labels}->{phase}})}++ if (${$result->{value}}[1] == 1);
}
my $results = $options{custom}->query(queries => [ '{__name__=~"' . $self->{metrics}->{status} . '",namespace=~"' . $self->{option_results}->{namespace} .
'"' . $extra_filter . '}' ]);
foreach my $metric (@{$results}) {
$self->{namespaces}->{$metric->{metric}->{namespace}}->{display} = $metric->{metric}->{namespace};
$self->{namespaces}->{$metric->{metric}->{namespace}}->{phase} = $metric->{metric}->{phase} if (${$metric->{value}}[1] == 1);
$self->{global}->{lc($metric->{metric}->{phase})}++ if (${$metric->{value}}[1] == 1);
}
if (scalar(keys %{$self->{namespaces}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No namespaces found.");
$self->{output}->option_exit();
@ -206,7 +217,11 @@ Check namespace status phase.
=item B<--namespace>
Filter on a specific namespace (Must be a regexp, Default: '.*')
Filter on a specific namespace (Must be a PromQL filter, Default: 'namespace=~".*"')
=item B<--phase>
Filter on a specific phase (Must be a PromQL filter, Default: 'phase=~".*"')
=item B<--warning-status>

View File

@ -54,7 +54,7 @@ sub custom_status_threshold {
sub custom_status_output {
my ($self, %options) = @_;
return sprintf("status is '%s', new pods schedulable : %s",
return sprintf("Status is '%s', New Pods Schedulable : %s",
$self->{result_values}->{status},
$self->{result_values}->{schedulable});
}
@ -105,7 +105,7 @@ sub custom_usage_threshold {
sub custom_usage_output {
my ($self, %options) = @_;
my $msg = sprintf("Allocation Capacity : %s, Allocated : %s (%.2f%%)",
my $msg = sprintf("Pods Allocation Capacity : %s, Allocated : %s (%.2f%%)",
$self->{result_values}->{capacity}, $self->{result_values}->{allocated}, $self->{result_values}->{prct_allocated});
return $msg;
}
@ -165,7 +165,7 @@ sub new {
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"node:s" => { name => 'node', default => '.*' },
"node:s" => { name => 'node', default => 'node=~".*"' },
"warning-status:s" => { name => 'warning_status' },
"critical-status:s" => { name => 'critical_status', default => '%{status} !~ /Ready/ || %{schedulable} =~ /false/' },
"extra-filter:s@" => { name => 'extra_filter' },
@ -191,6 +191,20 @@ sub check_options {
$self->{metrics}->{$1} = $2 if (defined($self->{metrics}->{$1}));
}
$self->{labels} = {};
foreach my $label (('node')) {
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;
$self->change_macros();
}
@ -209,29 +223,25 @@ sub manage_selection {
my ($self, %options) = @_;
$self->{nodes} = {};
my $results = $options{custom}->query(queries => [ 'label_replace({__name__=~"' . $self->{metrics}->{status} . '",' .
$self->{option_results}->{node} . ',' .
'status="true"' .
$self->{extra_filter} . '}, "__name__", "status", "", "")',
'label_replace({__name__=~"' . $self->{metrics}->{unschedulable} . '",' .
$self->{option_results}->{node} .
$self->{extra_filter} . '}, "__name__", "unschedulable", "", "")',
'label_replace({__name__=~"' . $self->{metrics}->{capacity} . '",' .
$self->{option_results}->{node} .
$self->{extra_filter} . '}, "__name__", "capacity", "", "")',
'label_replace({__name__=~"' . $self->{metrics}->{allocatable} . '",' .
$self->{option_results}->{node} .
$self->{extra_filter} . '}, "__name__", "allocatable", "", "")' ]);
my $extra_filter = '';
foreach my $filter (@{$self->{option_results}->{extra_filter}}) {
$extra_filter .= ',' . $filter;
}
my $results = $options{custom}->query(queries => [ 'label_replace({__name__=~"' . $self->{metrics}->{status} . '",
node=~"' . $self->{option_results}->{node} . '",status="true"' .
$extra_filter . '}, "__name__", "status", "", "")',
'label_replace({__name__=~"' . $self->{metrics}->{unschedulable} . '",
node=~"' . $self->{option_results}->{node} .
'"' . $extra_filter . '}, "__name__", "unschedulable", "", "")',
'label_replace({__name__=~"' . $self->{metrics}->{capacity} . '",
node=~"' . $self->{option_results}->{node} .
'"' . $extra_filter . '}, "__name__", "capacity", "", "")',
'label_replace({__name__=~"' . $self->{metrics}->{allocatable} . '",
node=~"' . $self->{option_results}->{node} .
'"' . $extra_filter . '}, "__name__", "allocatable", "", "")' ]);
foreach my $metric (@{$results}) {
$self->{nodes}->{$metric->{metric}->{node}}->{display} = $metric->{metric}->{node};
$self->{nodes}->{$metric->{metric}->{node}}->{$metric->{metric}->{__name__}} = ${$metric->{value}}[1];
$self->{nodes}->{$metric->{metric}->{node}}->{$metric->{metric}->{__name__}} = $metric->{metric}->{condition} if ($metric->{metric}->{__name__} =~ /status/);
foreach my $result (@{$results}) {
$self->{nodes}->{$result->{metric}->{$self->{labels}->{node}}}->{display} = $result->{metric}->{$self->{labels}->{node}};
$self->{nodes}->{$result->{metric}->{$self->{labels}->{node}}}->{$result->{metric}->{__name__}} = ${$result->{value}}[1];
$self->{nodes}->{$result->{metric}->{$self->{labels}->{node}}}->{$result->{metric}->{__name__}} = $result->{metric}->{condition} if ($result->{metric}->{__name__} =~ /status/);
}
if (scalar(keys %{$self->{nodes}}) <= 0) {
@ -252,7 +262,7 @@ Check node status.
=item B<--node>
Filter on a specific node (Must be a regexp, Default: '.*')
Filter on a specific node (Must be a PromQL filter, Default: 'node=~".*"')
=item B<--warning-status>