UPDATE October 16th 2019: Corrected several (copy/paste) mistakes and added some additional instructions.

Yesterday I tried to install ‘Grafana’ on my Raspberry Pi 2 but the process wasn’t as straightforward as installing a package through apt-get so I decided to write the process down in case anyone else decides to install Grafana on their Raspberry Pi.

If you don’t know what Grafana is, it’s a web-based environment in which you can create beautiful dashboards using all kinds of graphs, gauges etc. which are based on queries. Grafana is able to connect to a variety of datasources (mostly metric based databases) like Graphite, Prometheus, Elastic etc. Just take a look at their site to get an impression of Grafana’s capabilities.

Ok, let’s get started. My Raspberry Pi 2 is currently running ‘Raspbian 8 (jessie)’. This is what

cat /etc/os-release

gives me:

PRETTY_NAME="Raspbian GNU/Linux 8 (jessie)"
NAME="Raspbian GNU/Linux"
VERSION_ID="8"
VERSION="8 (jessie)"
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"

To install Grafana (v4.6.1 at the time of writing) on the Raspberry Pi in Raspbian we need to build Grafana from source. Fortunately this is not difficult and is for the most part already described on the Grafana website. But first we need to get some essential tools/dependencies in place.

First we need to install the build-essential package, to do this run:

sudo apt-get update && sudo apt-get install build-essential

According to the documentation on the Grafana website, at this time of writing, Grafana needs at least Go1.9 to build an run. Unfortunately this isn’t available as a package through apt (the available package for Go is currently at v1.3), so we need to get it elsewhere. Google has binaries available for v1.9 which we can download and use. As described here the steps are the following:

If Go is already installed through apt, remove it using the following commands:

sudo apt remove golang
sudo apt-get autoremove

Run the following commands to get the proper Go version and install it in /usr/local.

wget https://storage.googleapis.com/golang/go1.9.linux-armv6l.tar.gz
sudo tar -C /usr/local -xzf go1.9.linux-armv6l.tar.gz
export PATH=$PATH:/usr/local/go/bin

Next, we need to get the proper binaries for the latest NodeJS LTS version. These are available from the NodeJS website and can be retrieved and installed using the following commands.

wget https://nodejs.org/dist/v8.9.1/node-v8.9.1-linux-armv7l.tar.xz
sudo tar -C /usr/local -xf node-v8.9.1-linux-armv7l.tar.xz
export PATH=$PATH:/usr/local/node-v8.9.1-linux-armv7l/bin

To make sure the locations to the binaries are properly set in the $PATH environment variable check the versions for Go and NodeJS. For Go run:

go version

This should give you something like:

go version go1.9 linux/arm

For NodeJS run:

node -v

And this should give:

v8.9.1

Now, it’s more or less following the first steps for building from source as described on the Grafana website. I’ve created a ‘Go’ directory in my user’s home directory and set the $GOPATH variable accordingly.

export GOPATH=$HOME/go

During the build process I’ve encountered out-of-memory errors which I’ve resolved by setting the $GOMAXPROCS variable like so:

export GOMAXPROCS=1

Download Grafana

go get github.com/grafana/grafana

Now you can start the build of the backend code by running the following commands (this takes a while):

cd $GOPATH/src/github.com/grafana/grafana
go run build.go setup
go run build.go build

Before we get to building the frontend part of the Grafana system we need to get a version of PhantomJS in place or else the frontend build process will fail. There is no official package available for arm system so we need to install an unofficial package. I used the unofficial package from https://github.com/fg2it/phantomjs-on-raspberry/tree/master/rpi-2-3/wheezy-jessie/v2.1.1. As described on the README page just execute the following commands to install PhantomJS v2.1.1.

