LocalHake

Tutorial

Prometheus as a Service

Set up Prometheus as a service to monitor your system on Ubuntu 24.04

Hake HardwarePublished Updated ~5 minintermediate

This post contains paid links (affiliate) — how that works.


▶ Watch this build on YouTube
Contents

Introduction

This guide will provide instructions on how to install Prometheus as a service on Ubuntu 24.04.

Download and Install Prometheus

Navigate to the Prometheus Download Page and locate the release with the "Latest" tag. I typically do not use the beta version, and at the time of this wiki the latest version is prometheus-2.55.0.linux-amd64.tar.gz and it will be used as an example in future commands within this wiki.

Download the latest version to the home directory:

bash
wget -P ~/ https://github.com/prometheus/prometheus/releases/download/v2.55.0/prometheus-2.55.0.linux-amd64.tar.gz

Extract the downloaded file:

bash
tar -xvf ~/prometheus-2.55.0.linux-amd64.tar.gz

Move the extracted files:

bash
sudo mv ~/prometheus-2.55.0.linux-amd64 /etc/prometheus

Delete the tar.gz file:

bash
rm ~/prometheus-2.55.0.linux-amd64.tar.gz

Create the prometheus user:

bash
sudo useradd -r -s /bin/false -c "Prometheus service account" -d /nonexistent prometheus
  • -r makes it a system user
  • --no-create-home: This option prevents the creation of a home directory for the prometheus user.
  • --shell /bin/false: This prevents the user from being able to log in interactively.

Set permissions:

bash
sudo chown -R prometheus:prometheus /etc/prometheus

Create a data directory in /var/lib for Prometheus storage:

bash
sudo mkdir /var/lib/prometheus

Set permissions for the prometheus user:

bash
sudo chown -R prometheus:prometheus /var/lib/prometheus

Create a systemd service:

bash
sudo nano /etc/systemd/system/prometheus.service

Add the following configuration:

/etc/systemd/system/prometheus.serviceini
[Unit]
Description=Prometheus Service
Wants=network-online.target
After=network-online.target

[Service]
User=prometheus
Group=prometheus
Type=simple
ExecStart=/etc/prometheus/prometheus \
    --config.file=/etc/prometheus/prometheus.yml \
    --storage.tsdb.path=/var/lib/prometheus/ \
    --web.console.templates=/etc/prometheus/consoles \
    --web.console.libraries=/etc/prometheus/console_libraries

[Install]
WantedBy=multi-user.target

Save with Ctrl+X, Y, Enter.

Reload daemon:

bash
sudo systemctl daemon-reload

Start service:

bash
sudo systemctl start prometheus

Enable service to start on boot:

bash
sudo systemctl enable prometheus

Verify the status:

bash
sudo systemctl status prometheus

Access Prometheus

The Prometheus web front end should now be accessible on http://localhost:9090. If the service is running on another host, replace localhost with the IP of that host. To start scraping metrics, endpoints can be added to the prometheus.yml file, and then the prometheus service should be restarted for the changes to take effect.

Grafana

Learn how to add Prometheus as a data source for Grafana. If you are using Grafana Cloud, you will need to set up a PDC agent and add Prometheus as a data source.

Gear used