Having issue while creating custom dashboard in Grafana( data-source is Prometheus)

7/31/2018

I have setup Prometheus and Grafana for monitoring my kubernetes cluster and everything works fine. Then I have created custom dashboard in Grafana for my application.The metrics available in Prometheus is as follows and i have added the same in grafana as metrics:


sum(irate(container_cpu_usage_seconds_total{namespace="test", pod_name="my-app-65c7d6576b-5pgjq", container_name!="POD"}[1m])) by (container_name)


The issue is, my application is running as pod in kubernetes,so when the pod is deleted or recreated, then the name of the pod will change and it will be different than the pod name specified in the above metrics "my-app-65c7d6576b-5pgjq". So the data for the above metrics will not work anymore. and I have to add new metrics again in Grafana. Please let me know How can I overcome this situation.

-- manu thankachan
grafana
kubernetes
prometheus

2 Answers

8/1/2018

Answer was provided by manu thankachan:

I have done it. Made some change in the query as follow:

sum(irate(container_cpu_usage_seconds_total{namespace="test", container_name="my-app", container_name!="POD"}[1m])) by (container_name)

-- VAS
Source: StackOverflow

5/13/2020

If pod is created directly(not a part of deployment) then only pod name is same as we mentioned.

If pod is part of Deployment the it will have unique string from replicaset and also ends with random 5 characters to maintain unique name.

So always try to use container_name label or if your Kubernetes version is > v1.16.0 then use container label

-- mGeek
Source: StackOverflow