How to use Flux in Grafana 2023

Hi there,
anyone able to help getting Flux queries working in Grafana? I read through: this thread from 2020 and many other threads out there, but get stuck with error 401:

In InfluxDB script builder, this query for example…

from(bucket: "HomeAssistant/autogen")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "kWh")
  |> filter(fn: (r) => r["entity_id"] == "stromzahler_wohnung")
  |> aggregateWindow(every: v.windowPeriod, fn: last, createEmpty: false)
  |> yield(name: "last")

…seems to work:

So I assume the problem is not on InfluxDB end but somewhere at Grafana or in between :smiley:

My Grafana data source config looks like this:

  • Basic auth user/pw = is my influxDB user (and works with InfluxQL datasources)
  • Org/token = I took from this tip
  • “HomeAssistant/autogen” is the bucket I get from InfluxDB script builder (I tried also variations like only “autogen” or “HomeAssistant”)

Grafana Config:

plugins: []env_vars:  - name: GF_AUTH_ANONYMOUS_ENABLED    value: "true"  - name: GF_AUTH_ANONYMOUS_ORG_NAME    value: Main Org.  - name: GF_AUTH_ANONYMOUS_ORG_ROLE    value: Viewerssl: falsecertfile: fullchain.pemkeyfile: privkey.pem

InfluxDB Config:

auth: truereporting: truessl: falsecertfile: fullchain.pemkeyfile: privkey.pemenvvars: []loglevel: info

What else do I need to do? I don’t know where to access influxdb.conf to add this to http section: “flux-enabled = true” like mentioned in the other thread – if that is even still relevant for my setup.

  • Grafana Current version: 8.2.2
  • InfluxDB Current version: 4.6.0
  • Home Assistant 2023.4.6
    Supervisor 2023.04.1
    Operating System 10.1
    Frontend 20230411.1 - latest

Hi Max,

This got a easier since the 2.x.x versions of InfluxDB, those were instructions for version 1.x. (I assume you have that and 4.6.0 was a typo.)

I see you have access to the web interface of InfluxDB already on port 8086, you can generated a token for your organization there. Described here:

https://docs.influxdata.com/influxdb/v2.6/security/tokens/create-token/

Afterwards paste the org name and token into Grafana’s data source page and it should get it going. Disable basic auth, unless you did some special reverse proxy in front of InfluxDB. The org and token should be what is used for authentication.

Hi @attila_ha thank you!

However I can’t find the InfluxDB CLI or API token page that is mentioned in the docs.
4.6. wasn’t a typo, but the InfluxDB HASS addon version. Not sure, which is the actual InfluxDB version, tbh, the UI reads “Chronograf Version: 1.10.1” at one page in the footer.

Any pointers?

Meanwhile I also tried to set the API to version 1 – with no success… still get the 401

Hmm, sorry, from the screenshot it looked to me that you’re using the default InfluxDB interface, not Chronograf. I am not familiar with using InfluxDB through a HASS addon (I run it separately in docker) so I won’t be able to help.

Hopefully somebody else knows how to access the token creation page of InfluxDB.

EDIT: this must be a very common setup though, check YouTube for a recent howto about it, I bet there is something that walks though the HASS based InfluxDB + Grafana setup.

Thanks for coming back Attilla. Appreciate even if you cannot help.
I’m also surprised, that I can’t find any info. My current setup (HASS OS, Maria db, InfluxDB + Grafana) runs well with InfluxQL – but I can’t get Flux queries working. Confusing…

Hi Max, did you find a solution to your problem? I have exactly the same issue :frowning:

Only the organization field is required, which by default is “defaultorgname”.