Linux

How to install, configure Prometheus for Monitoring on a Linux Server

FEATURE-IMAGE-IMAGE

Prometheus is a lightweight open-source monitoring system with an effective alerting system. Prometheus gathers and saves metrics as time-series data, which means that metric data is kept alongside the timestamp at which it was captured, as well as additional key-value pairs known as labels. More information about this can be gotten from here: prometheus.io/docs/concepts/data. This tutorial will teach you how to install, set up, and monitor our first Prometheus resource. Prometheus will be downloaded, installed, and executed. Other tutorials can be found here: How to install PostgreSQL on Ubuntu, How to install Apache Tomcat on Ubuntu, How to install Node.js on Ubuntu, How to install PostgreSQL on Ubuntu, install Gradle on Ubuntu, and How to install and configure Tripwire on Ubuntu.

Attributes

  1. Time-series data identifiable by metric name and key/value pairs in an inter-data model
  2. Uses PromQL for Querying and PromQL is a versatile query language
  3. That allows you to make use of the dimensionality without relying on distributed storage.
  4. Single server nodes are self-contained, and time series are collected using a pull model over HTTP.
  5. Pushing time series is possible with the help of an intermediate gateway.
  6. Service discovery or static configuration is used to discover targets.
  7. Service discovery or static configuration is used to discover targets.

Requirements

  1. Be sure you have sudo access to the Linux server.
  2. The server has internet connectivity and can download the Prometheus binaries.
  3. On the server, firewall rules are opened to allow access to Prometheus port 9090.

Configure Prometheus Binaries

Step 1: Update the apt package repositories.

sudo apt update

Step 2: Go to the official Prometheus downloads page and get the latest download link for the Linux binary.

DPROMETHEUS-1
download prometheus

Step 3: extract using the tar command, and rename the extracted folder to Prometheus-files.

tar -xvf prometheus-2.35.0.linux-amd64.tar.gz
mv prometheus-2.35.0.linux-amd64 prometheus-files
tarx
extract & rename

Step 4: Create a Prometheus user, the necessary directories, and make Prometheus the owner of those directories.

sudo useradd --no-create-home --shell /bin/false prometheus
sudo mkdir /etc/prometheus
sudo mkdir /var/lib/prometheus
sudo chown prometheus:prometheus /etc/prometheus
sudo chown prometheus:prometheus /var/lib/prometheus

Step 5: Change the ownership to the Prometheus user and copy the Prometheus and promtool binaries from the Prometheus files folder to /usr/local/bin.

sudo cp prometheus-files/prometheus /usr/local/bin/
sudo cp prometheus-files/promtool /usr/local/bin/
sudo chown prometheus:prometheus /usr/local/bin/prometheus
sudo chown prometheus:prometheus /usr/local/bin/promtool

Step 6: Transfer the consoles and console libraries folders from Prometheus-files to the /etc/prometheus folder and assign the consoles and console libraries directories to the Prometheus user.

Configure Prometheus

The /etc/prometheus/Prometheus.yml file should contain all prometheus configurations.

Step 1: Create the prometheus.yml file.

sudo vi /etc/prometheus/prometheus.yml

Step 2: Copy the following contents to the prometheus.yml file.

global:
  scrape_interval: 10s

scrape_configs:
  - job_name: 'prometheus'
    scrape_interval: 5s
    static_configs:
      - targets: ['localhost:9090']

Step 3: Change the ownership of the file to Prometheus user.

sudo chown prometheus:prometheus /etc/prometheus/prometheus.yml

Setup Prometheus Service File

Step 1: Create a Prometheus service file.

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

Step 2: Copy the following content to 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=/etc/prometheus/consoles \
    --web.console.libraries=/etc/prometheus/console_libraries

[Install]
WantedBy=multi-user.target

Step 3: Reload the systemd service to register the Prometheus service and start the Prometheus service.

sudo systemctl daemon-reload
sudo systemctl start prometheus

Check the Prometheus service

sudo systemctl status prometheus
status-1

Access Prometheus Web UI

You may now access the Prometheus UI through the Prometheus server’s 9090 port.

To get the ip address type the command below

ip address show

To navigate to Prometheus UI type the command below and substitute the IP address of your environment

http://<prometheus-ip>:9090/graph

You should be able to view the UI depicted below.

prometheus-ui
Prometheus ui

We have just finished configuring the Prometheus server. To obtain metrics from the source systems, you must first register the target in the Prometheus.yml file.

If you wish to monitor 10 servers, for example, the IP addresses of these servers should be included as targets in the Prometheus setup to scrape the metrics.

Node Exporter should be installed on the server to capture all system metrics and make them available for Prometheus to scrape.

endpoint
endpoint well configured

Here is a video on how to Install, Configure Prometheus for Monitoring on a Linux Server.

Summary

We installed and configured Prometheus on an Ubuntu machine. And as you can see from the last screenshot, the state says up and this indicates that everything was well configured and working properly

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x