Prometheus is a system monitoring tool used for recording real-time metrics and system performance in a time-series database. It is open-source software that was originally developed at SoundCloud using the Go programming language.
You can monitor applications and system resources such as CPU usage, memory utilization, network bandwidth among others.
Prometheus can be accessed through a web interface, therefore, allowing you to monitor your server from any device. Moreover, you can send alerts via email and SMS messages in case a problem is identified in your system.
In this guide, we’ll discuss how you can install Prometheus on Ubuntu 20.04.
First, you need to create a system user and group for Prometheus. Let’ create a user, group, and directory called Prometheus. Run the following commands:
$ sudo useradd --no-create-home --shell /bin/false prometheus
$ sudo useradd --no-create-home --shell /bin/false node_exporter
Thereafter, we need to create directories for storing Prometheus files and data. Create a /var/lib directory for its data and /etc directory for configuration files.
$ sudo mkdir /etc/prometheus $ sudo mkdir /var/lib/prometheus
Next, modify the user and group ownership on the new directories to the Prometheus user you created. Run:
$ sudo chown prometheus:prometheus /etc/prometheus $ sudo chown prometheus:prometheus /var/lib/prometheus
Next, download the latest Prometheus archive file from Github or Prometheus official page. Execute the following wget command:
$ wget https://github.com/prometheus/prometheus/releases/download/v2.21.0/prometheus-2.31.0.linux-amd64.tar.gz
Then, use the sha256sum command line to verify the integrity of the Prometheus archive file you just downloaded.
$ sha256sum prometheus-2.31.0.linux-amd64.tar.gz
Ensure that the result of the above command matches the SHA256 Checksum on the official Prometheus download page. It will guarantee that our file is authentic and not corrupted.
Next, extract the contents of the archive file.
$ tar -xvf prometheus-2.21.0.linux-amd64.tar.gz
Navigate into the prometheus folder as shown:
$ cd prometheus-2.21.0.linux-amd64
Use the ls command to view the contents of the folder. You see two binary files (Prometheus and promtool), one prometheus.yml, two consoles, and console libraries directories containing the web interface files.
As seen, the prometheus directory contains two binary files, Prometheus and promtool. Copy the binary files to /usr/local/bin directory as shown:
$ sudo cp prometheus-2.31.0.linux-amd64/prometheus /usr/local/bin/ $ sudo cp prometheus-2.31.0.linux-amd64/promtool /usr/local/bin/
Next, set the user and group ownership on the binary files. Execute the commands:
$ sudo chown prometheus:prometheus /usr/local/bin/prometheus $ sudo chown prometheus:prometheus /usr/local/bin/promtool
We also need to copy prometheus console and console_libraries directories to /etc/prometheus/. Run:
$ sudo cp -r prometheus-2.31.0.linux-amd64/consoles /etc/prometheus sudo cp -r prometheus-2.31.0.linux-amd64/console_libraries /etc/prometheus $ sudo cp -r prometheus-2.31.0.linux-amd64/prometheus.yml /etc/prometheus
Then, update the user and group ownership on the /etc/promotheus directory using the command below:
$ sudo chown -R prometheus:prometheus /etc/prometheus/consoles $ sudo chown -R prometheus:prometheus /etc/prometheus/console_libraries $ sudo chown -R prometheus:prometheus /etc/prometheus/prometheus.yml
Prometheus has now been successfully installed on our system. Confirm the version installed with the command:
$ prometheus --version $ promtool --version
Next, open the prometheus default configuration file as shown below. You can modify the settings according to your preferences
$ cat /etc/prometheus/prometheus.yml
To launch Prometheus as a service, we must first configure it. We will specify a location for both the configuration file and the data directory as shown:
$ sudo -u prometheus /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
Next, create a systemd file for Prometheus so that you can easily manage the service. Let’s create a systemd file in /etc/systemd/system directory as shown:
$ sudo nano /etc/systemd/system/prometheus.service
Next, copy the lines below to the systemd 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=/etc/prometheus/consoles --web.console.libraries=/etc/prometheus/console_libraries [Install] WantedBy=multi-user.target
Save and close the file.
Next, reload the daemon services for the changes to be applied. Run:
$ sudo systemctl daemon-reload
Then, start and enable Prometheus service with the following commands:
$ sudo systemctl start prometheus $ sudo systemctl enable prometheus
Now check the status of Prometheus with the command:
$ sudo systemctl status prometheus
Prometheus is now up and running.
Now that Prometheus has been configured successfully, we can access it through the web interface. Also, make sure that port 9090 is enabled in the firewall. To allow the prometheus service in the firewall, run:
$ sudo ufw allow 9090/tcp
Open a web browser and access Prometheus as shown below:
$ http://server-IP:9090.
You will see the following screen.
Prometheus is now running on Ubuntu 20.04 system. You can now start monitoring your system performance and metrics.
In this article, we will see how to Install Google Cloud BigQuery Python client library…
Nov 15,2024 Wallpaper Contest for Xfce 4.20 open for voting The submission phase for the…
MicroCloud 2.1.0 LTS is now available, expanding the number of Canonical infrastructure solutions with a…
Canonical is thrilled to be joining forces with Dell Technologies at the upcoming Dell Technologies…
In today’s massive private mobile network (PMN) market, one of the most common approaches to…
Welcome to the Ubuntu Weekly Newsletter, Issue 865 for the week of November 3 –…