Prometheus as a Service
Set up Prometheus as a service to monitor your system on Ubuntu 24.04
Prometheus as a Service on Ubuntu
Introduction
This guide will provide instructions on how to install Prometheus as a service on Ubuntu 24.04.
- What is Prometheus?
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
wget -P ~/ https://github.com/prometheus/prometheus/releases/download/v2.55.0/prometheus-2.55.0.linux-amd64.tar.gzExtract the downloaded file
tar -xvf ~/prometheus-2.55.0.linux-amd64.tar.gzMove the extracted files
sudo mv ~/prometheus-2.55.0.linux-amd64 /etc/prometheusDelete the tar.gz file
rm ~/prometheus-2.55.0.linux-amd64.tar.gzCreate the prometheus user
sudo useradd -r -s /bin/false -c "Prometheus service account" -d /nonexistent prometheus-rmakes 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
sudo chown -R prometheus:prometheus /etc/prometheusCreate a data directory in /var/lib for Prometheus storage
sudo mkdir /var/lib/prometheusSet permissions for the prometheus user
sudo chown -R prometheus:prometheus /var/lib/prometheusCreate a systemd service
sudo nano /etc/systemd/system/prometheus.serviceAdd the following configuration, then press ctrl + x, then y, then enter to save.
[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
Reload daemon
sudo systemctl daemon-reloadStart service
sudo systemctl start prometheusEnable service to start on boot
sudo systemctl enable prometheusVerify the status
sudo systemctl status prometheusAccess 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.