Install Prometheus on Ubuntu 22.04

This tutorial is going to teach you how to Install Prometheus on Ubuntu 22.04. Prometheus is a free event monitoring and alerting software program.It uses an HTTP pull mechanism to store real-time metrics in a time series database with configurable searches and real-time alerting.

How to Install Prometheus on Ubuntu 22.04

  • To install Prometheus on Ubuntu 22.04, begin by creating a user and a group for the Prometheus system.
sudo groupadd --system prometheus
  • Next add a user and assign it to the group created.
sudo useradd -s /sbin/nologin --system -g prometheus prometheus

Create directory for Prometheus on Ubuntu 22.04

  • You need to create directory required to run Prometheus, run the following commands to create.
sudo mkdir /etc/prometheus

Then

sudo mkdir /var/lib/prometheus

Download Prometheus on Ubuntu 22.04

  • Check for latest version of Prometheus here and download it. Alternatively use the following command to download.
curl -s https://api.github.com/repos/prometheus/prometheus/releases/latest | grep browser_download_url | grep linux-amd64 | cut -d '"' -f 4 | wget -qi -
  • After downloading extract it using the command below.
tar xvf prometheus*.tar.gz

Sample output

prometheus-2.33.3.linux-amd64/
prometheus-2.33.3.linux-amd64/consoles/
prometheus-2.33.3.linux-amd64/consoles/index.html.example
prometheus-2.33.3.linux-amd64/consoles/node-cpu.html
prometheus-2.33.3.linux-amd64/consoles/node-disk.html
prometheus-2.33.3.linux-amd64/consoles/node-overview.html
prometheus-2.33.3.linux-amd64/consoles/node.html
prometheus-2.33.3.linux-amd64/consoles/prometheus-overview.html
prometheus-2.33.3.linux-amd64/consoles/prometheus.html
prometheus-2.33.3.linux-amd64/console_libraries/
prometheus-2.33.3.linux-amd64/console_libraries/menu.lib
prometheus-2.33.3.linux-amd64/console_libraries/prom.lib
prometheus-2.33.3.linux-amd64/prometheus.yml
prometheus-2.33.3.linux-amd64/LICENSE
prometheus-2.33.3.linux-amd64/NOTICE
prometheus-2.33.3.linux-amd64/prometheus
  • Navigate to the directory extracted.
cd prometheus*/
  • Place the binary files in the /usr/local/bin/ folder.
sudo mv prometheus promtool /usr/local/bin/
  • Confirm if everything is working okay.
prometheus --version

Sample output

prometheus, version 2.33.3 (branch: HEAD, revision: 56e14463bccfbb6a8facfb663fed5e0ca9f8b387)
  build user:       root@4ee34e4f7340
  build date:       20220211-20:48:21
  go version:       go1.17.7
  platform:         linux/amd64
  • In the /etc directory, copy the Prometheus configuration template.
sudo mv prometheus.yml /etc/prometheus/prometheus.yml
  • Consoles and console libraries should also be moved to the /etc/prometheus directory.
sudo mv consoles/ console_libraries/ /etc/prometheus/
cd $HOME
  • Grant the newly formed Prometheus user directory access
sudo chown prometheus:prometheus /etc/prometheus
sudo chown prometheus:prometheus /var/lib/prometheus
sudo chown -R prometheus:prometheus /etc/prometheus/consoles
sudo chown -R prometheus:prometheus /etc/prometheus/console_libraries

Create Prometheus Systemd Service on Ubuntu 22.04

  • If you want Prometheus to start and run automatically in the background as a system service every time you turn on your computer, you need to create systemd service file for Prometheus.
  • Run the following command, you can use your favorite text editor in my case it’s nano.
sudo nano /etc/systemd/system/prometheus.service
  • Paste the following, save and exit.
[Unit]
Description=Prometheus
Documentation=https://prometheus.io/docs/introduction/overview/
Wants=network-online.target
After=network-online.target
[Service]
User=prometheus
Group=prometheus
Type=simple
ExecStart=/usr/local/bin/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
  • Next run the commands below to start and enable Prometheus on Ubuntu 22.04.
sudo systemctl daemon-reload
sudo systemctl enable --now prometheus
  • After running the above commands, Prometheus should be running. Confirm using the command below.
systemctl status prometheus

Sample output

● prometheus.service - Prometheus
     Loaded: loaded (/etc/systemd/system/prometheu>
     Active: active (running) since Sun 2022-02-20>
       Docs: https://prometheus.io/docs/introducti>
   Main PID: 6935 (prometheus)
      Tasks: 7 (limit: 4588)
     Memory: 18.5M
     CGroup: /system.slice/prometheus.service
             └─6935 /usr/local/bin/prometheus --co>

Feb 20 20:37:39 ubuntu prometheus[6935]: ts=2022-0>
Feb 20 20:37:39 ubuntu prometheus[6935]: ts=2022-0>
Feb 20 20:37:39 ubuntu prometheus[6935]: ts=2022-0>
Feb 20 20:37:39 ubuntu prometheus[6935]: ts=2022-0>
Feb 20 20:37:39 ubuntu prometheus[6935]: ts=2022-0>
Feb 20 20:37:39 ubuntu prometheus[6935]: ts=2022-0>
Feb 20 20:37:39 ubuntu prometheus[6935]: ts=2022-0>
Feb 20 20:37:39 ubuntu prometheus[6935]: ts=2022-0>
Feb 20 20:37:39 ubuntu prometheus[6935]: ts=2022-0>
Feb 20 20:37:39 ubuntu prometheus[6935]: ts=2022-0>

Access Prometheus Web Interface on Ubuntu 22.04

  • By default Prometheus run on port 9090, allow port 9090 on your firewall using the command below.
sudo ufw allow 9090/tcp
  • Prometheus can be accessed from your favorite web browser by entering your server IP followed by port 9090 e.g. server-ip-address:9090 or localhost:9090 if you are testing it locally.
  • You have reached the end of the article, Congratulations, you have learned how to Install Prometheus on Ubuntu 22.04.

Other Tutorials

Install and Configure VNC server on Ubuntu 22.04

Install Guacamole remote desktop tool on Ubuntu 22.04

Encrypt data using EncFS on Ubuntu 22.04

System administrator | Software Developer | DevOps

Leave a Comment