From 225724fa1803f6d985bdba121db251cd2f0b5962 Mon Sep 17 00:00:00 2001 From: Simon Bomm Date: Wed, 13 Jan 2021 09:45:13 +0100 Subject: [PATCH] enh(prom)add-namespace-in-prefix-output (#2504) --- cloud/prometheus/direct/kubernetes/mode/containerstatus.pm | 3 ++- cloud/prometheus/direct/kubernetes/mode/daemonsetstatus.pm | 3 ++- cloud/prometheus/direct/kubernetes/mode/deploymentstatus.pm | 3 ++- cloud/prometheus/restapi/mode/expression.pm | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/cloud/prometheus/direct/kubernetes/mode/containerstatus.pm b/cloud/prometheus/direct/kubernetes/mode/containerstatus.pm index 8c8ff8439..1ec8ddf5a 100644 --- a/cloud/prometheus/direct/kubernetes/mode/containerstatus.pm +++ b/cloud/prometheus/direct/kubernetes/mode/containerstatus.pm @@ -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) { diff --git a/cloud/prometheus/direct/kubernetes/mode/daemonsetstatus.pm b/cloud/prometheus/direct/kubernetes/mode/daemonsetstatus.pm index 74a5dc879..24814d9c6 100644 --- a/cloud/prometheus/direct/kubernetes/mode/daemonsetstatus.pm +++ b/cloud/prometheus/direct/kubernetes/mode/daemonsetstatus.pm @@ -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) { diff --git a/cloud/prometheus/direct/kubernetes/mode/deploymentstatus.pm b/cloud/prometheus/direct/kubernetes/mode/deploymentstatus.pm index 3b2eabec7..d5acde84c 100644 --- a/cloud/prometheus/direct/kubernetes/mode/deploymentstatus.pm +++ b/cloud/prometheus/direct/kubernetes/mode/deploymentstatus.pm @@ -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) { diff --git a/cloud/prometheus/restapi/mode/expression.pm b/cloud/prometheus/restapi/mode/expression.pm index afd740b01..ef6532a58 100644 --- a/cloud/prometheus/restapi/mode/expression.pm +++ b/cloud/prometheus/restapi/mode/expression.pm @@ -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);