The last weeks, I've been having some issues with my Raspberry Pi, which unexpectedly stopped working after some days, so I asked a question on twitter, and the following stack was one of the proposals.
Prometheus is one of the most popular options when you think in a monitoring solution (time series based, alerting, etc), and one of their sub-projects is node_exporter, which shows a list of metrics that will be consumed by Prometheus.
Dokku is The smallest PaaS implementation you've ever seen, and I've blogged about it several times because I'm using it for all my personal projects hosted in the smallest dropplet in Digital Ocean (5$/month).
I've divided this article in two different posts, and these are all the parts:
- Export the metrics from the Raspberry Pi using
- Do the metrics accessible from internet (as we'll run Prometheus in a Digital Ocean dropplet).
- Install Prometheus in dokku.
- Install Grafana in dokku.
- Connect all the pieces.
- Importing a
1. Exporting the metrics
node_exporter is a small application that exposes several metrics in a format that Prometheus is able to pull.
The installation is straightforward, and consists in download the package from the releases tab in Github, and execute it (these commands are run in your RPi).
Once you run the command, you could visit http://<raspberry_IP>:9100/, and press in the metrics button, in my case it will link to http://192.168.0.166:9100/metrics.
You don't want to run this command manually every time that your raspberry needs to restart, so you can add an entry to your crontab:
2. Doing accessible node_exporter from Internet
As we'll have our Prometheus hosted in an external server (Digital Ocean in my case), we have to do our RPi accessible from the internet.
Doing that could be different depending on the router you have, so I gonna share a screenshot of my router's configuration, where it's only needed to set up the port to be mapped to the RPi, in my case, accessing to
<my_ip>:9101 from the internet, will be mapped to the port
9100 on my RPi.
3. Install Prometheus in Dokku
I'm going to explain how to deploy Prometheus in that droplet using Dokku.
# Create the dokku application dokku apps:create prometheus # Create the directory where we'll store the prometheus data mkdir -p /var/lib/dokku/data/storage/prometheus/ # The prometheus container uses the user `nobody`, so we change the permissions to do that directory writable # Related: https://github.com/prometheus/prometheus/blob/e963d953eac7d5181024eba2215740835b65c0a9/Dockerfile#L18-L21 sudo chown -R 65534:65534 /var/lib/dokku/data/storage/prometheus/
In our local, we create a new repository and setup a remote with our dokku host.
# Initialize the repository git init # Add a new remote called `dokku` with our dokku host git remote add dokku firstname.lastname@example.org:prometheus
Now, we have to create the minimum docker environment:
Dockerfile(using the prometheus image as base, and just copying the config).
prometheus.yml(with the config to scrape).
app.json(optional, but I'm using the dokku-require plugin, this file configures the mounted volumes).
After commit all these files, and push to the dokku server, you should be able to access to the prometheus in the default domain value, but maybe you prefer to access in a more friendly url, like https://prometheus.yourdomain.com:9091/.
# Configure your desired domain dokku domains:add prometheus prometheus.yourdomain.com # Enable the HTTPS using the letsencrypt plugin dokku letsencrypt prometheus # Set the proxy ports dokku proxy:ports-set prometheus http:9090:9090 https:9091:9090
The last step, is just to configure the start parameter that prometheus will use to run the container (more info about the available parameters in the prometheus website):
dokku config:set prometheus DOKKU_DOCKERFILE_START_CMD="--config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path=/data --storage.tsdb.retention.size=1GB --storage.tsdb.retention.time=30d"
After that, if you open https://prometheus.yourdomain.com:9091/ in your browser, you should see something similar to this under the
Status > Targets menu.
And you could start to play with the available metrics from the Graph menu (prometheus query examples).
In this article we've learned how to consume the metrics that node_exporter generates from our Raspberry Pi, and querying these using prometheus.
In the next article I'll explain how to install Grafana in Dokku, and how to connect all the pieces.