<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>InfluxDB data source on Grafana Labs</title><link>https://grafana.com/docs/grafana/v9.3/datasources/influxdb/</link><description>Recent content in InfluxDB data source on Grafana Labs</description><generator>Hugo -- gohugo.io</generator><language>en</language><atom:link href="/docs/grafana/v9.3/datasources/influxdb/index.xml" rel="self" type="application/rss+xml"/><item><title>Flux support in Grafana</title><link>https://grafana.com/docs/grafana/v9.3/datasources/influxdb/query-editor/</link><pubDate>Sun, 15 Mar 2026 16:11:32 +0000</pubDate><guid>https://grafana.com/docs/grafana/v9.3/datasources/influxdb/query-editor/</guid><content><![CDATA[&lt;h1 id=&#34;influxdb-query-editor&#34;&gt;InfluxDB query editor&lt;/h1&gt;
&lt;p&gt;This topic explains querying specific to the InfluxDB data source.
For general documentation on querying data sources in Grafana, see &lt;a href=&#34;../../../panels-visualizations/query-transform-data/&#34;&gt;Query and transform data&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;choose-a-query-editing-mode&#34;&gt;Choose a query editing mode&lt;/h2&gt;
&lt;p&gt;The InfluxDB data source&amp;rsquo;s query editor has two modes depending on your choice of query language in the &lt;a href=&#34;../#configure-the-data-source&#34;&gt;data source configuration&lt;/a&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#influxql-query-editor&#34;&gt;InfluxQL&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#flux-query-editor&#34;&gt;Flux&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You also use the query editor to retrieve &lt;a href=&#34;#query-logs&#34;&gt;log data&lt;/a&gt; and &lt;a href=&#34;#apply-annotations&#34;&gt;annotate&lt;/a&gt; visualizations.&lt;/p&gt;
&lt;h2 id=&#34;influxql-query-editor&#34;&gt;InfluxQL query editor&lt;/h2&gt;
&lt;p&gt;The InfluxQL query editor helps you select metrics and tags to create InfluxQL queries.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;To enter edit mode:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Click the panel title.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Edit&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;img
  class=&#34;lazyload d-inline-block&#34;
  data-src=&#34;/static/img/docs/influxdb/influxql-query-editor-8-0.png&#34;
  alt=&#34;InfluxQL query editor&#34; width=&#34;633&#34;
     height=&#34;267&#34;/&gt;&lt;/p&gt;
