Prometheus is a free and open-source monitoring application used for event monitoring and alerting. It gathers, organizes, and stores metrics in a time-series database. It has gained in popularity and has been adopted by many organizations to monitor their infrastructure metrics. It is written in the Go language and uses HTTP pulls to gather metrics from remote hosts and applications. It uses Grafana to visualize data for monitoring and analysis.

In this post, we will show you how to install Prometheus on Oracle Linux 8.

Step 1 – Download Prometheus

Before starting, you will need to create a dedicated user for Prometheus. You can create it using the following command:

adduser -M -r -s /sbin/nologin prometheus

Next, create a directory for Prometheus with the following command:

mkdir /var/lib/prometheus
mkdir /etc/prometheus/

Next, download the latest stable version of Prometheus using the following command:

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

Once the download is completed, extract the downloaded file with the following command:

tar -xvzf prometheus-2.36.2.linux-amd64.tar.gz

Step 2 – Configure Prometheus

Next, you will need to copy the Prometheus binary from the extracted source to the system directory. You can copy them with the following command:

cp prometheus-2.36.2.linux-amd64/prometheus /usr/local/bin/
cp prometheus-2.36.2.linux-amd64/promtool /usr/local/bin/

Next, copy the Prometheus console templates and libraries to the ‘/etc/prometheus’ directory.

cp -r prometheus-2.36.2.linux-amd64/consoles /etc/prometheus
cp -r prometheus-2.36.2.linux-amd64/console_libraries /etc/prometheus/

Next, copy the Prometheus configuration file using the following command:

cp prometheus-2.36.2.linux-amd64/prometheus.yml /etc/prometheus

Next, edit the Prometheus configuration file /etc/prometheus/prometheus.yml using the nano editor.

nano /etc/prometheus/prometheus.yml

Add the following lines:

  - job_name: "prometheus"

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ["your-server-ip:9090"]

Save and close the file, then change the ownership of the Prometheus directory:

chown prometheus:prometheus /etc/prometheus
chown prometheus:prometheus /var/lib/prometheus

Step 3 – Create a Systemd Service for Prometheus

Next, create a systemd service file to manage the Prometheus service via systemd:

nano /etc/systemd/system/prometheus.service

Add the following configuration:

[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, then reload the systemd daemon to apply the changes:

systemctl daemon-reload

Next, start and enable the Prometheus service with the following command:

systemctl enable --now prometheus

You can now check the status of the Prometheus service using the following command:

systemctl status prometheus

You will get the following output:

● prometheus.service - Prometheus
   Loaded: loaded (/etc/systemd/system/prometheus.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2022-06-29 11:26:03 EDT; 4s ago
 Main PID: 1272 (prometheus)
    Tasks: 7 (limit: 11409)
   Memory: 19.6M
   CGroup: /system.slice/prometheus.service
           └─1272 /usr/local/bin/prometheus --config.file /etc/prometheus/prometheus.yml --storage.tsdb.path /var/lib/prometheus/ --web.conso>

Jun 29 11:26:03 oraclelinux8 prometheus[1272]: ts=2022-06-29T15:26:03.653Z caller=head.go:536 level=info component=tsdb msg="On-disk memory m>
Jun 29 11:26:03 oraclelinux8 prometheus[1272]: ts=2022-06-29T15:26:03.653Z caller=head.go:542 level=info component=tsdb msg="Replaying WAL, t>
Jun 29 11:26:03 oraclelinux8 prometheus[1272]: ts=2022-06-29T15:26:03.654Z caller=head.go:613 level=info component=tsdb msg="WAL segment load>
Jun 29 11:26:03 oraclelinux8 prometheus[1272]: ts=2022-06-29T15:26:03.654Z caller=head.go:619 level=info component=tsdb msg="WAL replay compl>
Jun 29 11:26:03 oraclelinux8 prometheus[1272]: ts=2022-06-29T15:26:03.655Z caller=main.go:993 level=info fs_type=XFS_SUPER_MAGIC
Jun 29 11:26:03 oraclelinux8 prometheus[1272]: ts=2022-06-29T15:26:03.655Z caller=main.go:996 level=info msg="TSDB started"
Jun 29 11:26:03 oraclelinux8 prometheus[1272]: ts=2022-06-29T15:26:03.655Z caller=main.go:1177 level=info msg="Loading configuration file" fi>
Jun 29 11:26:03 oraclelinux8 prometheus[1272]: ts=2022-06-29T15:26:03.693Z caller=main.go:1214 level=info msg="Completed loading of configura>
Jun 29 11:26:03 oraclelinux8 prometheus[1272]: ts=2022-06-29T15:26:03.693Z caller=main.go:957 level=info msg="Server is ready to receive web >
Jun 29 11:26:03 oraclelinux8 prometheus[1272]: ts=2022-06-29T15:26:03.693Z caller=manager.go:937 level=info component="rule manager" msg="Sta>

By default, Prometheus listens on port 9090. You can check it with the following command:

ss -antpl | grep 9090

You should see the following output:

LISTEN 0      128                *:9090            *:*    users:(("prometheus",pid=1272,fd=7))

You can now verify the Prometheus dashboard using the URL http://your-server-ip:9090. You should see the Prometheus dashboard on the following page:
Prometheus dashboard

Step 4 – Install Node Exporter

Prometheus uses a Node Exporter to collect Linux system metrics like CPU load and disk I/O. First, download the Node Exporter with the following command:

wget https://github.com/prometheus/node_exporter/releases/download/v1.3.1/node_exporter-1.3.1.linux-amd64.tar.gz

Once the download is completed, extract the downloaded file with the following command:

tar -xvzf node_exporter-1.3.1.linux-amd64.tar.gz

Next, copy the Node Exporter binary to the system directory:

mv node_exporter-1.3.1.linux-amd64/node_exporter /usr/local/bin

Next, create a dedicated user for Node Exporter using the following command:

adduser -M -r -s /sbin/nologin node_exporter

Step 5 – Create a Systemd Service File for Node Exporter

Next, you will need to create a systemd service file for Node Exporter. You can create it with the following command:

nano /etc/systemd/system/node_exporter.service

Add the following lines:

[Unit]
Description=Node Exporter
After=network.target

[Service]
User=node_exporter
Group=node_exporter
Type=simple
ExecStart=/usr/local/bin/node_exporter

[Install]
WantedBy=multi-user.target

Save and close the file, then reload the systemd daemon to apply the changes:

systemctl daemon-reload

Next, start and enable the Node Exporter service:

systemctl enable --now node_exporter

You can check the status of the Node Exporter service using the following command:

systemctl status node_exporter

You will get the following output:

● node_exporter.service - Node Exporter
   Loaded: loaded (/etc/systemd/system/node_exporter.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2022-06-29 11:28:37 EDT; 4s ago
 Main PID: 1347 (node_exporter)
    Tasks: 3 (limit: 11409)
   Memory: 4.7M
   CGroup: /system.slice/node_exporter.service
           └─1347 /usr/local/bin/node_exporter

Jun 29 11:28:37 oraclelinux8 node_exporter[1347]: ts=2022-06-29T15:28:37.778Z caller=node_exporter.go:115 level=info collector=thermal_zone
Jun 29 11:28:37 oraclelinux8 node_exporter[1347]: ts=2022-06-29T15:28:37.778Z caller=node_exporter.go:115 level=info collector=time
Jun 29 11:28:37 oraclelinux8 node_exporter[1347]: ts=2022-06-29T15:28:37.779Z caller=node_exporter.go:115 level=info collector=timex
Jun 29 11:28:37 oraclelinux8 node_exporter[1347]: ts=2022-06-29T15:28:37.779Z caller=node_exporter.go:115 level=info collector=udp_queues
Jun 29 11:28:37 oraclelinux8 node_exporter[1347]: ts=2022-06-29T15:28:37.779Z caller=node_exporter.go:115 level=info collector=uname
Jun 29 11:28:37 oraclelinux8 node_exporter[1347]: ts=2022-06-29T15:28:37.779Z caller=node_exporter.go:115 level=info collector=vmstat
Jun 29 11:28:37 oraclelinux8 node_exporter[1347]: ts=2022-06-29T15:28:37.779Z caller=node_exporter.go:115 level=info collector=xfs
Jun 29 11:28:37 oraclelinux8 node_exporter[1347]: ts=2022-06-29T15:28:37.779Z caller=node_exporter.go:115 level=info collector=zfs
Jun 29 11:28:37 oraclelinux8 node_exporter[1347]: ts=2022-06-29T15:28:37.779Z caller=node_exporter.go:199 level=info msg="Listening on" addre>

By default, Node Exporter listens on port 9100. You can check it with the following command:

ss -antpl | grep 9100

You should see the following output:

LISTEN 0      128                *:9100            *:*    users:(("node_exporter",pid=1347,fd=3))

Step 6 – Configure Node Exporter

Next, you will need to edit the Prometheus configuration file and define Node Exporter:

nano /etc/prometheus/prometheus.yml

Add the following lines:

  - job_name: 'node_exporter_metrics'
    scrape_interval: 5s
    static_configs:
      - targets: ['SERVER-IP:9100']

Save and close the file, then restart the Prometheus service to apply the changes:

systemctl restart prometheus

Step 7 – Verify Prometheus and Node Exporter

Now, open your Prometheus dashboard and click on Status => Targets. You should see two endpoints:

Prometheus add target

Next, click on the Graph and type the PromQL query “node_os_info” on the search bar then click on the Execute button. You should see detailed information about your current operating system.
Prometheus execute query

Conclusion

In this post, we explained how to install Prometheus on Oracle Linux 8. We also explained how to add Node Exporter to Prometheus and run the query. I hope this guide will help you to implement your own monitoring system in your organization. Give it a try on dedicated server hosting from Atlantic.Net!