From 15e26aad672e7c4d4d2745c95a8fd92c6b6e17c4 Mon Sep 17 00:00:00 2001 From: Colin Gagnaire Date: Sat, 27 Oct 2018 12:48:36 +0200 Subject: [PATCH] enh kubernetes containerstatus mode (#1197) --- .../direct/kubernetes/mode/containerstatus.pm | 66 ++++++++++--------- 1 file changed, 35 insertions(+), 31 deletions(-) diff --git a/cloud/prometheus/direct/kubernetes/mode/containerstatus.pm b/cloud/prometheus/direct/kubernetes/mode/containerstatus.pm index 3344929e4..31e699f86 100644 --- a/cloud/prometheus/direct/kubernetes/mode/containerstatus.pm +++ b/cloud/prometheus/direct/kubernetes/mode/containerstatus.pm @@ -119,8 +119,8 @@ sub new { $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "container:s" => { name => 'container', default => '.*' }, - "pod:s" => { name => 'pod', default => '.*' }, + "container:s" => { name => 'container', default => 'container=~".*"' }, + "pod:s" => { name => 'pod', default => 'pod=~".*"' }, "warning-status:s" => { name => 'warning_status', default => '' }, "critical-status:s" => { name => 'critical_status', default => '%{status} !~ /running/ || %{state} !~ /ready/' }, "extra-filter:s@" => { name => 'extra_filter' }, @@ -172,34 +172,34 @@ sub manage_selection { $extra_filter .= ',' . $filter; } - my $results = $options{custom}->query(queries => [ 'label_replace({__name__=~"' . $self->{metrics}->{ready} . '", - container=~"' . $self->{option_results}->{container} . '", - pod=~"' . $self->{option_results}->{pod} . - '"' . $extra_filter . '}, "__name__", "ready", "", "")', - 'label_replace({__name__=~"' . $self->{metrics}->{running} . '", - container=~"' . $self->{option_results}->{container} . '", - pod=~"' . $self->{option_results}->{pod} . - '"' . $extra_filter . '}, "__name__", "running", "", "")', - 'label_replace({__name__=~"' . $self->{metrics}->{terminated} . '", - container=~"' . $self->{option_results}->{container} . '", - pod=~"' . $self->{option_results}->{pod} . - '"' . $extra_filter . '}, "__name__", "terminated", "", "")', - 'label_replace({__name__=~"' . $self->{metrics}->{terminated_reason} . '", - container=~"' . $self->{option_results}->{container} . '", - pod=~"' . $self->{option_results}->{pod} . - '"' . $extra_filter . '}, "__name__", "terminated_reason", "", "")', - 'label_replace({__name__=~"' . $self->{metrics}->{waiting} . '", - container=~"' . $self->{option_results}->{container} . '", - pod=~"' . $self->{option_results}->{pod} . - '"' . $extra_filter . '}, "__name__", "waiting", "", "")', - 'label_replace({__name__=~"' . $self->{metrics}->{waiting_reason} . '", - container=~"' . $self->{option_results}->{container} . '", - pod=~"' . $self->{option_results}->{pod} . - '"' . $extra_filter . '}, "__name__", "waiting_reason", "", "")', - 'label_replace({__name__=~"' . $self->{metrics}->{restarts} . '", - container=~"' . $self->{option_results}->{container} . '", - pod=~"' . $self->{option_results}->{pod} . - '"' . $extra_filter . '}, "__name__", "restarts", "", "")' ]); + my $results = $options{custom}->query(queries => [ 'label_replace({__name__=~"' . $self->{metrics}->{ready} . '",' . + $self->{option_results}->{container} . ',' . + $self->{option_results}->{pod} . + $extra_filter . '}, "__name__", "ready", "", "")', + 'label_replace({__name__=~"' . $self->{metrics}->{running} . '",' . + $self->{option_results}->{container} . ',' . + $self->{option_results}->{pod} . + $extra_filter . '}, "__name__", "running", "", "")', + 'label_replace({__name__=~"' . $self->{metrics}->{terminated} . '",' . + $self->{option_results}->{container} . ',' . + $self->{option_results}->{pod} . + $extra_filter . '}, "__name__", "terminated", "", "")', + 'label_replace({__name__=~"' . $self->{metrics}->{terminated_reason} . '",' . + $self->{option_results}->{container} . ',' . + $self->{option_results}->{pod} . + $extra_filter . '}, "__name__", "terminated_reason", "", "")', + 'label_replace({__name__=~"' . $self->{metrics}->{waiting} . '",' . + $self->{option_results}->{container} . ',' . + $self->{option_results}->{pod} . + $extra_filter . '}, "__name__", "waiting", "", "")', + 'label_replace({__name__=~"' . $self->{metrics}->{waiting_reason} . '",' . + $self->{option_results}->{container} . ',' . + $self->{option_results}->{pod} . + $extra_filter . '}, "__name__", "waiting_reason", "", "")', + 'label_replace({__name__=~"' . $self->{metrics}->{restarts} . '",' . + $self->{option_results}->{container} . ',' . + $self->{option_results}->{pod} . + $extra_filter . '}, "__name__", "restarts", "", "")' ]); foreach my $metric (@{$results}) { $self->{containers}->{$metric->{metric}->{pod} . "-" . $metric->{metric}->{container}}->{container} = $metric->{metric}->{container}; @@ -230,7 +230,11 @@ Check container status. =item B<--container> -Filter on a specific container (Must be a regexp, Default: '.*') +Filter on a specific container (Must be a PromQL filter, Default: 'container=~".*"') + +=item B<--pod> + +Filter on a specific pod (Must be a PromQL filter, Default: 'pod=~".*"') =item B<--warning-status>