Some time ago I wrote a blog entry about garden sensors inside of which was buried some information about using Grafana and InfluxDB. At the time the install was not that easy – and when along came STRETCH for the Raspberry Pi (2 and 3) it got worse.
However, reader Antonio and I have been working on this and we have an install for the latest Grafana with Influx.
But firstly let’s discuss what this is all about. Back in the dim and distant past, people were happy with simply line graphs and horrible fonts to display data until along came a number of services to produce pretty information which was easy to generate. There are many such services where you can send your Raspberry Pi or simply data, which may be from a variety of sources to a service – sometimes free, sometimes not – to log and display your data.
I’ve never been that happy with this though I did write a node to work with one of the providers – but I’ve always preferred the idea of keeping the data locally. I worked originally with MYSQL and various graphing packages that ran on Debian but there was never a simple to use system until Grafana came by.
Grafana can work with a variety of databases – but works well alongside InfluxDB. I’m not saying InfluxDB is great – but it DOES make life easy when working with Grafana because it uses Time Series data – in which all you send is a data series name – and a current value – that’s it… the rest is done in the background. You don’t need to worry about time and creating records or tables etc.
For Node-Red there is a node in which you simply send two items – msg.payload – which is the value you want to graph – and msg.measurement which is the name of the series. I usually use a function to copy the more familiar msg.topic into msg.measurement – that makes life even easier as you can send incoming MQTT data straight to the database for use by Grafana.
So having introduced the subject – what does Grafana look like in action? It runs from any modern browser – I use Chrome – and looks like this.
Well, that’s what my setup looks like – yours may end up looking completely different. A key point here is the ease of adding data. As new points are added for previously unused sets – they just become available in Grafana for you to use, via drop-down menus.
Now, while Antonio and I have managed to get this running on Stretch for the Pi2 and Pi3 I (after updating "the script" to work with Stretch) - would love to hear details of working up to date (i.e. version 4.4 or better Grafana) running on the likes of Orange Pi Zero, NanoPi Neo, M3 etc… that would be nice. A quick look at Xenial suggests they’re still on version 2.6 !!
Once the setup is up and running – you need to create a database. InfluxDB used to have a web interface for this but it seems they’ve binned it – there is a command line interface however and all you actually need it for is creating the database – along the lines of (from the command line - I used user PI)
create database “logger”
I called my database logger for no real reason.
You can also create a “user” in this interface – but it won’t be needed unless you enable password authorisation (see later on)
CREATE USER admin WITH PASSWORD '<password>' WITH ALL PRIVILEGES
Once that’s done – in Grafana itself – you add the database logger and create a new blank dashboard – and from there it is a simple matter to add graphs etc. using the data. In Node-Red there’s a node called InfluxDB and I’ve described above how to use that. With that Node-Red installation are other useful nodes including a batch node. I’ll leave it to the reader to investigate further.
Here is our first attempt at making the Pi2/3-with-stretch installation simple – this does not include creating the database (though it could) or adding any security. By default anyone can create an account in the Grafana database. There is a config option to stop that once you’ve created an account (port 3000).
So what we have is a simple script – and as with “the script” – just make a file (say, grafanasetup.sh) – copy this info to it, make sure the CRLF format is LF only for Linux – save the file and give it execute permission. Then run it – and somewhat later on – you should have a working InfluxDB/Grafana setup.
September 10, 2017
I've just tried this on a Roseapple Pi recently upgraded to "Stretch" Debian. To be honest I made such a mess of the upgrade I'm surprised it worked at all - but it did. I added the database to Influx as described above - then went to Grafana. At this point Grafana had nothing but the default username and password... admin and admin - a good idea to change that - easy. The job then was to add that new database - easy - add datasource - type influxdb - any username and pass as you've not set up security yet. That's it - you're then ready to add a dashboard.
Think of this as the “extras” section as we have a working setup above as long as security isn’t an issue. While reading about InfluxDB, I thought I’d look to see why they gave up on the graphical setup interface. Well, it turns out there is something called Chronograf and up to now I’ve not seen much about it – however in this French post I found this:
sudo wget https://dl.influxdata.com/chronograf/nightlies/chronograf_nightly_armhf.deb
sudo dpkg -i chronograf_nightly_armhf.deb
sudo systemctl start chronograf
With nothing to lose as I’d backed up my installation, I gave it a whirl. With no apparent errors I tried bringing up Chrome browser and pointing to the Pi at port 8888
Sure enough it worked and though creating a database didn’t seem to do any good – once I had some data thanks to the above setup…. I could query data and even create a user with password – but when connecting to Grafana I found I could still access the data without reference to that user or password.
It seems you still have to go into the config file to set this up (I could be wrong). I found the config file at /etc/influxdb and enabling security under the http section. I set that to true and rebooted after which – the setup in Grafana required a username and password in the data source section. Not https: at this point but better than nothing. Here (thanks to Antonio) is a simple command line to change that config file.
sudo sed -i -e 's/.*auth-enabled = false/ auth-enabled = true/g' /etc/influxdb/influxdb.conf
With all of this success, the only thing that was missing was to put Grafana onto something a little more meaty - a 64 bit machine. As it happens I'm messing with NEO PLUS2 boards right now and when I tried to install on them - the database worked (InfluxDB) but Grafana would only install an early version. Well, thanks to Antonio asking all the right questions and spending time on this - here's a list of instructions - which worked on the Plus2 at least.
and if you need to start from scratch...
October 28 2017
I just installed on a pair of NEO2 boards which are sitting in Spain running on solar while I'm suffering the rain in Britain.... the installation went flawlessly putting the boards at version 4.6 - be wary of any installation that sets you back to version 2.x