Setting up InfluxDB and Grafana using Docker

Home Assistant collects volumes of (time series) data that are well suited for some fancy graphs. Although the History component provides some nice plots, I am sure you have always wanted those fancy Grafana plots. The problem, however, is that low-powered device such as Raspberry Pi that most of us use for our Home Assistant setup are not well suited for such operation.

Instead of running InfluxDB and Grafana on a Raspberry Pi or a different system and go through the classic approach of installing both tools separately, you can run them in a Docker container on another machine. For this tutorial, I am using a Synology NAS, but the instructions should apply to other devices that can run Docker. Just follow the steps below:

  1. SSH into your NAS. You may have to run sudo su if you are getting permission errors.
  2. Download the docker-statsd-influxdb-grafana image using the command: docker pull samuelebistoletti/docker-statsd-influxdb-grafana
  3. To start the container for the first-time launch:
    docker run -d \
      --name docker-statsd-influxdb-grafana \
      -p 3003:3003 \
      -p 3004:8083 \
      -p 8086:8086 \
      -p 22022:22 \
      -p 8125:8125/udp \
      samuelebistoletti/docker-statsd-influxdb-grafana:latest
    
  4. The image should now be running and both InfluxBD and Grafana should be now up and running.
  5. You can access InfluxDB at http://NAS_IP_ADDRESS:3004/ and Grafana at http://NAS_IP_ADDRESS:3003/
  6. Navigate to http://NAS_IP_ADDRESS:3004/ and create the database home_assistant using the command CREATE DATABASE home_assistant.

    ![](upload://ei0nI97loIS3LJQdaAWxW0mIN7U.png)

  7. Now, you need to configure Home Assistant to use InfluxDB. Since, we did not add any username/password to our database, we can simply add the following to our configuration.yaml (replace the IP address with that of the device running Docker) and restart Home Assistant to setup InfluxDB (you will have to fine tune it based on your preferences):
    influxdb:
      host: 192.168.2.113
    
  8. Next, we need to configure Grafana to use InfluxDB. Navigate to http://NAS_IP_ADDRESS:3003/ to access Grafana (login with username and password root) and add your first data source. Here’s how you can configure Grafana to use InfluxDB database. Note that 192.168.2.113 is the IP address of my NAS.

    ![](upload://3baq8j1cq85yPa4nQ6niP7M3LOs.png)

  9. You should see Data source is working if you have configured everything correctly.
  10. With all that configured, you are now ready for the fun stuff. You can create as many dashboards as you want and then import the same in Home Assistant.
  11. To add the Grafana dashboard in HA, use the following config:
    panel_iframe:
      router:
        title: 'Temperature'
        url: 'http://192.168.2.113:3003/dashboard/db/temperature?edit&tab=time%20range'
    

    The URL can be obtained by clicking Share Dashboard link on your dashboard:

    ![](upload://fUjS0wGLgKiEC2XYdjIKnj8sfAH.png)


This is a companion discussion topic for the original entry at https://home-assistant.io/blog/2017/04/25/influxdb-grafana-docker/
4 Likes

Thanks for this guide but I’m stuck at step 8. There’s no option for me to edit data sources. I’m currently running MySQL for the back-end under the database name ‘homeassistant’ and I suspect that might be the culprit. I can’t figure out how to re-create schema as ‘home_assistant’ in InfluxDB because the InfluxDB UI doesn’t let me create tables. And I can’t figure out how to run the db migration script discussed in the component configuration because I can’t run ‘hass’ from the command line (command not found and grep-ing for ‘hass’ doesn’t turn up anything useful).

grafana_screenshot

outdated article, container should be start with

docker run --ulimit nofile=66000:66000 \
  -d \
  --name docker-statsd-influxdb-grafana \
  -p 3003:3003 \
  -p 3004:8888 \
  -p 8086:8086 \
  -p 22022:22 \
  -p 8125:8125/udp \
  samuelebistoletti/docker-statsd-influxdb-grafana:latest

and database creation and linking grafana to influxDB is not needed, it is already done

3 Likes

Hi and thanks for sharing.

I have two virtual machine on ESXi, one with Hassio and another one with Nodered and some other stuff in Docker.

For both VM I already have SSH and have Portainer to manage them.

Do I need to open port -p 22022:22 \ since it’s already opened?

Can I remove it from the start?

Since I was having issues with other container, like Nodered, I added --network host --user 0 to the container start.

Can/should I add these also here?

Thanks

A post was split to a new topic: What data do you collect and display with InfluxDB + Grafana?

As searches for grafana + HA mostly ends up here, it should be noted that https://grafana.com/docs/installation/configuration/#allow-embedding should be set to “true” in grafana, so that it allows embedding in a iFrame, or nothing will be shown.

More note: (I guess this post was based on an older grafana. I use 6.3.6 on rpi4)

  • Do the “share” on the panel level, not the dashboard one
  • There is now a specific “embed” tab. Use that url.
  • Be sure to disable “current time range”, or your graph will be stuck in time
  • Add “&kiosk=tv” to the url to remove menus

Display:

1 Like

FYI – Trying to get Grafana “Latest” (6.4.x) in Docker is failing with “No such file or directory.”

I was able to get back up specifying an older build (image: grafana/grafana:6.3.6)

Known issue…It will likely be fixed before you find this thread…but it sure bothered me for a while. You can track the issue here:
Docker: ARM images doesn’t work since v6.4.x #19585

Thank you @dixkom
we should update the article above. I almost was going to try with another docker image because the influxdb port wasnt working anymore.

I use this approach with the Grafana addon, but if I don’t visit the Grafana UI for a while I get a 401 error on all my embedded graphs. Is there any way to prevent this from happening?

Thomas

If you mean that you are dis-authorized, no, I didn’t found a way to prevent this.
But I get Grafana’s login screen, then, not a plain 401.

hi, was able to setup this docker also with latest instructions from the author in his github, only thing I don’t know where to find grafana.ini to set auth enable in rder to have iframe working in HA, can someone explain me how to find grafana.ini file inside the docker or create a new one and make it working? Thank you.

If you’re doing this in docker, you have to set the environment variable -e. I am using Docker Compose, so i had to structure it like this:

grafana:
    container_name: grafana
    ports:
      - '3000:3000'
    environment:
      - GF_SECURITY_ALLOW_EMBEDDING=true
    image: 'grafana/grafana:7.0.3-ubuntu'
1 Like

My HA is running in a virtual machine within unRaid.

I followed this guide, well more or less: I could not get the InfluxDB docker on my unRaid to start up, so using the InfluxDB addon in HA and Grafana in unRaid and everything is connected and I am able to access Home Assistant and Glances DB I created on Influx in HA.

I created dashboards in Grafana and changed the GF_SECURITY_ALLOW_EMBEDDING=true,
Here is my docker compse for Grafana;

version: '3.3'
services:
    grafana:
        container_name: Grafana
        network_mode: bridge
        environment:
            - TZ=America/Chicago
            - HOST_OS=Unraid
            - 'GF_SERVER_ROOT_URL=http://<unRaid server IP>'
            - GF_SECURITY_ADMIN_PASSWORD=admin
            - GF_SECURITY_ALLOW_EMBEDDING=true
        ports:
            - '3000:3000/tcp'
        volumes:
            - '/mnt/user/appdata/grafana:/var/lib/grafana:rw'
        image: grafana/grafana

added an iframe to lovelace but get the below error:

**If you're seeing this Grafana has failed to load its application files**
1. This could be caused by your reverse proxy settings.
2. If you host grafana under subpath make sure your grafana.ini root_url setting includes subpath. If not using a reverse proxy make sure to set serve_from_sub_path to true.
3. If you have a local dev build make sure you build frontend using: yarn start, yarn start:hot, or yarn build
4. Sometimes restarting grafana-server can help

Some googling and looking at Grafana config documentation tells me that it is something to do with my grafana server settings, below. But i’m not sure what to change.

|server||
|domain | localhost|
|enable_gzip | false|
|enforce_domain | false|
|http_addr | 0.0.0.0|
|http_port | 3000|
|protocol | http|
|root_url | http://unRaid IP |
|router_logging | false|
|serve_from_sub_path | false|
|socket | /tmp/grafana.sock|
|static_root_path | public|

All help is welcome.
Thanks.

Exact same problem for me here, if anyone have been able to solve the issue…

It was a little while ago, but pretty sure I had the same problem until I sorted out the reverse proxy (nginx). I’m running HA in a docker, and am using the linuxserver/swag container (previously called linuxserver/letsencrypt) for duckdns/reverse proxy/etc so my nginx directory structure maybe different from yours, but for me I edited the file letsencrypt/nginx/site-confs/default and added this:

### Grafana
server {
        listen 443 ssl;

        root /config/www;
        index index.html index.htm index.php;

        server_name grafana.yourduckdnshostname.duckdns.org;

        include /config/nginx/ssl.conf;

        client_max_body_size 0;

        location / {
                include /config/nginx/proxy.conf;
                proxy_pass http://192.168.1.9:3000;
        }
}

and then restarted the swag container.

The missing part of the puzzle for me is being able to view the panel iframes in HA over https.
Currently these are not visible to remote connections, including the HA companion app.
Only visible locally.

My limited understanding is that this is because the Grafana URLs are http, rather than https.

Achieving this is currently beyond me, but if anyone can provide guidance it would be appreciated. In the meantime I continue to research a possible solution for my Docker installation.

Somehow my password changed ( for the second time). Anyone who can help me ?
I logged in with putty to root and then used this code : docker exec -ti <container_name> grafana-cli admin reset-admin-password mypass@123 . I get the message that my admin pass is changed, but I cant log in with it …

Unable to login to grafana using admin/admin in the point 8. I found on github that people were dealing with this problem but without solution working for me. Any ideas? Thanks

ok, so I finally installed addon grafana and connected to the influxdb in the docker on my Synology NAS. What is actually the benefit of running grafana in Docker (when its filled with these bugs not letting you even reset admin password using grafana cli)? I guess all data will be in the influxdb, so my backups will again be below 1MB instead of 1.5GB

Hi guys, i also did setup a big while ago influxDB and grafana on my proxmox, however it still works great, but here is the thing i don’t even understand anymore…

So before my real life accident i did set this all up, after losing memory for some time and still recovering i’m trying to find out how influxDB is getting the data from home assistant…

As in Home Assistant is no addon even installed, and in InfluxDb the only thing i use is a bucket, but i can’t find out how it receives the realtime data…

I did check everything, i can not find it out…
It still gets the data every 5 seconds from my Home Assistant server in the bucket of InfluxDB… and i can read the data in Grafana…
In grafana the server url from influxDB is the one using the bucket, and nothing else…

Regards