sudo apt-get install libfontconfig1 libfreetype6
curl -o /tmp/phantomjs_2.1.1_armhf.deb -sSL https://github.com/fg2it/phantomjs-on-raspberry/releases/download/v2.1.1-wheezy-jessie/phantomjs_2.1.1_armhf.deb
sudo dpkg -i /tmp/phantomjs_2.1.1_armhf.deb

And now you can build the frontend part by executing (this also takes a while):

npm install -g yarn
yarn install --pure-lockfile
yarn start

Now, if all went well you should be able to run:

./bin/grafana-server

and see the HTTP server firing up. To get started visit your raspberrypi through your webbrowser on port 3000

http://raspberrypi_address:3000/

and see the magic happen.

If you want Grafana to be automatically started whenever the operating system starts we need to load up a unit file in systemd. You can do this by creating a unit file in /lib/systemd/system, something like this /lib/systemd/system/grafana.service. Give the grafana.service file the following contents:

[Unit]
Description=Grafana
After=syslog.target

[Service]
Type=simple
User=pi
WorkingDirectory=/home/pi/go/src/github.com/grafana/grafana
ExecStart=/home/pi/go/src/github.com/grafana/grafana/bin/grafana-server
StandardOutput=syslog
StandardError=syslog

[Install]
WantedBy=multi-user.target

Execute the following command to let the grafana server start when the operating system starts:

sudo systemctl enable grafana.service

If you’ve enabled the service you can start it right away running the following command (If you’ve Grafana running already you might want to kill that first):

sudo systemctl start grafana.service

To see if the Grafana service has successfully started you can run:

sudo systemctl status grafana.service

When successful this should give something like:

grafana.service - Grafana
   Loaded: loaded (/lib/systemd/system/grafana.service; enabled)
   Active: active (running) since Sat 2017-11-14 20:28:16 CET; 7s ago
 Main PID: 8810 (grafana-server)
   CGroup: /system.slice/grafana.service
           └─8810 /home/pi/go/src/github.com/grafana/grafana/bin/grafana-server

Nov 14 20:28:17 raspberrypi2 grafana-server[8810]: t=2017-11-14T20:28:17+0100 lvl=info msg="Starting DB migration" logger=migrator
Nov 14 20:28:17 raspberrypi2 grafana-server[8810]: t=2017-11-14T20:28:17+0100 lvl=info msg="Executing migration" logger=migrator id="copy data account to org"
Nov 14 20:28:17 raspberrypi2 grafana-server[8810]: t=2017-11-14T20:28:17+0100 lvl=info msg="Skipping migration condition not fulfilled" logger=migrator id="copy data account to org"
Nov 14 20:28:17 raspberrypi2 grafana-server[8810]: t=2017-11-14T20:28:17+0100 lvl=info msg="Executing migration" logger=migrator id="copy data account_user to org_user"
Nov 14 20:28:17 raspberrypi2 grafana-server[8810]: t=2017-11-14T20:28:17+0100 lvl=info msg="Skipping migration condition not fulfilled" logger=migrator id="copy data account_user to org_user"
Nov 14 20:28:17 raspberrypi2 grafana-server[8810]: t=2017-11-14T20:28:17+0100 lvl=info msg="Starting plugin search" logger=plugins
Nov 14 20:28:18 raspberrypi2 grafana-server[8810]: t=2017-11-14T20:28:18+0100 lvl=info msg="Initializing Alerting" logger=alerting.engine
Nov 14 20:28:18 raspberrypi2 grafana-server[8810]: t=2017-11-14T20:28:18+0100 lvl=info msg="Initializing CleanUpService" logger=cleanup
Nov 14 20:28:18 raspberrypi2 grafana-server[8810]: t=2017-11-14T20:28:18+0100 lvl=info msg="Initializing Stream Manager"
Nov 14 20:28:18 raspberrypi2 grafana-server[8810]: t=2017-11-14T20:28:18+0100 lvl=info msg="Initializing HTTP Server" logger=http.server address=0.0.0.0:3000 protocol=http subUrl= socket=