How to install and configure Prometheus on Ubuntu 22.04?

Prometheus is a popular open-source monitoring system that provides monitoring and alerting for applications and infrastructure. It is designed to collect metrics from various sources, store them, and provide a powerful query language to analyze and visualize the data. In this blog post, we will discuss how to install and configure Prometheus on Ubuntu 22.04.

Step 1: Update your system

Before installing Prometheus, you should update your Ubuntu system to ensure that you have the latest software packages. To do this, open the terminal and run the following command

sudo apt-get update

Step 2: Install Prometheus

To install Prometheus on Ubuntu 22.04, you can use the official Prometheus APT repository. To add the repository, run the following command

sudo apt-get install curl gnupg2 -y

curl https://packagecloud.io/gpg.key | sudo apt-key add -

echo "deb https://packagecloud.io/prometheus-rpm/release/ubuntu/22.04/ default main" | sudo tee /etc/apt/sources.list.d/prometheus.list

Once the repository is added, run the following command to install Prometheus

sudo apt-get update

sudo apt-get install prometheus -y

Step 3: Configure Prometheus

The default Prometheus configuration file is located at /etc/prometheus/prometheus.yml. You can edit this file to configure Prometheus to scrape metrics from your applications and infrastructure. Here is an example configuration that scrapes metrics from a sample Node.js application:

global:

  scrape_interval: 15s

  evaluation_interval: 15s


scrape_configs:

  - job_name: 'nodejs'

    scrape_interval: 5s

    static_configs:

      - targets: ['localhost:9090', 'localhost:3000']

This configuration file specifies that Prometheus should scrape metrics every 15 seconds and evaluate them every 15 seconds. It also includes a job named nodejs that scrapes metrics from two targets: localhost:9090 and localhost:3000.

Step 4: Start Prometheus

Once you have configured Prometheus, you can start it using the following command

sudo systemctl start prometheus

You can also enable Prometheus to start automatically at system startup by running the following command

sudo systemctl enable prometheus

Step 5: Access Prometheus

Prometheus provides a web-based user interface that you can use to view and analyze your metrics. By default, the Prometheus user interface is accessible at http://localhost:9090. You can open this URL in your web browser to access the user interface.

Conclusion

In this blog post, we have discussed how to install and configure Prometheus on Ubuntu 22.04. With Prometheus, you can easily collect, store, and analyze metrics from your applications and infrastructure. By following the steps outlined in this post, you can get started with Prometheus and begin monitoring your systems today.


How to install and configure Prometheus on Ubuntu 18.04?

How to install and configure Prometheus on Ubuntu 20.04?

Comments

Popular posts from this blog

How to update build number in Azure DevOps pipeline?

How to get latest build ID from Azure DevOps pipeline?

How to install AWS System Manager (SSM) Agent on windows using PowerShell?