Setting up InfluxDB and Grafana using Docker


#1

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.

  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.

  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:


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

#2

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


#3

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


#4

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


split this topic #5

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