Jul 11, 2023 5 min read

How to Install and Configure Prometheus on Ubuntu 22.04 LTS

Install and Configure Prometheus on Ubuntu 22.04 LTS with our step-by-step tutorial. It is a popular open-source monitoring and alerting tool.

Install and Configure Prometheus on Ubuntu 22.04 LTS
Table of Contents

Choose a different version or distribution

Introduction

Before we begin talking about how to install and configure Prometheus on Ubuntu 22.04 LTS, let's briefly understand – What is Prometheus?

Prometheus is a popular open-source monitoring and alerting tool used for tracking and analyzing the performance of computer systems and applications. It gathers metrics from various sources, allowing users to gain insights into resource utilization, system health, and application behavior. With its flexible query language and intuitive visualization capabilities, Prometheus empowers users to monitor real-time metrics and create custom dashboards.

Its robust alerting system notifies administrators of any anomalies or issues, enabling timely intervention. Prometheus supports a wide range of integrations and is highly scalable, making it suitable for small setups and large-scale deployments. By providing valuable monitoring data, Prometheus helps optimize system performance and ensures the smooth operation of critical applications.

In this tutorial, you will learn how to install Prometheus on Ubuntu 22.04. We will also address a few FAQs on how to install Prometheus on Ubuntu 22.04.

Advantages of Prometheus

  1. Monitoring and Metrics: Prometheus provides powerful monitoring capabilities, collecting metrics from various sources to track system performance and application behavior.
  2. Flexible Query Language: Its flexible query language allows users to easily retrieve and analyze metrics, enabling insightful data exploration.
  3. Alerting System: Prometheus features a robust alerting system, notifying administrators of any anomalies or issues in real-time for proactive problem resolution.
  4. Visualization and Dashboards: It offers intuitive visualization tools, allowing users to create custom dashboards and gain clear insights into system metrics.
  5. Scalability: Prometheus is highly scalable, capable of handling large-scale deployments and accommodating growing monitoring needs with ease.

Steps to install Prometheus on Ubuntu 22.04

A time-series database is used to store the metrics of applications in Prometheus, an open-source web-based monitoring system. Prometheus must meet a few requirements in order to be installed on Ubuntu 22.04.  Follow the step-by-step instructions below to install Prometheus on the most recent version of Ubuntu 22.04:

Step 1 - Update System’s packages

To obtain the system's updated packages, you should update the system's package repository. Use the following command in the terminal to update the system's packages:

sudo apt update

The installed packages have successfully been updated.

Step 2 - Create Prometheus system’s group

Before installing Prometheus on Ubuntu 22.04, first create a user and the Prometheus system's group. Complete the following command in a terminal to create the Prometheus system group:

sudo groupadd --system prometheus

Prometheus' user and system group is successfully created.

Step 3 - Add user to assign the group

Add the Prometheus user and assign it to the newly formed group when the group has been created. In the Linux terminal, type and execute the following command to add a user and assign the newly established group:

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

The designated group receives a new user.

Step 4 - Create directory

The Prometheus has its own system for storing things. However, the directory is used to store the data.

Execute the subsequent command to create the directory:

sudo mkdir /etc/prometheus

It is Prometheus's main directory. It will, however, contain a few subdirectories. Run the command listed below to establish a subdirectory:

sudo mkdir /var/lib/prometheus

Successful creation of the subdirectory.

Step 5 - Download Prometheus on Ubuntu 22.04

Use the following URL to access the GitHub source and check the Prometheus version that is currently available for download.

https://prometheus.io/download/

Step 6 - Extract the file

Use the following command to extract the file after it has been downloaded:

tar xvf prometheus*.tar.gz

The file is successfully extracted.

Step 7 - Navigate to directory

After the file has been extracted, use the following command to go to the directory:

cd prometheus*/

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

sudo mv prometheus promtool /usr/local/bin/

Use the following command to verify the Prometheus version installed on Ubuntu 22.04:

prometheus --version

On Ubuntu, Prometheus is confirmed to be installed as version 2.35.0.

Step 8 - Move Prometheus configuration template

Move the configuration template to the /etc directory for Prometheus configuration after the installation has been successful. Use the next command to move the template:

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

To return to the home directory, you should also transfer the console libraries there. Type and run the following command to transfer the console libraries:

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

The output indicated that after relocating the console library to /etc/ prometheus/, the directory had been changed to home.

Configure Prometheus on Ubuntu

Run the following command in terminal to set up Prometheus on Ubuntu 22.04 to create and change the file:

sudo vim /etc/prometheus/prometheus.yml

Create Prometheus systemd service

The prometheus systemd service file should be created if you wish to launch prometheus automatically. In the terminal, enter and run the following command:

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

And then 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 was successfully built.

Reload and enable the Prometheus

You should enable the prometheus if you want it to launch automatically once the system reboots. Type and execute the following commands in terminal to reload and enable the prometheus on Ubuntu 22.04:

sudo systemctl daemon-reload 

The prometheus service has successfully been reloaded.

sudo systemctl enable --now prometheus

After a system reboot, the prometheus is set to run automatically.

Access the Prometheus port

The Prometheus's standard operating port is 9090. Use the following command to configure your firewall to allow port 9090:

sudo ufw allow 9090/tcp

The output indicated that adding the rule had been successful.

You have so far learnt how to install and set up Prometheus on Ubuntu 22.04.

FAQs to Install Prometheus on Ubuntu 22.04

Where is the configuration file for Prometheus located in Ubuntu 22.04?

The configuration file for Prometheus is typically named prometheus.yml and can be placed in the directory where you extracted the Prometheus binary.

How do I access the Prometheus web interface after installation on Ubuntu 22.04?

By default, you can access the Prometheus web interface by opening a web browser and visiting http://localhost:9090.

How can I add targets for monitoring in Prometheus on Ubuntu 22.04?

To add targets, you need to modify the Prometheus configuration file and specify the endpoints you want to monitor. Then, restart Prometheus for the changes to take effect.

What is the default storage location for Prometheus data on Ubuntu 22.04?

Prometheus stores its data in a local time series database. By default, the data is stored in the directory where you run the Prometheus binary.

How can I configure alerts in Prometheus on Ubuntu 22.04?

Prometheus supports configuring alerts using the Alertmanager component. You can define alerting rules in the Prometheus configuration file and configure Alertmanager to handle and send alerts.

How do I start or stop the Prometheus service on Ubuntu 22.04?

Prometheus is typically run as a standalone binary. You can start it by executing the Prometheus binary, and to stop it, you can terminate the running process.

Can I integrate Prometheus with other monitoring tools on Ubuntu 22.04?

Yes, Prometheus supports various integrations with other monitoring tools and systems. You can explore exporters, plugins, and connectors to integrate Prometheus with your preferred tools.

How do I upgrade Prometheus to a newer version on Ubuntu 22.04?

To upgrade Prometheus, you can follow a similar installation process as described earlier but replace the old Prometheus binary with the new version.

Conclusion

We hope this detailed tutorial helped you understand how to install Prometheus on Ubuntu 22.04.

If you have any queries or doubts, please leave them in the comment below. We'll be happy to address them.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to DevOps Tutorials - VegaStack.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.