Sumo Logic template variables
Template variables let you create dynamic, reusable dashboards where users can change what data is displayed using drop-down selectors instead of editing queries directly. For example, you can create a variable that lists all available hosts, then use it to filter dashboard panels to a specific host.
For general information about variables in Grafana, refer to Templates and variables.
Before you begin
- Configure the Sumo Logic data source.
- Familiarize yourself with Grafana template variables.
Supported variable types
The following table lists the variable types supported by the Sumo Logic data source.
Create a query variable
Query variables populate their options by running a query against the data source. The Sumo Logic data source runs variable queries as metrics queries using the raw code editor – the visual Builder mode isn’t available for variable queries.
The query returns values from the first string field in the results. If no string field exists, it uses the first non-time field. If the query returns an error or no data, the variable has no options.
Variable queries are time-range aware. When the dashboard time range changes and the variable refresh setting is set to On time range change, the query re-runs and the variable options update accordingly.
To create a query variable:
- Navigate to Dashboard settings > Variables.
- Click Add variable.
- Select Query as the variable type.
- Select your Sumo Logic data source.
- Enter a metrics query in the Query field that returns the values you want as variable options.
- Choose a Refresh option to control when the variable updates.
Variable query examples
Return a list of available metrics:
* | count by metricReturn a list of hosts reporting CPU metrics:
metric=cpu_idle | count by hostReturn a list of departments:
metric=cpu_idle | count by departmentReturn a list of source categories from a specific metric:
metric=http_requests | count by _sourceCategoryUse variables in queries
After creating a variable, reference it in your Sumo Logic queries using variable syntax. Variable substitution is supported in the following query fields:
- Query: The main query string for both metrics and logs queries.
- Rollup: The rollup function for metrics queries.
Metrics query examples
Filter by a single-value variable named host:
metric=cpu_idle host=$hostUse a multi-value variable named department with the in filter syntax:
metric=cpu_idle department=($department)Combine multiple variables to drill down:
metric=$metric host=$host | avg by _sourceCategoryUse a variable in the rollup field by setting the Rollup drop-down to $rollup, where rollup is a Custom variable with values like Avg, Sum, Max.
Logs query examples
Filter logs by host:
_sourceHost=$host error | count by _sourceCategoryUse a variable for the source category:
_sourceCategory=$sourceCategory | count by _sourceHost | sort by _count descCombine variables to scope log searches:
_sourceHost=$host _sourceCategory=$sourceCategory $search_term | count by _messageSeverity


