Create and Manage Variables
Overview
Variables allow you to build flexible, interactive Custom Dashboards. Instead of hardcoding values like environment names or service IDs directly into each widget’s query, you can define a template variable once and reuse it throughout your dashboard.
This guide walks you through how to set up, create, and use dashboard variables.
Create a variable
To create a new variable:
- Click {} on the left side of the dashboard.
- In the VARIABLES panel, click + Variable.
- Enter the variable details including the variables name, display name, and optional description.
Field | Description |
---|---|
Variable name | Internal reference used in widget queries (e.g., ${env} ). Must be unique, lowercase, and contain no spaces. |
Display name | Friendly label shown in the dashboard toolbar. Can contain spaces and capitalization. |
Description (optional) | Tooltip shown on hover to explain how the variable is used. Helps collaborators understand its purpose. |
Choose how the variable will behave based on the kind of values it should accept.
Choose a value type
Each variable must have an Expected Value Type that defines the kind of data the variable is meant to hold. Specific Methods (how the values are provided) are supported based on the value type you selected.
Note
The value type determines the kind of values the variable selects. The method is the mechanism in which the values are assigned to the variable.
Expected Value Type | Purpose | Supported Methods | Example Use Cases |
---|---|---|---|
Single string | A single value selected or entered | Static values, Text box, all Query (All sources: DataPrime, metrics, logs/spans) | Filter by one service, team, or region |
Multi-string | One or more values (tags-like input) | Static values, Query (All sources: DataPrime, metrics and logs/spans) | Filter by multiple environments, error codes |
Numeric | A single number | Text box, Static values, DataPrime query | Thresholds, percentile selection, scaling factor |
Regex | A pattern-matching expression | Text box | Match log labels or spans using wildcard/pattern filters |
Lucene (coming soon) | A structured Lucene query | Text box | Inject Lucene logic into log or span queries |
Note
Some methods support both single and multiple values. A query-based method, for example, may return multiple values, but whether the variable accepts multiple selections depends on the value type (single-string vs. multi-string).
Choose a method
The method defines how the values for the variable will be entered, retrieved, or calculated. Each method has its own configuration rules and use cases.
Method | Description | Supported value types |
---|---|---|
Static values | Enter a fixed list of values (e.g., frontend , backend ). | single-string , multi-string |
Text box | Allow dashboard users to manually input values. | single-string , numeric , regex , Lucene (coming soon) |
Query | Dynamically populate values by querying logs, spans, metrics, or DataPrime. | single-string , multi-string , numeric |
Static values method
Use static values when you know the set of possible options in advance, such as teams, environments, or regions.
Configuration
- Enter values as a comma-separated list (e.g.,
frontend, backend, api
). - Optionally map query values to user-friendly display names using
key : value
syntax (e.g.,us-east:US East
). The left side (key
) is the display value used in the query, and the right side (value
) is the actual value injected into the variable. - Set a default value to preselect when the dashboard loads.
Behavior
- Users select from a predefined dropdown list.
- Values do not update unless manually edited.
Use-case example
You define a variable region
with values:
This shows “US East” in the dropdown, but uses us-east
in your queries.
Text box method
Text boxes allow you to manually enter values in the dashboard. The variable method defines how input is interpreted and validated.
- Single-string: Manually enter a single text value.
- Numeric: Enter numbers for thresholds or parameters.
- Regex: Enter regex patterns to filter or extract values.
- Lucene (pending release): Enter Lucene query expressions for logs/traces (e.g.,
resource.attributes.cloud_region:"us-east-2”
).
Behavior
- Users type values into a text field at runtime.
- Used for dynamic filters and template inputs.
- Lucene and Regex are mutually exclusive and must be chosen at variable creation.
Use-case examples
Lucene (coming soon)
Allows structured expressions such as severity: “error”
or cx_rum.environment: "production"
.
Example widget query:
Use when you need field-based filtering, especially for complex log or span queries that can include boolean logic, phrase matching (e.g., "connection timeout"
) or exact field-value pairs.
Regex
Regex (regular expressions) textbox allows you to match, filter, or transform variable values based on patterns instead of exact matches. This is useful when your values share naming patterns (e.g., different node IDs, region codes, or service prefixes) and you want to select them dynamically without listing every possibility.
Supports input like .*prod.*
and named capture groups (e.g., (?<value>.*)
):
Example widget query (PromQL):
If ${hostname}
is a variable populated with node names, the regex ensures that the variable includes only values matching the node
naming pattern. The =~
operator applies the regex filter inside the metric query.
Number
Used for:
- Thresholds in visualizations
- Statistical filters (e.g., percentiles)
- Multipliers or units
Examples widget queries (metric):
1. Percentile value with scaling factor
(histogram_quantile(0.99, sum(rate(price_cx_bucket[5m])) by (le))) * ${factor}
This PromQL query calculates the 99th percentile from a histogram and then multiplies the result by ${factor}
. Set ${factor}
to apply a scaling or unit conversion (for example, 1000
to convert seconds to milliseconds).
2. Dynamic percentile selection
(histogram_quantile(${factor}, sum(rate(price_cx_bucket[5m])) by (le))))
Here, ${factor}
is a numeric variable that determines which percentile to display (for example, 0.5
for median, 0.9
for the 90th percentile). You can switch the value at runtime to explore different percentiles without editing the query.
Query method
Use the query method when you want to populate variable values dynamically based on your latest telemetry data. This is sourced and retrieved from logs, spans, metrics, and DataPrime queries.
Behavior
- A query runs in the background to retrieve possible values.
- The values list updates automatically.
Logs or spans
- Select a field (e.g.,
objectRef.name
,json.http_resp_status
) - The variable dropdown shows all distinct values for that field.
Use Case: Filter by severity
from span metadata.
Metric names or labels via regex
- Use regex to filter metric names or label names.
Example:
This pattern matches any metric label named node
, with or without a trailing number (e.g., node19
, node7
).
Use Case: Show “frontend” in the UI, but pass api
into the query.
Metric label values
Use this method to populate your variable with the values of a specific label from a selected metric. This is useful when you want to filter widgets by metric attributes like cpu
, or instance
.
- Select a metric (e.g.,
http_requests_total
). - Choose a label (e.g.,
status_code
). The variable is populated with all values of that label - Optionally, add label filters to limit which metric series are queried when retrieving values.
Note
You can reference other variables inside the label filters. This allows you to “nest” variables, so the label values shown for this variable depend on the selection made in another variable.
Use Case: Filter dashboards by metric dimensions such as HTTP status codes or region, based on the labels defined in your metric data.
DataPrime
- Write a custom DataPrime query that returns values.
- Your query can retrieve values from logs, metrics, or spans. Learn more about DataPrime queries.
- Reference template variables in your widgets using
$p.variableName
.
Example:
Use Case: Dynamically generate values for log severities or groupings.
Format and filter display values
Filter display values
Use regex to include or exclude certain results from the values list.
Example: /frontend.*/
filters for services starting with “frontend”.
Format display values
Use named regex capture groups to specify which part of the value should be displayed in the values list.
text
: shown in the dropdown.value
: inserted in the query.
If no groups are defined, the full match is used for both display and value.
Include all option
Enable Include All to add an “All” option to the variable dropdown. This selects all available (and future) values in a single click.
Behavior
- “All” automatically maps to every available result.
- The dropdown option label can be renamed (e.g., “Any”, “All (*)”).
- If disabled, users must manually select values.
Use variables in queries
You can reference variables in widget queries across all query languages:
Query Type | Syntax | Example |
---|---|---|
Lucene | ${variable} | env:${env} |
PromQL | ${variable} | rate(http_requests_total{pod=~"${pod}"}[5m]) |
DataPrime (single value) | $p.variable | filter env == $p.env |
where variable name is env | ||
DataPrime (multi value) | $p.variable | filter if($p.envs ≠ null, $p.envs.arrayContains(env), true) or firstNonNull(arrayContains($p.var, $d.foo), true) |
Advanced: Chained variables
You can use the values of one variable inside another’s query.
Example:
Define a cluster
variable and use it in a pod
variable:
source logs | filter $d.resource.attributes.k8s_cluster_name == $p.cluster | distinct $d.kubernetes.pod.name
This filters pod
values by the selected values in your cluster
variable.
Manage variables
Easily view and manage the variables from the Custom Dashboards upper toolbar.
Edit or delete
To edit or delete a variable:
- Hover over the variable at the top of the dashboard.
- Click the
more actions menu. - Select EDIT or DELETE from the dropdown.
Reorder variables
Variables support drag-and-drop reordering, allowing you to organize them in a logical and meaningful order-especially helpful after adding new variables.
To reorder one or more variables:
- Click
Manage Variables. - In the VARIABLES panel that opens, drag variables up or down to update their order in the toolbar at the top of your dashboard.
Query with template variables
You can use template variables in Lucene, PromQL, or DataPrime queries to build reusable dashboards. This eliminates the need to input the same data points into each widget, and instead allows you to filter all the widgets on your dashboard simultaneously with one variable.
To edit the query, select the widget and navigate to the query builder at the bottom of the screen.
Lucene
In a Lucene query, a template variable is referenced with {{ variable_name }}
syntax.
Example:
In this example, the pid
is the variable name, which must match the name you defined in the dashboard.
PromQL
In a PromQL query, a template variable is referenced with ${variable_name}
syntax.
Example:
In this example, {pod=~${pod}}
is a label selector that filters the kube_pod_owner
metric for the specific pod whose name matches the name selected in the ${pod}
template variable. The ${pod}
is dynamically replaced with the selected pod when the query runs.
DataPrime
In a DataPrime query, a template variable is accessed with $p.<variable_name>
syntax.
Example:
source logs
| filter $l.applicationname.inArray($p.application)
| groupby $l.applicationname as Application
, $m.timestamp / 10m as timestamp agg count() as count
In this example, the DataPrime query groups log activity into 10 minute intervals and filters them by the selected application
dashboard variable, using a parameter that dynamically updates based on the variable you select. This allows you to compare log volume across one or more applications.
Learn more about query parameters.
Global variables
Coralogix provides predefined, system-managed variables that automatically adapt to the scope of your dashboard context. These variables can be included directly in your widget queries and update dynamically when the global dashboard context changes, such as when you adjust the dashboard time range using the time picker.
PromQL predefined variables
Use these variables in metrics-based widgets.
Variable | Description | Example |
---|---|---|
${__range} | This variable represents the duration of the dashboard time range. It is rendered as an interval string supported by PromQL. e.g., If one selects a time range from 13.00 to 14.30, then ${__range} will be rendered as 90m . | 30m , 1d |
${__range_s} | Rendered as the number of seconds in the selected time frame. | 60s , 180s |
${__range_ms} | Rendered as the number of milliseconds in the selected time frame. | 60ms , 180ms |
${__interval} | A dynamic interval based on the selected time range. Used to group time series data efficiently in visualizations. Behavior depends on the widget type. In widgets that support time bucket configuration (such as line charts and vertical bar charts by time), the ${__interval} variable resolves to the value set in the widget's configuration. In other widgets, it defaults to the selected time range divided by 96. | 5m , 1h , 1d |
${__interval_s} | The ${__interval} value in seconds, rendered as a number. Useful for functions that require interval math in seconds. | 60s , 1200s |
${__interval_ms} | The ${__interval} value expressed in milliseconds as a number. Useful for calculations or functions requiring millisecond precision. | 60000ms , 1200000ms |
${__rate_interval} | A dynamic range for PromQL rate() queries. It resolves to the larger of ${__interval} + 15s or 60s , ensuring both adequate overlap and enough data points for accurate calculations. | 60s , 2m |
${__rate_interval_s} | The ${__rate_interval} value in seconds, rendered as a number. | 60s , 120s |
${__rate_interval_ms} | The ${__rate_interval} value expressed in milliseconds as a number. Enables precise math and comparisons. | 6000000ms , 1200000ms |
Example:
This query calculates the average CPU time accumulated across all nodes over the time range selected in the dashboard. The ${__range}
variable dynamically reflects the current time picker selection, so the aggregation always matches the visible timeframe.
DataPrime predefined variables
Take advantage of predefined global dashboard variables in your widgets querying with DataPrime.
Variable | Description | Example |
---|---|---|
$p.timeRange.startTime | The start of the dashboard time range, based on the current time picker setting. Use this to align query results with the visible time scope. | 1d , 5m , 60s |
$p.timeRange.endTime | The end of the dashboard time range, based on the current time picker setting. Use this to align query results with the visible time scope. | 1d , 5m , 60s |
$p.timeRange.suggestedInterval | The suggested interval variable allows you to include queries that automatically adjust the widget's query and visualization according to the current dashboard time range by dividing it into 96 uniform time buckets. This ensures the query and visualization remain appropriately scaled as users change the time picker. | 1d , 5m , 60s |
Example:
source logs | groupby $m.timestamp / $p.timeRange.suggestedInterval
as timestamp agg count() as count
This example dynamically groups log data by time without hardcoding an interval, ensuring the widget adapts gracefully across different time ranges. Use $p.timeRange.suggestedInterval
instead of manually selected a time interval, which can result in charts that are too broad or too granular when the time range is adjusted.
Additional resources
