How to use Grafana variables in a promql query count_values("__label_name__", __metric__)

Hi, I’m in need of some help, I’ve already searched the official documentation and Google and I haven’t found anything on the topic.

I have a panel with a graph showing the amount of DaemonSet (K8s). On dashboar I have a variable called namespace

  • To use the namespace variable in other panels, I use the following query:

    count(kube_daemonset_status_number_available{namespace=~"$namespace"})
    
  • I can’t find a way to use the variable {namespace=~"$namespace"} in the following query:

    count_values("kube_daemonset_status_number_available", kube_daemonset_status_number_available != 0)
    
  • Query structure:

    count_values("__label_name__", __metric__)
    

Thank you for your help

Hi,

I understand where to insert the variable {namespace=~"$namespace"} into the count_values("__label_name__", __metric__) query.

Here’s how I’m using it on Grafana:

count_values("kube_daemonset_status_number_available", kube_daemonset_status_number_available {namespace=~"$namespace"} != 0)

Hope this topic helps other people who might need it.