How to add kubernetes pods label to prometheus metrics?

6/12/2019

There is a label like envName=vnc in kubernetes pod yaml file, the original metrics collected by prometheus is:

container_memory_usage_bytes{container_name="vncserver-vscode",id="......",image="......",name="......",namespace="kube-system",pod_name="vncserver-vscode-59878ff5cf-l2dd9"} 6.28785152e+08

And I want add the label to the metrics, like this:

container_memory_usage_bytes{container_name="vncserver-vscode",id="......",image="......",name="......",namespace="kube-system",pod_name="vncserver-vscode-59878ff5cf-l2dd9", envName="vnc"} 6.28785152e+08

Does prometheus support that?

-- zhashuyu
kubernetes
prometheus

1 Answer

6/12/2019

Unfortunately there's no way to do this. You can not change/add labels in metrics that already exists. You will need to create new scrape with desired labels.

-- VKR
Source: StackOverflow