enh(prom)add-namespace-in-prefix-output (#2504)

This commit is contained in:
Simon Bomm 2021-01-13 09:45:13 +01:00 committed by GitHub
parent bef7aed6f0
commit 225724fa18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 4 deletions

View File

@ -83,7 +83,7 @@ sub set_counters {
sub prefix_container_output {
my ($self, %options) = @_;
return "Container '" . $options{instance_value}->{container} . "' [pod: " . $options{instance_value}->{pod} . "] ";
return "Container '" . $options{instance_value}->{container} . "' [pod: " . $options{instance_value}->{pod} . ", namespace: " . $options{instance_value}->{namespace} . "] ";
}
sub new {
@ -186,6 +186,7 @@ sub manage_selection {
$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);
$self->{containers}->{$result->{metric}->{$self->{labels}->{pod}} . "_" . $result->{metric}->{$self->{labels}->{container}}}->{namespace} = $result->{metric}->{namespace};
}
if (scalar(keys %{$self->{containers}}) <= 0) {

View File

@ -126,7 +126,7 @@ sub set_counters {
sub prefix_daemonset_output {
my ($self, %options) = @_;
return "Daemonset '" . $options{instance_value}->{display} . "' ";
return "Daemonset '" . $options{instance_value}->{display} . " [namespace: ". $options{instance_value}->{namespace} . "]' ";
}
sub new {
@ -214,6 +214,7 @@ sub manage_selection {
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];
$self->{daemonsets}->{$result->{metric}->{$self->{labels}->{daemonset}}}->{namespace} = $result->{metric}->{namespace};
}
if (scalar(keys %{$self->{daemonsets}}) <= 0) {

View File

@ -109,7 +109,7 @@ sub set_counters {
sub prefix_deployment_output {
my ($self, %options) = @_;
return "Deployment '" . $options{instance_value}->{display} . "' ";
return "Deployment '" . $options{instance_value}->{display} . " [namespace: ". $options{instance_value}->{namespace} ."]' ";
}
sub new {
@ -189,6 +189,7 @@ sub manage_selection {
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];
$self->{deployments}->{$result->{metric}->{$self->{labels}->{deployment}}}->{namespace} = $result->{metric}->{namespace};
}
if (scalar(keys %{$self->{deployments}}) <= 0) {

View File

@ -34,7 +34,7 @@ sub custom_status_perfdata {
label => $key,
nlabel => $key,
value => $self->{result_values}->{$key},
instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef
instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{instance} : undef
);
}
}
@ -161,6 +161,7 @@ sub manage_selection {
my $prom_query = sprintf('label_replace(%s,"__name__","%s","","")', $self->{query_ranges}->{$label}, $label);
push @query_ranges, $prom_query;
}
my $queries_results = $options{custom}->query(queries => \@queries) if (scalar(@queries) > 0);
my $query_ranges_results = $options{custom}->query_range(queries => \@query_ranges, timeframe => $self->{prom_timeframe}, step => $self->{prom_step}) if (scalar(@query_ranges) > 0);