InfluxDB, Telegraf and Grafana on a Raspberry Pi 2

07 Oct 2015

Prerequisites

InfluxDB

Install dependencies

$ sudo apt-get install ruby-dev gcc
$ sudo gem install fpm

Build package

Let's build InfluxDB 0.9.4.

Setup a gvm package set:

$ gvm pkgset create influxdb
$ gvm pkgset use influxdb

Checkout sources:

$ mkdir -p ~/.gvm/pkgsets/go1.5/influxdb/src/github.com/influxdb
$ cd ~/.gvm/pkgsets/go1.5/influxdb/src/github.com/influxdb
$ git clone https://github.com/influxdb/influxdb.git

Build debian package:

$ cd influxdb
$ ./package.sh -t deb -p 0.9.4

Install

Install package:

$ sudo dpkg -i influxdb_0.9.4_armhf.deb

Start server:

$ sudo service influxdb start

Test server:

$ /opt/influxdb/influx

Note: configuration file is located at: /etc/opt/influxdb/influxdb.conf

Telegraf

Install dependencies

$ sudo apt-get install rpm

Build package

Let's build Telegraf 0.1.9.

Setup a gvm package set:

$ gvm pkgset create telegraf
$ gvm pkgset use telegraf

Install godep:

$ go get github.com/tools/godep

Checkout sources:

$ mkdir -p ~/.gvm/pkgsets/go1.5/telegraf/src/github.com/influxdb
$ cd ~/.gvm/pkgsets/go1.5/telegraf/src/github.com/influxdb
$ git clone https://github.com/influxdb/telegraf.git

Build debian package:

$ cd telegraf
$ ./scripts/package.sh

Respond to questions:

...
Commence creation of unknown packages, version 0.1.9-27-gb4e8a23? [Y/n] Y
...
Publish packages to S3? [y/N] N
...

Install

Install package:

$ sudo dpkg -i telegraf_0.1.9-27-gb4e8a23_armhf.deb

Start server:

$ sudo service telegraf start

Configuration file is located at: /etc/opt/telegraf/telegraf.conf

Grafana

Install dependencies

$ sudo apt-get install ruby-dev rpm
$ sudo gem install fpm

Install nodejs

NOTE: You can skip that part if you already have node.js installed

Install pre-built binaries. In that case, we fetch the armv7l package for a Raspberry Pi 2:

$ sudo mkdir /opt/node
$ wget https://nodejs.org/dist/v4.1.2/node-v4.1.2-linux-armv7l.tar.gz
$ tar zxvf node-v4.1.2-linux-armv7l.tar.gz
$ sudo cp -r node-v4.1.2-linux-armv7l/* /opt/node
$ rm node-v4.1.2-linux-armv7l.tar.gz

Adds those lines to /etc/profile juste before export PATH:

NODE_JS_HOME="/opt/node"
PATH="$PATH:$NODE_JS_HOME/bin"

Build package

Let's build Grafana 2.1.3.

Setup a gvm package set:

$ gvm pkgset create grafana
$ gvm pkgset use grafana

Fetch sources:

$ go get github.com/grafana/grafana
$ cd ~/.gvm/pkgsets/go1.5/grafana/src/github.com/grafana/grafana/
$ git checkout tags/v2.1.3

Setup build:

$ go run build.go setup
$ godep restore
$ npm install
$ sudo /opt/node/bin/npm install -g grunt-cli

Change build.go file, line 76, with grunt("--force","release") to bypass an issue with phantomjs (cf. https://github.com/grafana/grafana/issues/2683).

Then fix a timeout issue:

$ sed -i 's/baseUrl: '\''.\/app'\'',/baseUrl: '\''.\/app'\'',waitSeconds: 0,/' tasks/options/requirejs.js

Build package:

$ go run build.go build package

Install

Install package:

$ sudo dpkg -i dist/grafana_2.1.3_armhf.deb

Setup service:

$ sudo update-rc.d grafana-server defaults 95 10

Start server:

$ sudo service grafana-server start

Configuration files are located at: /etc/default/grafana-server and /etc/grafana/grafana.ini.

Create dashboards

Navigate with a browser to: http://RPI_IP:3000/

Authenticate with admin / admin credendials then change password at: http://RPI_IP:3000/profile/password.

Add the telegraf influxdb datasource as explained at: http://docs.grafana.org/datasources/influxdb/:

- Name: RPI-NAME
- Default: checked
- Type: InfluxDB 0.9.x
- Url: http://localhost:8086/
- Access: proxy
- Basic Auth: NOT checked
- Database: telegraf
- User: admin
- Password: admin

You can now create cool grafana dashboards. Enjoy.

JeeLink

External References