Skip to main content

InfluxDB Data Source

InfluxDB is a time series database optimized for high-write and query loads. Grafana supports querying InfluxDB using three query languages: InfluxQL (1.x), Flux (2.x and 1.8+), and SQL (3.x).

Overview

The InfluxDB data source provides:
  • Support for InfluxQL, Flux, and SQL query languages
  • Time series visualization and aggregation
  • Retention policy and bucket management
  • Template variables from InfluxDB data
  • Annotation support
Source: public/app/plugins/datasource/influxdb/

Configuration

Query Language Selection

First, select your query language based on your InfluxDB version:
For InfluxDB 1.xSQL-like query language for InfluxDB 1.x:
  • Familiar SQL-style syntax
  • Database and retention policy support
  • Continuous queries and retention policies
Source: public/app/plugins/datasource/influxdb/components/editor/config/ConfigEditor.tsx:21-43

Connection Settings

1

Add Data Source

Navigate to Configuration > Data Sources > Add data source > InfluxDB
2

Select Query Language

Choose InfluxQL, Flux, or SQL based on your InfluxDB version
3

Configure URL

Set the InfluxDB server URL:InfluxDB 1.x (InfluxQL):
InfluxDB 2.x (Flux):
InfluxDB 3.x (SQL):
4

Authentication

InfluxQL (1.x):
  • Enable Basic Auth
  • Set username and password
Flux (2.x) / SQL (3.x):
  • Set organization name
  • Provide API token in secure settings
5

Database/Bucket Settings

InfluxQL:
  • Database: telegraf
  • Retention Policy: autogen (optional)
Flux/SQL:
  • Default Bucket: my-bucket

Data Source Options

string
required
Query language: InfluxQL, Flux, or SQL
string
InfluxQL only: Database name
string
Flux/SQL only: Organization name
string
Flux/SQL only: Default bucket for queries
number
default:"1000"
Limit the number of series/tables processed. Prevents performance issues with high-cardinality data.
Source: public/app/plugins/datasource/influxdb/components/editor/config/ConfigEditor.tsx:141-158

InfluxQL Query Language

Basic Queries

Select data from a measurement:

Aggregations

Mean:
Multiple aggregations:

Group By Tags

Group by tag values:

Sub-queries

Macros

Grafana provides InfluxQL macros:
  • $timeFilter: Expands to time >= <start> AND time <= <end>
  • $__interval: Auto-calculated time interval
  • $__interval_ms: Interval in milliseconds

Flux Query Language

Basic Queries

Query data from a bucket:

Aggregations

Mean:
Custom aggregation:

Group By

Group by tags:

Transformations

Map:
Join:

Flux Variables

Grafana provides Flux variables:
  • v.timeRangeStart: Dashboard start time
  • v.timeRangeStop: Dashboard stop time
  • v.windowPeriod: Auto-calculated window period
  • v.defaultBucket: Configured default bucket

SQL Query Language (InfluxDB 3.x)

Basic Queries

Select from a measurement:

Aggregations

Group By

Window Functions

Query Editor

Visual Query Builder (InfluxQL)

1

Select Measurement

Choose measurement from dropdown (e.g., cpu)
2

Add Tag Filters

Filter by tag values:
  • Tag: host
  • Operator: =
  • Value: server-01
3

Select Fields

Choose fields to query:
  • usage_idle
  • usage_system
4

Add Aggregation

Select aggregation function:
  • mean()
  • max()
  • sum()
5

Group By

Add grouping:
  • time($__interval)
  • Tag: host

Code Editor

Switch to code mode for advanced queries:
  • Full query language support
  • Syntax highlighting
  • Query validation
  • Variable substitution preview

Template Variables

InfluxQL Variables

Show tag values:
Show tag values with condition:
Show measurements:
Show field keys:

Flux Variables

Get tag values:
Get measurements:

SQL Variables (InfluxDB 3.x)

Get distinct values:
Get values with filter:

Using Variables in Queries

InfluxQL:
Flux:
SQL:

Performance Optimization

Use Retention Policies

Configure appropriate retention policies to reduce data volume:

Limit Series

Set maxSeries to prevent high-cardinality issues:

Use Downsampling

Query pre-aggregated data from continuous queries:

Add Tag Filters

Always filter by tags to reduce query scope:

Annotations

Create annotations from InfluxDB data: InfluxQL:
Flux:
Configure:
  • Text Column: Field containing annotation text
  • Tags Column: Field containing comma-separated tags

Troubleshooting

  • Verify database/bucket name is correct
  • Check retention policy (InfluxQL) or bucket retention (Flux/SQL)
  • Confirm time range includes data points
  • Test query in InfluxDB CLI or UI
  • Review time field format and timezone
  • InfluxQL: Verify username/password in Basic Auth
  • Flux/SQL: Check API token has correct permissions
  • Confirm organization name is correct (Flux/SQL)
  • Review InfluxDB user permissions
  • Reduce time range
  • Add more tag filters
  • Lower maxSeries setting
  • Use continuous queries for pre-aggregation
  • Increase query timeout in InfluxDB config
  • Lower maxSeries in data source settings
  • Add tag filters to reduce cardinality
  • Use more specific measurement names
  • Review tag cardinality: SHOW TAG CARDINALITY

Best Practices

  1. Choose the right query language: Use InfluxQL for 1.x, Flux for 2.x, SQL for 3.x
  2. Use tag filters: Always filter by tags before field operations
  3. Configure retention policies: Set appropriate data retention for your use case
  4. **Avoid SELECT ***: Query only needed fields
  5. Use continuous queries: Pre-aggregate data for common queries
  6. Monitor cardinality: Keep tag cardinality low (< 100k series per measurement)
  7. Leverage macros/variables: Use Grafana’s built-in time variables

Further Reading