Skip to Content
KubeSense

Variables

Variables let you create dynamic, reusable dashboards. Define variables at the dashboard level, then reference them in panel queries using $variableName syntax. When a variable value changes, all panels that reference it update automatically.

Creating Variables

Overview

Variables appear as dropdowns or text inputs at the top of the dashboard. On a dashboard with tabs, the variables apply to every tab. They allow users to filter and slice dashboard data without editing individual panel queries. For example, you might create variables for workload, protocol, node, or version to let users dynamically scope the entire dashboard.

Variable Types

Traces, Logs, and Metrics

These variable types are dynamically populated from your observability data:

TypeConfiguration
TracesSelect a trace Field — the variable is populated with all distinct values for that field
LogsSelect a log Field — the variable is populated with all distinct values for that field
MetricsSelect a Metric and a Label — the variable is populated with all distinct values of that label for the chosen metric

Use these when you want the variable options to reflect live data (e.g., all available service names, namespaces, or status codes).

RUM

Populated from Real User Monitoring data. Pick an Event Type (session, view, action, error, resource or long_task) and a Field of that event type, such as application_id, browser_name, device_type or country. The dropdown lists the top 50 values of the field over the dashboard time range; typing searches all values for that text. Any filterable field that is not numeric can be used, including list fields such as state or city on sessions, where a selection matches sessions whose list contains it.

Add optional Filters to scope which events the values come from. A filter can reference another variable, which makes the variable dependent. For example, a dev variable on device_type filtered by application_id = $app lists only the device types of the application chosen in $app.

If you change the event type, the field and filters are kept when the new event type has them, and dropped otherwise.

Textbox

A free-text input field. The user types any value, which is then substituted into queries. Use this for ad-hoc filtering where the set of possible values is not known in advance (e.g., a specific pod name or custom tag).

Static

A predefined list of values that you define when creating the variable. The user selects from this fixed set of options. Use this when the possible values are known and unlikely to change (e.g., environment names like production, staging, development).

Single Select vs Multi Select

Each variable can be configured as Single Select or Multi Select:

ModeBehavior
Single SelectUser picks exactly one value. A default value must be provided when creating or editing the variable.
Multi SelectUser can pick one or more values from the dropdown.

Choosing the Right Query Operator

The selection mode determines which query operators you should use in your panel queries:

Selection ModeOperator
Single selectEQ, NEQ
Multi select (single value selected)EQ, NEQ
Multi select (multiple values selected)IN, NOT_IN

Creating a Variable

  1. Open a dashboard and click Add Variable at the top of the page
  2. Enter a Name (used to reference the variable as $name, or $$name for its field, in queries)
  3. Optionally add a Description
  4. Select the Variable Type (Traces, Logs, Metrics, RUM, Textbox, or Static)
  5. Configure the type-specific fields (e.g., select a Field for Traces/Logs, a Metric and Label for Metrics, or an Event Type and Field for RUM)
  6. Choose Single Select or Multi Select
  7. If Single Select is enabled, provide a Default Value
  8. Click Create

Using Variables in Queries

Using Variables

Once created, variables can be referenced in any panel query using the $variableName syntax. In the example above, the Traces query filter includes $version, $node, $protocol, and $workload — all defined as dashboard variables. Changing any variable value at the top of the dashboard instantly re-runs the query with the new filter values.

Referencing a Variable's Field with $$

With $name you write both halves of the condition yourself: the field, then the variable that supplies its values (namespace = $namespace). A field reference, $$name, writes both for you. KubeSense takes the field from the variable's configuration and the values from its current selection, so $$namespace means "namespace is one of the selected namespaces".

Using a field reference

In the example above, the metrics filter bar holds phase:Running and $$namespace. With kubesense selected in the namespace variable, the panel runs kube_pod_status_phase{phase="Running", namespace="kubesense"}.

Field references work with Traces, Logs, RUM, and Metrics variables, which name a field or label. Textbox and Static variables have no field, so only $name is available for them.

WhereWriteRuns as
Filter bar (traces, logs, metrics builder)Type $$ and pick the variable from the suggestionsnamespace = the selected values
Advanced querystatus = "error" AND $$namespacestatus = "error" AND namespace IN (…selected values)
PromQL (code mode)kube_pod_status_phase{$$namespace, phase="Running"}kube_pod_status_phase{namespace="…", phase="Running"}, matching the selected values

In PromQL, write the reference inside a selector's braces, where a label matcher can go.

How the condition follows the selection

  • One value selected: the condition matches that value.
  • Several values selected: the condition matches any of them.
  • Nothing selected: the condition is left out, and the panel shows every value of the field.
  • Variable's field changed: every panel that uses $$name filters on the new field. You do not need to edit the panels.

note: Field references are expanded only in the places listed above. SQL and SPL queries do not expand $$name.

On this page