Ask Your Question
3

How to set up Prometheus on Ubuntu?

asked 2022-05-16 11:00:00 +0000

djk gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2021-11-27 07:00:00 +0000

devzero gravatar image

Here are the steps to set up Prometheus on Ubuntu:

  1. Install Prometheus:

First, you need to download the latest version of Prometheus from the official website.

wget https://github.com/prometheus/prometheus/releases/download/v2.30.2/prometheus-2.30.2.linux-amd64.tar.gz

Then extract the content of the downloaded file:

tar -xzf prometheus-2.30.2.linux-amd64.tar.gz

This will create a directory named prometheus-2.30.2.linux-amd64 which contains the Prometheus files.

  1. Create a user:

For security purposes, it is best to create a dedicated user to run Prometheus.

sudo useradd -rs /bin/false prometheus
  1. Configure Prometheus:

Create a new directory for the Prometheus configuration files and move the sample configuration file to this directory:

sudo mkdir /etc/prometheus
sudo mv prometheus-2.30.2.linux-amd64/prometheus.yml /etc/prometheus/prometheus.yml

Edit the Prometheus configuration file using a text editor of your preference:

sudo nano /etc/prometheus/prometheus.yml

You will find a list of targets, which are the endpoints that Prometheus will scrape. Modify this list to add the endpoints of the systems that you want to monitor.

  1. Create a systemd service:

To start and stop Prometheus automatically, create a systemd service file:

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

Paste the following configuration into the file:

[Unit]
Description=Prometheus
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=/usr/local/share/prometheus/console_templates \
    --web.console.libraries=/usr/local/share/prometheus/console_libraries \
--web.enable-lifecycle

[Install]
WantedBy=multi-user.target

Save and close the file.

  1. Create a data directory:

Prometheus stores its data in a directory. Create the directory and assign it to the Prometheus user:

sudo mkdir /var/lib/prometheus
sudo chown prometheus:prometheus /var/lib/prometheus
  1. Start Prometheus:

Start the Prometheus service, and enable it to start at boot time:

sudo systemctl daemon-reload
sudo systemctl start prometheus
sudo systemctl enable prometheus
  1. Verify Prometheus installation:

Check the status of Prometheus to ensure that it has started correctly:

sudo systemctl status prometheus

If there are any problems, refer to the log files and troubleshoot as needed.

The Prometheus server should now be up and running, ready to start monitoring your system!

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-05-16 11:00:00 +0000

Seen: 22 times

Last updated: Nov 27 '21