How to Install Prometheus on Ubuntu 22.04 LTS

Prometheus is an efficient and open-source computer monitoring system. It observes the computer events, software and services. The Prometheus allows the application metrics to store in a time-series database because it has its own storage system. This application was developed and used at Soundcloud. However, various organisations used it later on for monitoring purposes. It is written in Go programming language.

Prometheus has the data collection method called ‘scraping’. However, ‘exporter’ is a data collection tool. Prometheus provides various advantages to entertain its users such as data processing, web-based user interface and an alert managing system.

This article demonstrates the several methods to install the Prometheus on Ubuntu 22.04.

How to install Prometheus on Ubuntu 22.04

Prometheus is an open-source web-based monitoring system that stores the metrics of applications into a time-series database. There are some prerequisites for installation of Prometheus on Ubuntu 22.04. To install the Prometheus on latest version of Ubuntu 22.04, follow the step-by-step-guide given as follows:

Step 1: Update System’s packages

How to install Kali Linux in Window...

You should update the system’s packages repository to get the updated packages of the system. To update the system’s packages, run the following command in the terminal:

$ sudo apt update

The installed packages are updated successfully.

Step 2: Create Prometheus system’s group

First, create a user and Prometheus system’s group before installing the prometheus on Ubuntu 22.04. To create the prometheus system group, execute the given command in terminal:

$ sudo groupadd --system prometheus

User and system’s group of prometheus is created successfully.

Step 3: Add user to assign the group

When the group is created, add the Prometheus user and assign it the created group. To add a user and assign the created group, type and run the following command in Linux terminal:

$ sudo useradd -s /sbin/nologin --system -g prometheus prometheus

A user is added to the assigned group.

Step 4: Create directory

The Prometheus has its own storing system. However, it stores the data using the directory.

Therefore, to create the directory, run the following command:

$ sudo mkdir /etc/prometheus

It is the primary directory of Prometheus. However, it will have some sub directory. To create sub directory, run the below mentioned command:

$ sudo mkdir /var/lib/prometheus

The sub-directory is created successfully.

Step: 5 Download Prometheus on Ubuntu 22.04

To check and download the latest version of Prometheus, go to the github repository using the following link.

https://prometheus.io/download/

Step 6: Extract the file

When the file is downloaded, extract it using the following command:

$ tar xvf prometheus*.tar.gz

The file is extracted successfully.

Step 7: Navigate to directory

When the file is extracted, navigate to the directory by using following command:

$ cd prometheus*/

And move the binary files to the local folder to change the directory. To move the files to /usr/local/bin, use the following command:

$ sudo mv prometheus promtool /usr/local/bin/

To confirm the installed version of Prometheus on Ubuntu 22.04, execute the following command:

$ prometheus --version

It is verified that the installed version of Prometheus on Ubuntu is 2.35.0.

Step 8: Move Prometheus configuration template

When the installation is completed successfully, move the configuration template to the /etc directory for Prometheus configuration. To move the template, run the following command:

$ sudo mv prometheus.yml /etc/prometheus/prometheus.yml

You should also move the console libraries to the /etc directory to change back to the home directory. To move the console libraries, type and run the following command:

$ sudo mv consoles/ console_libraries/ /etc/prometheus/
$ cd $HOME

The output showed that the directory is changed to home after moving the console library to the /etc/ prometheus/.

How to configure Prometheus on Ubuntu

For the configuration of Prometheus on Ubuntu 22.04 to create and edit the file, run the following command in terminal:

$ sudo vim /etc/prometheus/prometheus.yml

How to Create Prometheus systemd service

If you want to start the prometheus automatically then you should create the prometheus systemd service file. Type and execute the command in terminal as given in following:

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

And paste the following:

[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

The system service is created successfully.

How to Reload and enable the Prometheus

If you want to start the prometheus automatically after the system reboot, you should enable the prometheus. To reload and enable the prometheus on Ubuntu 22.04, type and run the following commands in terminal:

$ sudo systemctl daemon-reload 

The prometheus service is reloaded successfully.

$ sudo systemctl enable --now prometheus

The prometheus is enabled to run automatically after the system reboot.

How to Access the Prometheus port

The port 9090 is the default running port of the Prometheus. To allow the port 9090 on firewall, execute the following command:

$ sudo ufw allow 9090/tcp

The output showed that the rule was added successfully.

Until now, you have learned to get and configure Prometheus on Ubuntu 22.04.

Conclusion

Prometheus can be installed on Ubuntu 22.04 using the official system’s repository. Prometheus is an efficient and open-source computer monitoring system. It observes the computer events, software and services. It stores the metrics of applications in a time series database as it has its own data storage system. This article provided a complete guide to install the Prometheus on Ubuntu 22.04. We have also illustrated the configuration of Prometheus on Ubuntu 22.04.