
* refactors config panels and visualizations, corrects relrefs * adds an alias * Remove some old content * moves visualizations topic to the root * moves out panels and visualization topics to the root * adds move and resize panel to add/organize panel; creates a create dashboard topic under build dashboards; adjusts context of add a panel to be from within an existing dashboard * updates aliases * creates search at root, moves dashboard preview to search, creates standalone search dashboard topic * moves Set dashboard time range to use-dashboards, creates modify dashboard settings and adds moves Modify dashboard time settings to that topic * moves existing query-options topic from working with panels to configure-panel-visualizations, moves panel time overrides and timeshift content to query options * Moving things to better category, fixing links, improving ordering * Move panel inspector to main panel topic * completes partial fix of relrefs * relref fixes con't * restructures remaining panels topics * more relref fixes * Minor fix * Minor tweak * finishes fixing relrefs Co-authored-by: Torkel Ödegaard <torkel@grafana.com> Co-authored-by: Jack Baldry <jack.baldry@grafana.com>
4.3 KiB
aliases | title | weight | |||
---|---|---|---|---|---|
|
Variables | 130 |
Variables
The following topics describe how to add and manage variables in your dashboards:
{{< section >}}
A variable is a placeholder for a value. You can use variables in metric queries and in panel titles. So when you change the value, using the dropdown at the top of the dashboard, your panel's metric queries will change to reflect the new value.
Variables allow you to create more interactive and dynamic dashboards. Instead of hard-coding things like server, application, and sensor names in your metric queries, you can use variables in their place. Variables are displayed as dropdown lists at the top of the dashboard. These dropdowns make it easy to change the data being displayed in your dashboard. {{< figure src="/static/img/docs/v50/variables_dashboard.png" >}}
These can be especially useful for administrators who want to allow Grafana viewers to quickly adjust visualizations but do not want to give them full editing permissions. Grafana Viewers can use variables.
Variables and templates also allow you to single-source dashboards. If you have multiple identical data sources or servers, you can make one dashboard and use variables to change what you are viewing. This simplifies maintenance and upkeep enormously.
Templates
A template is any query that contains a variable.
For example, if you were administering a dashboard to monitor several servers, you could make a dashboard for each server. Or you could create one dashboard and use panels with template queries like this one:
wmi_system_threads{instance=~"$server"}
Variable values are always synced to the URL using the syntax var-<varname>=value
.
Examples
Variables are listed in drop-down lists across the top of the screen. Select different variables to see how the visualizations change.
To see variable settings, navigate to Dashboard Settings > Variables. Click a variable in the list to see its settings.
Variables can be used in titles, descriptions, text panels, and queries. Queries with text that starts with $
are templates. Not all panels will have template queries.
The following dashboards in Grafana Play provide examples of template variables.
- Elasticsearch Metrics - Uses ad hoc filters, global variables, and a custom variable.
- Graphite Templated Nested - Uses query variables, chained query variables, an interval variable, and a repeated panel.
- Influx DB Group By Variable - Query variable, panel uses the variable results to group the metric data.
- InfluxDB Raw Query Template Var - Uses query variables, chained query variables, and an interval variable.
- InfluxDB Server Monitoring - Uses query variables, chained query variables, an interval variable, and an ad hoc filter.
- Prometheus templating - Uses chained query variables.
- Template Redux - Uses query variables, chained query variables, ad hoc filters, an interval variable, a text box variable, a custom variable, and a data source variable.
- Templating, repeated panels - Two sets of repeated panels use query variables.
- Templating showcase - Uses custom, query, chained query, and data source variables.
- Templating value groups - Uses query variable with value groups.
Variable best practices
- Variable drop-down lists are displayed in the order they are listed in the variable list in Dashboard settings.
- Put the variables that you will change often at the top, so they will be shown first (far left on the dashboard).