I installed Prometheus using Helm, which automatically includes cAdvisor and other components. I have several pods with similar names, but each has a unique identifier, such as my-app-23hj2
and my-app-44h23
.
I created a Grafana dashboard to visualize resource utilization for these pods, and I want to select all pods that start with the prefix my-app. However, I can’t use my-app.*
because I have other pods with different names like url-shortener-2u3j2
, so I cannot directly use the regex my-app.*
.
- source_labels: [__meta_kubernetes_pod_name]
regex: "^([^-]+)-.*"
target_label: first_word
replacement: $1
I tried creating new labels using regex to capture only the first two suffixes of each pod name, but I haven’t gotten it right. How can I correctly filter these pods by their common prefix?
1
You can filter pods begining with my-app
substring directly in Grafana using pattern pod=~"my-app-[^-]+"
. For example:
sum(container_memory_usage_bytes{pod=~"my-app-[^-]+"})
1