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:- InfluxQL
- Flux
- SQL
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-43Connection Settings
Configure URL
Set the InfluxDB server URL:InfluxDB 1.x (InfluxQL):InfluxDB 2.x (Flux):InfluxDB 3.x (SQL):
Authentication
InfluxQL (1.x):
- Enable Basic Auth
- Set username and password
- Set organization name
- Provide API token in secure settings
Data Source Options
Query language:
InfluxQL, Flux, or SQLInfluxQL only: Database name
Flux/SQL only: Organization name
Flux/SQL only: Default bucket for queries
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-158InfluxQL Query Language
Basic Queries
Select data from a measurement:Aggregations
Mean:Group By Tags
Group by tag values:Sub-queries
Macros
Grafana provides InfluxQL macros:$timeFilter: Expands totime >= <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:Group By
Group by tags:Transformations
Map:Flux Variables
Grafana provides Flux variables:v.timeRangeStart: Dashboard start timev.timeRangeStop: Dashboard stop timev.windowPeriod: Auto-calculated window periodv.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)
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:Flux Variables
Get tag values:SQL Variables (InfluxDB 3.x)
Get distinct values:Using Variables in Queries
InfluxQL: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:- Text Column: Field containing annotation text
- Tags Column: Field containing comma-separated tags
Troubleshooting
No data returned
No data returned
- 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
Authentication failed
Authentication failed
- 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
Query timeout
Query timeout
- Reduce time range
- Add more tag filters
- Lower
maxSeriessetting - Use continuous queries for pre-aggregation
- Increase query timeout in InfluxDB config
Too many series
Too many series
- Lower
maxSeriesin data source settings - Add tag filters to reduce cardinality
- Use more specific measurement names
- Review tag cardinality:
SHOW TAG CARDINALITY
Best Practices
- Choose the right query language: Use InfluxQL for 1.x, Flux for 2.x, SQL for 3.x
- Use tag filters: Always filter by tags before field operations
- Configure retention policies: Set appropriate data retention for your use case
- **Avoid SELECT ***: Query only needed fields
- Use continuous queries: Pre-aggregate data for common queries
- Monitor cardinality: Keep tag cardinality low (< 100k series per measurement)
- Leverage macros/variables: Use Grafana’s built-in time variables