&lt;h3 id=&#34;filter-data-where&#34;&gt;Filter data (WHERE)&lt;/h3&gt;
&lt;p&gt;To add a tag filter, click the plus icon to the right of the &lt;code&gt;WHERE&lt;/code&gt; condition.&lt;/p&gt;
&lt;p&gt;To remove tag filters, click the tag key, then select &lt;strong&gt;&amp;ndash;remove tag filter&amp;ndash;&lt;/strong&gt;.&lt;/p&gt;
&lt;h4 id=&#34;match-by-regular-expressions&#34;&gt;Match by regular expressions&lt;/h4&gt;
&lt;p&gt;You can enter regular expressions for metric names or tag filter values.
Wrap the regex pattern in forward slashes (&lt;code&gt;/&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;Grafana automatically adjusts the filter tag condition to use the InfluxDB regex match condition operator (&lt;code&gt;=~&lt;/code&gt;).&lt;/p&gt;
&lt;h3 id=&#34;field-and-aggregation-functions&#34;&gt;Field and aggregation functions&lt;/h3&gt;
&lt;p&gt;In the &lt;code&gt;SELECT&lt;/code&gt; row, you can specify which fields and functions to use.&lt;/p&gt;
&lt;p&gt;If you have a group by time, you must have an aggregation function.
Some functions like &lt;code&gt;derivative&lt;/code&gt; also require an aggregation function.&lt;/p&gt;
&lt;p&gt;The editor helps you build this part of the query.
For example:&lt;/p&gt;
&lt;p&gt;&lt;img
  class=&#34;lazyload&#34;
  data-src=&#34;/static/img/docs/influxdb/select_editor.png&#34;
  alt=&#34;&#34; width=&#34;657&#34;
     height=&#34;46&#34;/&gt;&lt;/p&gt;
&lt;p&gt;This query editor input generates an InfluxDB &lt;code&gt;SELECT&lt;/code&gt; clause:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT derivative(mean(&amp;#34;value&amp;#34;), 10s) /10 AS &amp;#34;REQ/s&amp;#34; FROM ....&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;To select multiple fields:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Click the plus button.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Select &lt;strong&gt;Field &amp;gt; field&lt;/strong&gt; to add another &lt;code&gt;SELECT&lt;/code&gt; clause.&lt;/p&gt;
&lt;p&gt;You can also &lt;code&gt;SELECT&lt;/code&gt; an asterisk (&lt;code&gt;*&lt;/code&gt;) to select all fields.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;group-query-results&#34;&gt;Group query results&lt;/h3&gt;
&lt;p&gt;To group results by a tag, define it in a &amp;ldquo;Group By&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;To group by a tag:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Click the plus icon at the end of the GROUP BY row.&lt;/li&gt;
&lt;li&gt;Select a tag from the dropdown that appears.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;To remove the &amp;ldquo;Group By&amp;rdquo;:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Click the tag.&lt;/li&gt;
&lt;li&gt;Click the &amp;ldquo;x&amp;rdquo; icon.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;text-editor-mode-raw&#34;&gt;Text editor mode (RAW)&lt;/h3&gt;
&lt;p&gt;You can write raw InfluxQL queries by switching the editor mode.
However, be careful when writing queries manually.&lt;/p&gt;
&lt;p&gt;If you use raw query mode, your query &lt;em&gt;must&lt;/em&gt; include at least &lt;code&gt;WHERE $timeFilter&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Also, &lt;em&gt;always&lt;/em&gt; provide a group by time and an aggregation function.
Otherwise, InfluxDB can easily return hundreds of thousands of data points that can hang your browser.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;To switch to raw query mode:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Click the hamburger icon.&lt;/li&gt;
&lt;li&gt;Toggle &lt;strong&gt;Switch editor mode&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;alias-patterns&#34;&gt;Alias patterns&lt;/h3&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Alias pattern&lt;/th&gt;
              &lt;th&gt;Replaced with&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$m&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Measurement name.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$measurement&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Measurement name.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$1&lt;/code&gt; - &lt;code&gt;$9&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Part of measurement name (if you separate your measurement name with dots).&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$col&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Column name.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$tag_exampletag&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;The value of the &lt;code&gt;exampletag&lt;/code&gt; tag. The syntax is &lt;code&gt;$tag*yourTagName&lt;/code&gt; and must start with &lt;code&gt;$tag*&lt;/code&gt;. To use your tag as an alias in the ALIAS BY field, you must use the tag to group by in the query.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;p&gt;You can also use &lt;code&gt;[[tag_hostname]]&lt;/code&gt; pattern replacement syntax.&lt;/p&gt;
&lt;p&gt;For example, entering the value &lt;code&gt;Host: [[tag_hostname]]&lt;/code&gt; in the ALIAS BY field replaces it with the &lt;code&gt;hostname&lt;/code&gt; tag value for each legend value.
An example legend value would be &lt;code&gt;Host: server1&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&#34;flux-query-editor&#34;&gt;Flux query editor&lt;/h2&gt;
&lt;p&gt;Grafana supports Flux when running InfluxDB v1.8 and higher.
If your data source is &lt;a href=&#34;./#configure-the-data-source&#34;&gt;configured for Flux&lt;/a&gt;, you can use the &lt;a href=&#34;https://www.influxdata.com/products/flux/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Flux query and scripting language&lt;/a&gt; in the query editor, which serves as a text editor for raw Flux queries with macro support.&lt;/p&gt;
&lt;p&gt;For more information and connection details, refer to &lt;a href=&#34;https://github.com/influxdata/influxdb-client-go/#influxdb-18-api-compatibility&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;1.8 compatibility&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&#34;use-macros&#34;&gt;Use macros&lt;/h3&gt;
&lt;p&gt;You can enter macros in the query to replace them with values from Grafana&amp;rsquo;s context.
Macros support copying and pasting from &lt;a href=&#34;https://www.influxdata.com/time-series-platform/chronograf/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Chronograf&lt;/a&gt;.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Macro example&lt;/th&gt;
              &lt;th&gt;Replaced with&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;v.timeRangeStart&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;The start of the currently active time selection, such as &lt;code&gt;2020-06-11T13:31:00Z&lt;/code&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;v.timeRangeStop&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;The end of the currently active time selection, such as &lt;code&gt;2020-06-11T14:31:00Z&lt;/code&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;v.windowPeriod&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;An interval string compatible with Flux that corresponds to Grafana&amp;rsquo;s calculated interval based on the time range of the active time selection, such as &lt;code&gt;5s&lt;/code&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;v.defaultBucket&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;The data source configuration&amp;rsquo;s &amp;ldquo;Default Bucket&amp;rdquo; setting.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;v.organization&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;The data source configuration&amp;rsquo;s &amp;ldquo;Organization&amp;rdquo; setting.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;p&gt;For example, the query editor interpolates this query:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;flux&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-flux&#34;&gt;from(bucket: v.defaultBucket)
  |&amp;gt; range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |&amp;gt; filter(fn: (r) =&amp;gt; r[&amp;#34;_measurement&amp;#34;] == &amp;#34;cpu&amp;#34; or r[&amp;#34;_measurement&amp;#34;] == &amp;#34;swap&amp;#34;)
  |&amp;gt; filter(fn: (r) =&amp;gt; r[&amp;#34;_field&amp;#34;] == &amp;#34;usage_system&amp;#34; or r[&amp;#34;_field&amp;#34;] == &amp;#34;free&amp;#34;)
  |&amp;gt; aggregateWindow(every: v.windowPeriod, fn: mean)
  |&amp;gt; yield(name: &amp;#34;mean&amp;#34;)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Into this query to send to InfluxDB, with interval and time period values changing according to the active time selection:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;flux&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-flux&#34;&gt;from(bucket: &amp;#34;grafana&amp;#34;)
  |&amp;gt; range(start: 2020-06-11T13:59:07Z, stop: 2020-06-11T14:59:07Z)
  |&amp;gt; filter(fn: (r) =&amp;gt; r[&amp;#34;_measurement&amp;#34;] == &amp;#34;cpu&amp;#34; or r[&amp;#34;_measurement&amp;#34;] == &amp;#34;swap&amp;#34;)
  |&amp;gt; filter(fn: (r) =&amp;gt; r[&amp;#34;_field&amp;#34;] == &amp;#34;usage_system&amp;#34; or r[&amp;#34;_field&amp;#34;] == &amp;#34;free&amp;#34;)
  |&amp;gt; aggregateWindow(every: 2s, fn: mean)
  |&amp;gt; yield(name: &amp;#34;mean&amp;#34;)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;To view the interpolated version of a query with the query inspector, refer to &lt;a href=&#34;../../../panels-visualizations/panel-inspector/&#34;&gt;Panel Inspector&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;query-logs&#34;&gt;Query logs&lt;/h2&gt;
&lt;p&gt;You can query and display log data from InfluxDB in &lt;a href=&#34;../../../explore/&#34;&gt;Explore&lt;/a&gt; and with the &lt;a href=&#34;../../../panels-visualizations/visualizations/logs/&#34;&gt;Logs panel&lt;/a&gt; for dashboards.&lt;/p&gt;
&lt;p&gt;Select the InfluxDB data source, then enter a query to display your logs.&lt;/p&gt;
&lt;h3 id=&#34;create-log-queries&#34;&gt;Create log queries&lt;/h3&gt;
&lt;p&gt;The Logs Explorer next to the query field, accessed by the &lt;strong&gt;Measurements/Fields&lt;/strong&gt; button, lists measurements and fields.
Choose the desired measurement that contains your log data, then choose which field to use to display the log message.&lt;/p&gt;
&lt;p&gt;Once InfluxDB returns the result, the log panel lists log rows and displays a bar chart, where the x axis represents the time and the y axis represents the frequency/count.&lt;/p&gt;
&lt;h3 id=&#34;filter-search&#34;&gt;Filter search&lt;/h3&gt;
&lt;p&gt;To add a filter, click the plus icon to the right of the &lt;strong&gt;Measurements/Fields&lt;/strong&gt; button, or next to a condition.&lt;/p&gt;
&lt;p&gt;To remove tag filters, click the first select, then choose &lt;strong&gt;&amp;ndash;remove filter&amp;ndash;&lt;/strong&gt;.&lt;/p&gt;
&lt;h2 id=&#34;apply-annotations&#34;&gt;Apply annotations&lt;/h2&gt;
&lt;p&gt;&lt;a href=&#34;../../../dashboards/build-dashboards/annotate-visualizations/&#34;&gt;Annotations&lt;/a&gt; overlay rich event information on top of graphs.
You can add annotation queries in the Dashboard menu&amp;rsquo;s Annotations view.&lt;/p&gt;
&lt;p&gt;For InfluxDB, your query &lt;strong&gt;must&lt;/strong&gt; include &lt;code&gt;WHERE $timeFilter&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;If you select only one column, you don&amp;rsquo;t need to enter anything in the column mapping fields.&lt;/p&gt;
&lt;p&gt;The &lt;strong&gt;Tags&lt;/strong&gt; field&amp;rsquo;s value can be a comma-separated string.&lt;/p&gt;
&lt;h3 id=&#34;annotation-query-example&#34;&gt;Annotation query example&lt;/h3&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT title, description from events WHERE $timeFilter ORDER BY time ASC&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="influxdb-query-editor">InfluxDB query editor&lt;/h1>
&lt;p>This topic explains querying specific to the InfluxDB data source.
For general documentation on querying data sources in Grafana, see &lt;a href="../../../panels-visualizations/query-transform-data/">Query and transform data&lt;/a>.&lt;/p></description></item><item><title>InfluxDB template variables</title><link>https://grafana.com/docs/grafana/v9.3/datasources/influxdb/template-variables/</link><pubDate>Sun, 15 Mar 2026 16:11:32 +0000</pubDate><guid>https://grafana.com/docs/grafana/v9.3/datasources/influxdb/template-variables/</guid><content><![CDATA[&lt;h1 id=&#34;influxdb-template-variables&#34;&gt;InfluxDB template variables&lt;/h1&gt;
&lt;p&gt;Instead of hard-coding details such as server, application, and sensor names in metric queries, you can use variables.
Grafana lists these variables in dropdown select boxes at the top of the dashboard to help you change the data displayed in your dashboard.
Grafana refers to such variables as template variables.&lt;/p&gt;
&lt;p&gt;For an introduction to templating and template variables, refer to the &lt;a href=&#34;../../../dashboards/variables/&#34;&gt;Templating&lt;/a&gt; and &lt;a href=&#34;../../../dashboards/variables/add-template-variables/&#34;&gt;Add and manage variables&lt;/a&gt; documentation.&lt;/p&gt;
&lt;h2 id=&#34;use-query-variables&#34;&gt;Use query variables&lt;/h2&gt;
&lt;p&gt;If you add a query template variable, you can write an InfluxDB exploration (metadata) query.
These queries can return results like measurement names, key names, or key values.&lt;/p&gt;
&lt;p&gt;For more information, refer to &lt;a href=&#34;../../../dashboards/variables/add-template-variables/#add-a-query-variable&#34;&gt;Add query variable&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;For example, to create a variable that contains all values for tag &lt;code&gt;hostname&lt;/code&gt;, specify a query like this in the query variable &lt;strong&gt;Query&lt;/strong&gt;:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SHOW TAG VALUES WITH KEY = &amp;#34;hostname&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;chain-or-nest-variables&#34;&gt;Chain or nest variables&lt;/h3&gt;
&lt;p&gt;You can also create nested variables, sometimes called &lt;a href=&#34;../../../dashboards/variables/add-template-variables/#chained-variables&#34;&gt;chained variables&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;For example, if you had a variable called &lt;code&gt;region&lt;/code&gt;, you could have the &lt;code&gt;hosts&lt;/code&gt; variable show only hosts from the selected region with a query like:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SHOW TAG VALUES WITH KEY = &amp;#34;hostname&amp;#34;  WHERE region = &amp;#39;$region&amp;#39;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;You can fetch key names for a given measurement:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SHOW TAG KEYS [FROM &amp;lt;measurement_name&amp;gt;]&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;If you have a variable with key names, you can use this variable in a group-by clause.
This helps you change group-by using the variable list at the top of the dashboard.&lt;/p&gt;
&lt;h3 id=&#34;use-ad-hoc-filters&#34;&gt;Use ad hoc filters&lt;/h3&gt;
&lt;p&gt;InfluxDB supports the special &lt;strong&gt;Ad hoc filters&lt;/strong&gt; variable type.
You can use this variable type to specify any number of key/value filters, and Grafana applies them automatically to all of your InfluxDB queries.&lt;/p&gt;
&lt;p&gt;For more information, refer to &lt;a href=&#34;../../../dashboards/variables/add-template-variables/#add-ad-hoc-filters&#34;&gt;Add ad hoc filters&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;choose-a-variable-syntax&#34;&gt;Choose a variable syntax&lt;/h2&gt;
&lt;p&gt;The InfluxDB data source supports two variable syntaxes for use in the &lt;strong&gt;Query&lt;/strong&gt; field:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;$&amp;lt;varname&amp;gt;&lt;/code&gt;, which is easier to read and write but does not allow you to use a variable in the middle of a word.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT mean(&amp;#34;value&amp;#34;) FROM &amp;#34;logins&amp;#34; WHERE &amp;#34;hostname&amp;#34; =~ /^$host$/ AND $timeFilter GROUP BY time($__interval), &amp;#34;hostname&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;${varname}&lt;/code&gt;&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT mean(&amp;#34;value&amp;#34;) FROM &amp;#34;logins&amp;#34; WHERE &amp;#34;hostname&amp;#34; =~ /^[[host]]$/ AND $timeFilter GROUP BY time($__interval), &amp;#34;hostname&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;When you enable the &lt;strong&gt;Multi-value&lt;/strong&gt; or &lt;strong&gt;Include all value&lt;/strong&gt; options, Grafana converts the labels from plain text to a regex-compatible string, so you must use &lt;code&gt;=~&lt;/code&gt; instead of &lt;code&gt;=&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&#34;templated-dashboard-example&#34;&gt;Templated dashboard example&lt;/h3&gt;
&lt;p&gt;To view an example templated dashboard, refer to &lt;a href=&#34;https://play.grafana.org/dashboard/db/influxdb-templated&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;InfluxDB Templated Dashboard&lt;/a&gt;.&lt;/p&gt;
]]></content><description>&lt;h1 id="influxdb-template-variables">InfluxDB template variables&lt;/h1>
&lt;p>Instead of hard-coding details such as server, application, and sensor names in metric queries, you can use variables.
Grafana lists these variables in dropdown select boxes at the top of the dashboard to help you change the data displayed in your dashboard.
Grafana refers to such variables as template variables.&lt;/p></description></item></channel></rss>