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
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:
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:
Run the following commands to get the proper Go version and install it in /usr/local.
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.
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:
This should give you something like:
For NodeJS run:
And this should give:
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.
During the build process I’ve encountered out-of-memory errors which I’ve resolved by setting the $GOMAXPROCS variable like so:
Now you can start the build of the backend code by running the following commands (this takes a while):
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.
And now you can build the frontend part by executing (this also takes a while):
Now, if all went well you should be able to run:
and see the HTTP server firing up. To get started visit your raspberrypi through your webbrowser on port 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:
Execute the following command to let the grafana server start when the operating system starts:
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):
To see if the Grafana service has successfully started you can run:
When successful this should give something like: