How to correlate kube_pod_info and kube_pod_status_phase

2,616 views
Skip to first unread message

wangchao...@gmail.com

unread,
Dec 27, 2017, 12:58:41 AM12/27/17
to Prometheus Users
kube_pod_info and kube_pod_status_phase are two metrics provided by quay.io/coreos/kube-state-metrics:v1.1.0. Please refer to the following document, 

You know, kube_pod_info has the following labels:  
pod=<pod-name> 
namespace=<pod-namespace> 
host_ip=<host-ip> 
pod_ip=<pod-ip> 
node=<node-name>
created_by_kind=<created_by_kind>
created_by_name=<created_by_name>

And kube_pod_status_phase has the following labels,
pod=<pod-name> 
namespace=<pod-namespace> 
phase=<Pending|Running|Succeeded|Failed|Unknown>

What I want is to use one query statement to get each pod's info together with the phase, because I need to get them displayed in one grafana table instead of two separate tables. How can I achieve this? Thanks. 

Parag Somani

unread,
Dec 27, 2017, 3:35:34 AM12/27/17
to Prometheus Users
You can try with following job in config.yml, using which you can mention which pods to look for. This value will be available in TSDB of prometheus, which will be pulled later on by grafana as data source
- job_name: 'kubernetes-pods'
  scrape_interval
: 10s
  kubernetes_sd_configs
:
 
- role: pod
    namespaces
:
      names
: [ProjectA, ProjectB]
  relabel_configs
:
 
- source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
    action
: keep
    regex
: true
 
- source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path]
    action
: replace
    target_label
: __metrics_path__
    regex
: (.+)
 
- source_labels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port]
    action
: replace
    regex
: ([^:]+)(?::\d+)?;(\d+)
    replacement
: $1:$2
    target_label
: __address__
 
- action: labelmap
    regex
: __meta_kubernetes_pod_label_(.+)
 
- source_labels: [__meta_kubernetes_namespace]
    action
: replace
    target_label
: kubernetes_namespace
 
- source_labels: [__meta_kubernetes_pod_name]
    action
: replace
    target_label
: kubernetes_pod_name

Hope this helps, if i understood your question correctly

wangchao...@gmail.com

unread,
Dec 27, 2017, 4:45:28 AM12/27/17
to Prometheus Users
Thanks for the response, but I did not see any relationship between my question and your answer.  Thanks anyway. 

My question is how to get the labels (host_ip, pod_ip...) provided by kube_pod_info and the label (phase) provided by kube_pod_status_phase displayed in one grafana table.  Currently I get them displayed in two separately grafana table, but that isn't expected, what I want is to get them displayed in one table. 


在 2017年12月27日星期三 UTC+8下午4:35:34,Parag Somani写道:

wangchao...@gmail.com

unread,
Dec 27, 2017, 10:18:33 AM12/27/17
to Prometheus Users
I just got an expected answer from grafana community. This feature has just been supported by grafana, please refer to the following issue, 
https://github.com/grafana/grafana/pull/10050 

在 2017年12月27日星期三 UTC+8下午5:45:28,wangchao...@gmail.com写道:

Tom Wilkie

unread,
Dec 27, 2017, 12:40:29 PM12/27/17
to wangchao...@gmail.com, Prometheus Users
Hi there - you can do this with a single PromQL query too: 

kube_pod_info 
  * on (namespace, pod) group_left (phase) 
kube_pod_status_phase

--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.
To post to this group, send email to promethe...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/796eb6e4-a65c-4868-a9ff-98bd43ed7dce%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages