Today() function not working in a flux query

I am using the latest Grafana version with influxDB1.8 as a data source and I am trying to do a very simple thing: get the max temperature since the beginning of the day. The measurement that I am using is extremely simple as it contains only one field (temperature)
I type the following flux query in Grafana but it doesn’t work (“NO DATA”) and I can’t figure out why.

from(bucket:"hsohives")
|>range(start: today())
|> filter(fn: (r)=> r._measurement == "scale01temperature")
|> max()

The issue is with today(), which is not accepted but I wonder why.
Thanks for any help

Welcome

What happens if you ran that query in influxdb itself?

That might be the problem. I have installed influxDB with Docker. I only have access to the CLI and it seems that only InfluxQL commands are accepted. I don’t know how to test Flux commands.

That should be accessible on port 8086. Is the grafana also installed in same docker?

Yes, Grafana is on the same docker.
I access InfluxDB CLI through portainer, by clicking on the > icon.
http://localhost:8086 doesn’t allow to access influxDB, which is the way it should be if I understand well.

yes by default it is 8086. is that port exposed for external access?

Hi @h23,

I think you need to use the container IP address instead of localhost to access it on port 8086

For e.g.

I use docker on my VM and if my VM has an IP of 192.168.122.139

Then to use any deployed container I always use smth like

192.168.122.139:3306 #for grafana
192.168.122.139:8086 #for influxdb
192.168.122.139:9000 #for prometheus

etc.

Do that and then follow the steps as @yosiasz suggests i.e. to run the that query inside influxdb

1 Like

Thanks much for your help. As you might understand I am not an expert…
My raspberry is on 192.168.1.58
My Docker-compose file (influxDB portion) is as follows:

influxdb:
    container_name: influxdb
    image: "influxdb:1.8"
    restart: unless-stopped
    ports:
    - "8086:8086"
    environment:
    - TZ=Etc/UTC
    - INFLUXDB_HTTP_FLUX_ENABLED=true
    - INFLUXDB_REPORTING_DISABLED=false
    - INFLUXDB_HTTP_AUTH_ENABLED=false
    - INFLUXDB_MONITOR_STORE_ENABLED=FALSE
    volumes:
    - /media/pi/PI4HOME_HDD/influxdb/data:/var/lib/influxdb
    - /media/pi/PI4HOME_HDD/influxdb/backup/db:/var/lib/influxdb/backup
    healthcheck:
      test: ["CMD", "curl", "http://localhost:8086"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 30s

localhost:8086 is not accessible and I am not sure what the container IP address is.
Thanks again

Thanks @h23

Can you please paste your complete docker-compose file or the above is your complete file?

Thanks for your help.
Here is the complete docker-compose file. It seems that when InfluxDB is installed with docker, the UI is InfluxQL only, even if Flux is enabled. When Flux is enabled, some (most ?) Flux commands work in Grafana but not today().

version: '3.6'

networks:
  default:
    driver: bridge
    ipam:
      driver: default
  nextcloud:
    driver: bridge
    internal: true
    ipam:
      driver: default

services:
  duckdns:
    container_name: duckdns
    build: https://github.com/ukkopahis/docker-duckdns.git
    network_mode: host
    restart: unless-stopped
    environment:
      PUID: 1000
      PGID: 1000
      # Required variables, define here on in docker-compose.override.yml
      TOKEN: 0bd9fcbd-fba1-42d5-bf6f-5fce796cecbf
      SUBDOMAINS: hsors01
      # Optional
      #PRIVATE_SUBDOMAINS: your domain added to duckdns.org (without .duckdns.org)
  grafana:
    container_name: grafana
    image: grafana/grafana
    restart: unless-stopped
    user: "0"
    ports:
    - "3000:3000"
    environment:
    - TZ=Etc/UTC
    - GF_PATHS_DATA=/var/lib/grafana
    - GF_PATHS_LOGS=/var/log/grafana
    volumes:
    - /media/pi/PI4HOME_HDD/grafana/data:/var/lib/grafana
    - ./volumes/grafana/log:/var/log/grafana
    healthcheck:
      test: ["CMD", "wget", "-O", "/dev/null", "http://grafana.staged-by-discourse.com"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 30s

  influxdb:
    container_name: influxdb
    image: "influxdb:1.8"
    restart: unless-stopped
    ports:
    - "8086:8086"
    environment:
    - TZ=Etc/UTC
    - INFLUXDB_HTTP_FLUX_ENABLED=true
    - INFLUXDB_REPORTING_DISABLED=false
    - INFLUXDB_HTTP_AUTH_ENABLED=false
    - INFLUXDB_MONITOR_STORE_ENABLED=FALSE
  # - INFLUX_USERNAME=dba
  # - INFLUX_PASSWORD=supremo
  # - INFLUXDB_UDP_ENABLED=false
  # - INFLUXDB_UDP_BIND_ADDRESS=0.0.0.0:8086
  # - INFLUXDB_UDP_DATABASE=udp
    volumes:
    - /media/pi/PI4HOME_HDD/influxdb/data:/var/lib/influxdb
    - /media/pi/PI4HOME_HDD/influxdb/backup/db:/var/lib/influxdb/backup
    healthcheck:
      test: ["CMD", "curl", "http://localhost:8086"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 30s

  nodered:
    container_name: nodered
    build:
      context: ./services/nodered/.
      args:
      - DOCKERHUB_TAG=latest
      - EXTRA_PACKAGES=
    restart: unless-stopped
    user: "0"
    environment:
    - TZ=Etc/UTC
    ports:
    - "1880:1880"
    volumes:
    - /media/pi/PI4HOME_HDD/nodered/data:/data
    - ./volumes/nodered/ssh:/root/.ssh
    - /var/run/docker.sock:/var/run/docker.sock
    - /var/run/dbus/system_bus_socket:/var/run/dbus/system_bus_socket
    devices:
    - "/dev/ttyAMA0:/dev/ttyAMA0"
    - "/dev/vcio:/dev/vcio"
    - "/dev/gpiomem:/dev/gpiomem"

  portainer-ce:
    container_name: portainer-ce
    image: portainer/portainer-ce
    restart: unless-stopped
    ports:
    - "8000:8000"
    - "9000:9000"
    volumes:
    - /var/run/docker.sock:/var/run/docker.sock
    - ./volumes/portainer-ce/data:/data

  portainer_agent:
    image: portainer/agent
    container_name: portainer-agent
    ports:
    - "9001:9001"
    volumes:
    - /var/run/docker.sock:/var/run/docker.sock
    - /var/lib/docker/volumes:/var/lib/docker/volumes
    restart: unless-stopped

Hi @h23,

I am getting this error for the duckdns part as I do not know why it is not working.

[+] Building 0.0s (1/1) FINISHED                                                                                                                                                                                   
 => ERROR [root_duckdns internal] load git source https://github.com/ukkopahis/docker-duckdns.git                                                                                                             1.9s
------
 > [root_duckdns internal] load git source https://github.com/ukkopahis/docker-duckdns.git:
------
failed to solve: rpc error: code = Unknown desc = failed to solve with frontend dockerfile.v0: failed to read dockerfile: failed to load cache key: failed to fetch remote https://github.com/ukkopahis/docker-duckdns.git: signal: terminated

Maybe you know how to resolve it as without it I cannot proceed further OR if ok can comment out the DuckDNS part in docker-file?

OK, found the reason after commenting out DuckDNS, NodeRED as why you cannot access the InfluxDB via port 8086

The answer is here

So use chronograf (or like I used in the past telegraf agent to collect data) or search for some tutorial which explains in more detail as how to use Grafana/InfluxDBv1 with any other tools as a whole stack correctly with more detailed configuration settings.

I hope this helps.

1 Like

Thanks much usmanahmad, I appreciate your help and will try.
Another option is to upgrade to influxDB2 where the UI is integrated.

Yes, you can use InfluxDB ver2 but keep in mind that if you have previous data which was on ver 1 then you need to ask their support as how to migrate it. Because v1 save it in a database while v2 use the concept of Buckets (which is also v.new for me).

If there is no data then feel free to play around with InfluxDB v2 :sunglasses:

In order to manage my docker containers, I am using a utility called IOTstack from from Graham Garner (not completely sure about the name) which is very convenient for me. InfluxDB2 container is included and there is

a complete procedure for migrating the data here.