prometheusgrafana

How to make one label value refer another label values in grafana


This query label_values(kubelet_runtime_operations_total{job="kubelet", metrics_path="/metrics"}, instance) gives label as:

100.130.101.101 100.130.101.102 100.130.101.103

another different query gives nodes: devops-test-srv01 devops-test-srv02 devops-test-srv03

I tried custom values like this 100.130.101.101 : devops-test-srv01,100.130.101.102 : devops-test-srv02,100.130.101.103 : devops-test-srv03 and used ${label:text} and ${label:value} where I only be using the label as filter and thing is I don't want to do customization in the production everytime

How to map the two labels in query so that I don't have to reconfigure again manualy in the custom values in a new cluster?


Solution

  • Looks like in both cases you could craft the label name from the last 2 digits of the initial label value:

    https://regex101.com/r/rufmke/1

    So you might want to use label_replace():

    label_replace(kubelet_runtime_operations_total, "instanceNew", "devops-test-srv$1", "instance", ".*(\\d\\d)$")
    

    --->

    kubelet_runtime_operations_total{instance='100.130.101.103', instanceNew='devops-test-srv03'} 1
    kubelet_runtime_operations_total{instance='devops-test-srv03', instanceNew='devops-test-srv03'} 2