< Billy Overton >

Programmer / Technology Consultant

Smart Meter Dashboard: Installing InfluxDB

Posted 2016-05-30 | Billy Overton

For this project I knew I didn’t want to store a log of the information from the meter on the Pi. Through some testing, I determined that my power meter broadcasted it’s consumption about once every 30 seconds. While there isn’t much data overall that I wanted to store, I was kind of hesitant to write to a file on the Pi’s SD card that frequently. Looking around for a simple time series database, I found InfluxDB which seemed perfect for my use case.


After spinning up a new Debian droplet, the installation was pretty simple.

# Enable the influxDB
curl -sL https://repos.influxdata.com/influxdb.key | sudo apt-key add -
source /etc/os-release
echo "deb https://repos.influxdata.com/debian jessie stable" | sudo tee /etc/apt/sources.list.d/influxdb.list

# Install the packages
sudo apt-get update && sudo apt-get install influxdb
sudo service influxdb start

Creating a Database

Creating a database was pretty simple using the provided command line client.

$ influx

Enable SSL

Since I planned on having authentication to prevent direct database access, I didn’t want the communication between my local machine and the server to be in clear text. By default influxDB does all of it’s communication over HTTP, but it does have support for SSL. To enable it I needed to create a PEM encoded SSL key and certificate. For my purposes a self-signed certificate was good enough, but for added security (namely SSL validation) a signed certificate should be used.

# Create self-signed certificate for influx
cd /etc/ssl
openssl genrsa -out key.pem 2048 # Generate a private key
openssl req -new -key key.pem -out cert.csr # Create a certificate signing request
openssl x509 -req -days 365 -in cert.csr -signkey key.pem -out cert.pem # Sign the certificate with the key

Influx uses a combined file for both the private key and the certificate file, so I had to append them together.

cat key.pem > influxDB.pem
cat cert.pem >> influxDB.pem

Once the combined file was created, I enable ssl by editing /etc/influxdb/influxdb.conf. I scrolled down to the sections for [admin] changed the https-enabled option to true and changed the https-certificate to the path of the newly created combined PEM file. For me that was https-certificate = "/etc/ssl/influxDB.pem". I did the same in the [http] section.

I tested if this was successful by restarting the influxdb service with sudo service influxdb restart and attempted to connect using the influx command line tool. Since SSL is enabled you need to pass a few more flags in order for this to work: influx -ssl -unsafeSsl. Since I used a self-signed certificate, I had to use the -unsafeSsl flag to disable the clients validation step.

Enable Authorization and Authentication

By default influxDB does not have authorization and authentication enabled. To enable it you must first create at least one administrator user account. I used the command line client to create two users: an admin user with all privileges and a power user that only has permissions to the power database I created earlier.

influx -ssl -unsafeSsl
> CREATE USER power WITH PASSWORD '<password>'
> GRANT [READ,WRITE,ALL] ON power TO power

Once the users were created, I enabled authentication by editing /etc/influxdb/influxdb.conf again. In the [http] section, I changed auth-enabled to true. I restarted the influx service and relaunch the influx command line client. It should deny all requests to read data till you authenticate with > auth <username> <password>. Alternatively you can launch with influx -ssl -unsafeSsl -username <username> -password <password> to authenticate before the client launches.

Next Step

Once I had a place to store my power usage information, I needed to setup the radio to pickup and send the information over to influxDB. That will be the topic of the next post.