23w4ertfgyhj
23w4ertfgyhj

Reputation: 703

How to extract label value to a variable in Grafana?

In my Grafana I have a Variable:

Name: variable_host_ip

Type: Query

Data Source: Prometheus

Refresh: On Dashboard Load

Query: query_result(kube_pod_info{pod=~".*kube-proxy.*"})

Result:

kube_pod_info{created_by_kind="DaemonSet",created_by_name="kube-proxy",endpoint="kube-state-metrics",host_ip="192.168.0.238",instance="192.168.0.244:8080",job="kube-state",namespace="kube-system",node="192.168.0.2",pod="kube-proxy-",pod_ip="192.168.0.123",service="kube-prometheus-exporter"} 

How can I filter this so the result will be 192.168.0.238?

I tried with regex but Grafana doesn't seem to support advanced regex to extract IP address.

Upvotes: 0

Views: 4148

Answers (2)

mighq
mighq

Reputation: 1024

Use label_values(EXPRESSION, LABEL) as Query in the variable definition.

Upvotes: 4

Try the following Regex:

/.*host_ip="([^"]+)".*/

Upvotes: 4

Related Questions