As I do play around with environment sensors, based on TinkerForge components Arduino and LoRaWAN, I need to be able to store the data and also expose the it in some interesting way. InfluxDB is perfect for storing time based measurements, also it does not really requires too much Database Management knowledge. Which makes it a good choice for home automation projects as you can focus on functionality and not on Database Management. I also need a way to expose and present the data in a good way and Grafana is a good solution. You might have noticed, I use Open Source all over the place. I just like it and there is so much out there, huge communities, people working together, building stuff and everybody can join and help projects grow.
I did notice that using a Raspberry Pi and fetch data, transform it, store it and expose it can have an impact on your SD-card of your Pi. For that reason I mainly use my Rapsberry Pi to prototype my setup, but my “production” environment is an Intel NUC with 8GB memory, 8 GB memory, internal SSD and USB-3 SSD Drive. This delivers more stability and, more important for me, more performance. But back to the subject of this post.
Influxdb install
Running InfluxDB on Ubuntu 20.04. First we need to add the influx repository and import the GPG key so we can use apt to install and upgrade InfluxDB.
$ echo "deb https://repos.influxdata.com/ubuntu bionic stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
$ sudo curl -sL https://repos.influxdata.com/influxdb.key | sudo apt-key add -
Now we are ready to update the apt index and install InfluxDB on our Raspberry Pi.
$ sudo apt-get update
$ sudo apt-get install influxdb

As I want the database server to run when I reboot my Raspberry PI so I will need to start and enable the services.
$ sudo systemctl enable --now influxdb
And check if all works correct
$ systemctl status influxdb
● influxdb.service - InfluxDB is an open-source, distributed, time series database
Loaded: loaded (/lib/systemd/system/influxdb.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2020-05-09 12:42:12 UTC; 1min 49s ago
Docs: https://docs.influxdata.com/influxdb/
Main PID: 24237 (influxd)
Tasks: 14 (limit: 1039)
CGroup: /system.slice/influxdb.service
└─24237 /usr/bin/influxd -config /etc/influxdb/influxdb.conf
May 09 12:42:12 ubuntu influxd[24237]: ts=2020-05-09T12:42:12.538561Z lvl=info msg="Starting precreation service" log_id=0MfN9vGl00>
May 09 12:42:12 ubuntu influxd[24237]: ts=2020-05-09T12:42:12.538666Z lvl=info msg="Starting snapshot service" log_id=0MfN9vGl000 s>
May 09 12:42:12 ubuntu influxd[24237]: ts=2020-05-09T12:42:12.538758Z lvl=info msg="Starting continuous query service" log_id=0MfN9>
May 09 12:42:12 ubuntu influxd[24237]: ts=2020-05-09T12:42:12.538896Z lvl=info msg="Starting HTTP service" log_id=0MfN9vGl000 servi>
May 09 12:42:12 ubuntu influxd[24237]: ts=2020-05-09T12:42:12.538959Z lvl=info msg="opened HTTP access log" log_id=0MfN9vGl000 serv>
May 09 12:42:12 ubuntu influxd[24237]: ts=2020-05-09T12:42:12.538797Z lvl=info msg="Storing statistics" log_id=0MfN9vGl000 service=>
May 09 12:42:12 ubuntu influxd[24237]: ts=2020-05-09T12:42:12.539780Z lvl=info msg="Listening on HTTP" log_id=0MfN9vGl000 service=h>
May 09 12:42:12 ubuntu influxd[24237]: ts=2020-05-09T12:42:12.539964Z lvl=info msg="Starting retention policy enforcement service" >
May 09 12:42:12 ubuntu influxd[24237]: ts=2020-05-09T12:42:12.540701Z lvl=info msg="Listening for signals" log_id=0MfN9vGl000
May 09 12:42:12 ubuntu influxd[24237]: ts=2020-05-09T12:42:12.541562Z lvl=info msg="Sending usage statistics to usage.influxdata.co>
And I am now also able to run influxdb commands from the command line. It is very simple, just run the command ” influx” and you are in.
$ influx
Connected to http://localhost:8086 version 1.8.0
InfluxDB shell version: 1.8.0
> _
I have not setup any security, so I am able to get to the CLI very easy. This very basic setup should only be used for your own testing and development. If you do want to run it in a more production like environment, possible exposed to the internet, make sure you setup you firewall on Ubuntu and InfluxDB authentication. Things I will touch in future post.
GRAFANA INSTALL
We have a few options to install Grafana, for me the only options I consider are using the official apt repository or installing the .deb package which can be downloaded from Grafana. For this post I will be using the apt repository, first make sure the systems is up to date, add the Grafana repository and install it.
$ sudo apt update
$ sudo apt upgrade
Install the Grafana key so I can install the signed packages.
$ curl https://packages.grafana.com/gpg.key | sudo apt-key add -
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1694 100 1694 0 0 9359 0 --:--:-- --:--:-- --:--:-- 9359
OK
And finally install the Grafana apt repository.
$ sudo add-apt-repository "deb https://packages.grafana.com/oss/deb stable main"

Now I have added the Grafana apt repository and I can update the apt repositories and install Grafana.
$ sudo apt-get update
$ sudo apt-get -y install grafana

And as with InfluxDB I want Grafana to run after a reboot using systemd, I run the following commands, these commands are also shown during the Grafana installation process.
$ sudo systemctl daemon-reload
$ sudo systemctl enable grafana-server
$ sudo systemctl start grafana-server
And check Grafana is indeed active by checking the status of the services.
$ systemctl status grafana-server.service
Or you could also do a quick check using the ps command.
$ ps -ef | grep grafana
grafana 27320 1 25 19:32 ? 00:00:01 /usr/sbin/grafana-server --config=/etc/grafana/grafana.ini --pidfile=/var/run/grafana/grafana-server.pid --packaging=deb cfg:default.paths.logs=/var/log/grafana cfg:default.paths.data=/var/lib/grafana cfg:default.paths.plugins=/var/lib/grafana/plugins cfg:default.paths.provisioning=/etc/grafana/provisioning
ubuntu 27331 24705 0 19:32 pts/0 00:00:00 grep --color=auto grafana
And the final test, open you favorite browser and go to; http://192.168.2.190:3000. Make sure to replace the IP-address with the IP-address of your own Ubuntu Server.

Login using the default username : admin and password : admin. Grafana will request you to change the password for the admin account. Change the admin password and the Grafana Welcome screen will appear.

And Grafana is ready for adding your data-source and create dashboards like my home environment dashboard.

I have not setup the firewall on Ubuntu, if you did you will need to allow traffic on port 3000 for Grafana. How to do that I will show you in a next post.