Using Flux from Grafana



After Getting started with Flux, you might be asking how to finally use it from Grafana?

Grafana datasource plugin for Flux (InfluxDB)


Use this datasource if you want to use Flux to query your InfluxDB. Feel free to run this datasource side-by-side with the non-Flux datasource. If you point both datasources to the same InfluxDB instance, you can switch query mode by switching the datasources.

State of the onion

While we already assumed to require the »Grafana datasource plugin for Flux (InfluxDB)«, there are currently two versions around:

We should use the most recent one. However, there is another commit Updated db: to bucket: to support new changes in Flux · grafana/influxdb-flux-datasource@ac49cf7 · GitHub sitting in the branch “bucket-updates” which most notably includes the switchover regarding addressing databases from within a Flux expression. Flux switched from

  • from(db: "${database}")


  • from(bucket: "${database}")

So, databases will be called buckets now. That’s ok.



curl -sS | sudo apt-key add -
echo "deb stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
apt update
apt install yarn

How to install Yarn on Debian 9 | Linuxize


git clone /opt/grafana-influxdb-flux-datasource

cd /opt/grafana-influxdb-flux-datasource
yarn install
yarn dev


Note: Please make sure you uninstalled the GA release from the Grafana Plugin Repository by using e.g.

grafana-cli plugins uninstall grafana-influxdb-flux-datasource

Then, link the DEV release into the Grafana plugin directory:

ln -s /opt/grafana-influxdb-flux-datasource /var/lib/grafana/plugins/
systemctl restart grafana-server



Panel metrics


Please note there’s no need to configure a default database (so we used "null" there), as the database (bucket) is addressed from within the Flux query expression anyway. Thus, there will be probably no need to configure a different Grafana data source for each InfluxDB database - every query can be run through the canonical one, right?

Important note about Flux (again)

Flux requires a time range when querying time series data. “Unbounded” queries are very resource-intensive and as a protective measure, Flux will not query the database without a specified range.

Query InfluxDB with Flux | InfluxData Documentation

When sending an “unbounded” query to InfluxDB through Flux, like from(bucket:"hiveeyes_open_hive_clemens") without the range($range) part, it will respond appropriately:

Failed to create physical plan: result 'from0' is unbounded. 
Add a 'range' call to bound the query,

Getting started with Flux

Data sources

Data sources for submitting Flux query expressions through Grafana have been added to both InfluxDB instances:


Example dashboard

[amo] Open Hive Clemens with Flux is an example dashboard which already uses Flux to query beekeeping data.