Prometheus labels identify the targets and other dimensions attached to a metric. A Grafana query variable turns those label values into a dashboard dropdown, so the same panel can display a different target without a query edit.

A Query variable fetches its choices from the selected Prometheus data source. The dropdown alone does not filter a panel; the panel's PromQL expression must reference the variable in a label matcher. A single-value variable works with an equality matcher, while multiple selections require regular-expression matching.

The dashboard needs an existing Prometheus data source, permission to save edits, and a panel whose metrics carry the chosen label. The instance label suits a target selector. Its values come from the scraped series, so a target missing from those series cannot appear as a choice.

Steps to add a Prometheus label variable in Grafana:

  1. Open the dashboard that should receive the label dropdown from Dashboards.
  2. Click Edit in the dashboard toolbar.
  3. Click the plus button above the panel area.

    The variable control is at the upper left, beside any existing variables; the plus button in the right sidebar adds dashboard elements.

  4. Choose Variable from the menu.
  5. Select Query as the variable type.
  6. Set Name to target_instance.

    The name identifies the variable inside PromQL. It must be unique within the dashboard.

  7. Enter Instance in Label.

    This label appears beside the dropdown; it does not change the Prometheus label being queried.

  8. Click Open variable editor under Query options in the sidebar.
  9. Select the dashboard's Prometheus data source in Target data source.
  10. Set Query type to Label values.
  11. Select instance in the required Label field.

    An empty Metric field queries label values across metrics. For a dropdown limited to one metric, the optional Metric field can hold that metric instead. Labels such as job or env work only where they exist on the series being filtered.

  12. Click Run query to populate Preview of values.
  13. Click Apply when the preview contains the expected instance values.

    An empty preview points to the selected data source, label, or metric filter. The default Refresh setting is On dashboard load. Multi-value and Include All value remain off for the single-value matcher below.

  14. Close the Query variable sidebar with its upper-right X.
  15. Select the panel that should respond to Instance by clicking its title.
  16. Click Edit visualization in the Panel sidebar.
  17. Select Code in the panel's Queries section.
  18. Set the panel's PromQL instance matcher to instance="$target_instance".
    up{instance="$target_instance"}

    If an instance matcher already exists, replace it; otherwise, add one inside the metric's selector braces. Other label matchers and the surrounding query stay unchanged. If multi-value or All selection is enabled later, the matcher must use instance=~"$target_instance" instead.

  19. Click Run queries to refresh the panel with the edited expression.
  20. Click Back to return to the dashboard editor.
  21. Click Save in the dashboard toolbar.
  22. Click Save in the Save dashboard drawer to store the variable and panel query.
  23. Click Exit edit after the dashboard is saved.
  24. Select a different value from the Instance dropdown.
  25. Reload the dashboard in the browser.
  26. Confirm that the panel displays only the selected instance after reloading.

    For up, 1 means the scrape succeeded and 0 means it failed; either value can confirm the selected target's series. The legend here contains only node-02, matching Instance. If the panel shows No data, check the time range, selected label value, and request in Query inspector.
    Related: How to use Grafana query inspector

Share this guide