Skip to main content

Dashboard Templating

Templating allows you to create dynamic, reusable dashboards that adapt based on variable values. Template variables can be used throughout your dashboard in queries, panel titles, annotations, and links.

Template Syntax

Grafana uses a simple templating syntax for variable interpolation:

Variable Interpolation

In Queries

Template variables are most commonly used in data source queries:

In Panel Titles

Make panel titles dynamic:

In Descriptions

Add context with variable values:

In Annotations

Filter annotations using variables:
Create dynamic dashboard and external links:

Variable Formats

Apply different formats to variable values:

Text Formats

Multi-Value Formats

Date Formats

Format time range variables:

Advanced Templating

Nested Variables

Variables can reference other variables:

Chained Variables

Create variable dependencies:
Be careful with variable chains. When a parent variable changes, all dependent variables refresh, which can cause performance issues with many levels.

Conditional Templating

Use variable values to control behavior:

Dynamic Panel Repetition

Repeat panels based on variable values:

Row Repetition

Repeat entire rows:

Built-in Template Variables

Grafana provides several built-in variables:

Time Range Variables

Rate Interval

Series Variables (Panel Repeat)

Dashboard Variables

URL Variables

Template Functions

While Grafana doesn’t have built-in template functions, you can achieve similar results:

String Manipulation via Regex

Mathematical Operations

Use query expressions:

Best Practices

Query Optimization

1

Use Appropriate Refresh

Set refresh to match data update frequency
2

Limit Variable Cardinality

Avoid variables with thousands of values
3

Use Constants for Static Values

Don’t query for values that never change
4

Cache When Possible

Use onDashboardLoad refresh for static data

Naming Conventions

Variable Organization

Order variables logically:
  1. Data source variables first
  2. High-level filters (environment, region)
  3. Mid-level filters (datacenter, cluster)
  4. Low-level filters (server, pod)
  5. Display options (interval, aggregation)
  6. Hidden variables last

Performance Considerations

Keep these performance tips in mind:
  • Limit variable chains to 3-4 levels max
  • Avoid regex on large result sets
  • Use multi-value variables sparingly
  • Set reasonable maxPerRow for repeated panels
  • Consider hiding variables not needed by users

Common Patterns

Multi-Tenant Dashboards

Environment-Based Configuration

Dynamic Aggregation

Time Window Comparison

Troubleshooting

Variable Not Interpolated

  • Check variable name spelling and syntax
  • Verify variable has a current value
  • Check for hidden or disabled variables
  • Review variable scope and permissions

Incorrect Format

  • Use correct format for data source type
  • Check multi-value variable formatting
  • Verify escape characters in regex

Performance Issues

  • Reduce variable query complexity
  • Limit number of chained variables
  • Decrease auto-refresh frequency
  • Use constant variables for static data

Next Steps

Variables

Learn about all variable types and configuration

Creating Dashboards

Build dashboards using templates

Panels

Apply templates in panel queries

Sharing

Share templated dashboards