help with relabel in kubernetes

44 views
Skip to first unread message

cava cavamagie

unread,
May 20, 2020, 5:04:05 PM5/20/20
to Prometheus Users
HI
i'm newbi
can someone help me to write a relabeling to obtain


targets: ['test-env.prometheus-dev:9095']


i think i have to use this but now why

__meta_kubernetes_pod_container_name="test-env"
__meta_kubernetes_namespace="prometheus-dev"
__meta_kubernetes_pod_container_port_number="9095"


many thanks for help

Andrea


ps can i add other custom label?

Julius Volz

unread,
May 21, 2020, 4:55:53 AM5/21/20
to cava cavamagie, Prometheus Users
Hi,

It sounds like you want a relabeling rule like:

relabel_configs:
- action: replace
  source_labels: [__meta_kubernetes_pod_container_name, __meta_kubernetes_namespace, __meta_kubernetes_pod_container_port_number]
  target_label: instance
  regex: (.+);(.+);(\d+)
  replacement: $1.$2:$3

(The source labels are concatenated with a ";" by default for the regex match - you can control this character by setting "separator: ..." explicitly in the relabeling rule)

Be aware that the combination of pod container name, namespace, and port number doesn't necessarily give you a unique instance identifier, as there could be multiple pods with the same attributes. If you have multiple pods of the same type, you probably want some distinguishing label like "__meta_kubernetes_pod_name" or so in there. Most commonly, the labels that identify a type of instance rather than a single specific instance / pod, are put into the "job" label instead (with sometimes some dimensions like namespace etc. broken out into separate labels as well).

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/aefcf756-f60f-4ac3-8720-36ddb0e5cb28%40googlegroups.com.


--
Julius Volz
PromLabs - promlabs.com

cava cavamagie

unread,
May 22, 2020, 11:44:26 AM5/22/20
to Prometheus Users
hi thanks it works!!!

there is the possibility to mantain other label without using to match the target? only to filter in grafana?

thanks
To unsubscribe from this group and stop receiving emails from it, send an email to promethe...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages