Prometheus is a time series database for monitoring and alerting. For my environment I am going to use it as a data source in Grafana. This post will go over installing Prometheus on a Raspberry Pi and scraping node_exporter.

Download

For Raspbian to run Prometheus we need to download a precompiled version for the armv7 architecture and then unarchive the download.

wget https://github.com/prometheus/prometheus/releases/download/v2.22.0/prometheus-2.22.0.linux-armv7.tar.gz
tar xfz prometheus-2.22.0.linux-armv7.tar.gz

Installation

Now the folder needs to be moved to a system location before we create the systemd service for prometheus.

sudo mv prometheus-2.22.0.linux-armv7 /opt/prometheus

We also need a user to run this server. We need to create it and ensure the owner is set on our new folder.

sudo useradd prometheus
sudo chown -R prometheus /opt/prometheus

Now create the configuration file /opt/prometheus/prometheus.yml like below, where host1/host2 are your hosts with node_exporter installed.

global:
  scrape_interval:     15s 
  external_labels:
    monitor: 'homelab-monitor'

scrape_configs:
  - job_name: 'prometheus'
    scrape_interval: 5s

    static_configs:
      - targets: 
        - host1:9100
        - host2:9100

Then create the systemd unit file at /etc/systemd/system/prometheus.service.

sudo vim /etc/systemd/system/prometheus.service

The file should look like this.

[Unit]
Description=Prometheus Server
Documentation=https://prometheus.io/docs/introduction/overview/
After=network-online.target

[Service]
User=prometheus
Restart=on-failure

ExecStart=/opt/prometheus/prometheus \
  --config.file=/opt/prometheus/prometheus.yml \
  --storage.tsdb.path=/opt/prometheus/data

[Install]
WantedBy=multi-user.target

Now enable/start the new service.

sudo systemctl daemon-reload
sudo systemctl enable prometheus
sudo systemctl start prometheus

Ansible Code

I have ansible code in Github to setup the Prometheus server on a Raspberry Pi here.

To use clone the repository and update the ansible_hosts file.

git clone https://github.com/xadlien/rpi-prometheus.git
cd rpi-prometheus
vim ansible_hosts

After the host has been updated run this command to execute the ansible.

ansible-playbook -i ansible_hosts playbooks/prometheus_server.yml

Next Steps

The next step in getting monitoring setup in my home lab would be to connect Grafana to Prometheus. This will be released shortly.