You can use Grafana template variables ($var or ${VarName}) to make dashboards dynamic. This is useful for switching between different Log Topic IDs or time intervals.
Query Type Variables
Use this to populate a variable with values from your logs (e.g., a list of HTTP status codes).
- Set variable name (e.g.,
HttpStatus). - Set type to Query.
- Select the Log Service data source.
- Use a query like:
| select distinct(status). - Reference it in your panel query:
status: ${HttpStatus}.
Custom Type Variables
Use this for predefined lists (e.g., time intervals).
- Set variable name (e.g.,
Interval). - Set type to Custom.
- Enter comma-separated values:
1 MINUTE,5 MINUTE,15 MINUTE. - Reference it in your query:
| select ... interval ${Interval}) ....
Quick Topic ID Switching
To switch between different log topics quickly:
- Create a variable named
TopicId (Type: Custom or TextBox). - In your panel's Log Topic ID input field, enter
$TopicId.
-- Example: Using a Custom variable ${Interval}
| select histogram( cast(__TIMESTAMP__ as timestamp),interval ${Interval}) as time, count(*) as pv group by time order by time
-- Example: Using a Query variable ${HttpStatus}
status: ${HttpStatus}