Welcome to today’s guide on the installation of Prometheus on Amazon Linux 2 server. Prometheus is a free to use and an open-source systems monitoring and alerting toolkit originally built at SoundCloud. Since its original inception many companies have adopted Prometheus hence the growth of its user community. Prometheus is now a standalone project maintained and developed by the open source community. Prometheus joined the Cloud Native Computing Foundation in 2016 as the second hosted project, after Kubernetes.

Below are the main features of Prometheus monitoring tool.

  • a multi-dimensional data model with time series data identified by metric name and key/value pairs
  • PromQL, a flexible query language to leverage this dimensionality
  • no reliance on distributed storage; single server nodes are autonomous
  • time series collection happens via a pull model over HTTP
  • pushing time series is supported via an intermediary gateway
  • targets are discovered via service discovery or static configuration
  • multiple modes of graphing and dashboarding support

Install Prometheus on Amazon Linux 2

Prometheus collects metrics from configured targets at given intervals, evaluates rule expressions, displays the results, and can trigger alerts if some condition is observed to be true.

You can install prometheus from a binary file downloadable from the Project website or by using packagecloud YUM repository.

Method 1: Install Prometheus from YUM repository

For the YUM repository method we’ll use Packagecloud. Run the following commands in your terminal to add the repository to your Amazon Linux 2 machine.

sudo tee /etc/yum.repos.d/prometheus.repo <<EOF 
[prometheus]
name=prometheus
baseurl=https://packagecloud.io/prometheus-rpm/release/el/7/x86_64
repo_gpgcheck=1
enabled=1
gpgkey=https://packagecloud.io/prometheus-rpm/release/gpgkey
       https://raw.githubusercontent.com/lest/prometheus-rpm/master/RPM-GPG-KEY-prometheus-rpm
gpgcheck=1
metadata_expire=300
EOF

After adding the YUM repository install Prometheus and Node exporter using the following commands:

sudo yum -y install prometheus2 node_exporter

Installation process output:

....
Total download size: 33 M
Installed size: 147 M
Downloading packages:
warning: /var/cache/yum/x86_64/2/prometheus/packages/node_exporter-1.0.1-2.el7.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID 168a1ea1: NOKEY6 MB  00:00:25 ETA
Public key for node_exporter-1.0.1-2.el7.x86_64.rpm is not installed
(1/2): node_exporter-1.0.1-2.el7.x86_64.rpm                                                                                                | 4.5 MB  00:00:09
(2/2): prometheus2-2.21.0-1.el7.x86_64.rpm                                                                                                 |  28 MB  00:00:28
------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                             1.2 MB/s |  33 MB  00:00:28
Retrieving key from https://packagecloud.io/prometheus-rpm/release/gpgkey
Importing GPG key 0x7457CCD1:
 Userid     : "https://packagecloud.io/prometheus-rpm/centos (https://packagecloud.io/docs#gpg_signing) <[email protected]>"
 Fingerprint: d7df c575 af4b 92c6 e62a d3c5 f721 6757 7457 ccd1
 From       : https://packagecloud.io/prometheus-rpm/release/gpgkey
Retrieving key from https://raw.githubusercontent.com/lest/prometheus-rpm/master/RPM-GPG-KEY-prometheus-rpm
Importing GPG key 0x168A1EA1:
 Userid     : "prometheus-rpm <[email protected]>"
 Fingerprint: c7b7 cccb be77 86a4 9df8 e28d 3a09 16e8 168a 1ea1
 From       : https://raw.githubusercontent.com/lest/prometheus-rpm/master/RPM-GPG-KEY-prometheus-rpm
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : prometheus2-2.21.0-1.el7.x86_64                                                                                                                1/2
  Installing : node_exporter-1.0.1-2.el7.x86_64                                                                                                               2/2
  Verifying  : node_exporter-1.0.1-2.el7.x86_64                                                                                                               1/2
  Verifying  : prometheus2-2.21.0-1.el7.x86_64                                                                                                                2/2

Installed:
  node_exporter.x86_64 0:1.0.1-2.el7                                               prometheus2.x86_64 0:2.21.0-1.el7

Complete!

You can use rpm command to check for the version of Prometheus installed.

$ rpm -qi prometheus2
Name        : prometheus2
Version     : 2.21.0
Release     : 1.el7
Architecture: x86_64
Install Date: Mon 05 Oct 2020 11:51:13 AM UTC
Group       : Unspecified
Size        : 138216726
License     : ASL 2.0
Signature   : RSA/SHA1, Fri 11 Sep 2020 03:17:48 PM UTC, Key ID 3a0916e8168a1ea1
Source RPM  : prometheus2-2.21.0-1.el7.src.rpm
Build Date  : Fri 11 Sep 2020 03:12:23 PM UTC
Build Host  : abfe7ce424c1
Relocations : (not relocatable)
URL         : https://prometheus.io
Summary     : The Prometheus 2.x monitoring system and time series database.

Configure basic settings by editing the prometheus.yml file.

sudo vim /etc/prometheus/prometheus.yml

I’ll set it to monitor the local server using the node exporter we installed.

# my global config
global:
  scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

# Alertmanager configuration
alerting:
  alertmanagers:
  - static_configs:
    - targets:
      # - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'prometheus'

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

    static_configs:
    - targets: ['localhost:9090']
  # Pull host metrics with node exporter
  - job_name: mynode
    static_configs:
      - targets: ['localhost:9100']

Restart prometheus and node_exporter services.

sudo systemctl restart prometheus node_exporter

Also set the services to start at host boot.

$ sudo systemctl enable prometheus node_exporter
Created symlink from /etc/systemd/system/multi-user.target.wants/prometheus.service to /usr/lib/systemd/system/prometheus.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/node_exporter.service to /usr/lib/systemd/system/node_exporter.service.

Check if the services are in running state.

$ systemctl status prometheus.service node_exporter.service
● prometheus.service - The Prometheus 2 monitoring system and time series database.
   Loaded: loaded (/usr/lib/systemd/system/prometheus.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2020-10-05 17:16:20 UTC; 2min 23s ago
     Docs: https://prometheus.io
 Main PID: 7206 (prometheus)
   CGroup: /system.slice/prometheus.service
           └─7206 /usr/bin/prometheus --web.console.libraries=/usr/share/prometheus/console_libraries --web.console.templates=/usr/share/prometheus/consoles --...

Oct 05 17:16:20 amazon-linux prometheus[7206]: level=info ts=2020-10-05T17:16:20.511Z caller=head.go:658 component=tsdb msg="On-disk memory mappable c…tion=3.26µs
Oct 05 17:16:20 amazon-linux prometheus[7206]: level=info ts=2020-10-05T17:16:20.512Z caller=head.go:664 component=tsdb msg="Replaying WAL, this may take a while"
Oct 05 17:16:20 amazon-linux prometheus[7206]: level=info ts=2020-10-05T17:16:20.519Z caller=head.go:716 component=tsdb msg="WAL segment loaded" segme...Segment=1
Oct 05 17:16:20 amazon-linux prometheus[7206]: level=info ts=2020-10-05T17:16:20.519Z caller=head.go:716 component=tsdb msg="WAL segment loaded" segme...Segment=1
Oct 05 17:16:20 amazon-linux prometheus[7206]: level=info ts=2020-10-05T17:16:20.519Z caller=head.go:719 component=tsdb msg="WAL replay completed" che…=7.831963ms
Oct 05 17:16:20 amazon-linux prometheus[7206]: level=info ts=2020-10-05T17:16:20.521Z caller=main.go:721 fs_type=XFS_SUPER_MAGIC
Oct 05 17:16:20 amazon-linux prometheus[7206]: level=info ts=2020-10-05T17:16:20.521Z caller=main.go:724 msg="TSDB started"
Oct 05 17:16:20 amazon-linux prometheus[7206]: level=info ts=2020-10-05T17:16:20.521Z caller=main.go:850 msg="Loading configuration file" filename=/et...theus.yml
Oct 05 17:16:20 amazon-linux prometheus[7206]: level=info ts=2020-10-05T17:16:20.522Z caller=main.go:881 msg="Completed loading of configuration file" filename…ns
Oct 05 17:16:20 amazon-linux prometheus[7206]: level=info ts=2020-10-05T17:16:20.522Z caller=main.go:673 msg="Server is ready to receive web requests."

● node_exporter.service - Prometheus exporter for machine metrics, written in Go with pluggable metric collectors.
   Loaded: loaded (/usr/lib/systemd/system/node_exporter.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2020-10-05 17:16:20 UTC; 2min 23s ago
     Docs: https://github.com/prometheus/node_exporter
 Main PID: 7204 (node_exporter)
   CGroup: /system.slice/node_exporter.service
           └─7204 /usr/bin/node_exporter

Oct 05 17:16:20 amazon-linux node_exporter[7204]: level=info ts=2020-10-05T17:16:20.465Z caller=node_exporter.go:112 collector=thermal_zone
Oct 05 17:16:20 amazon-linux node_exporter[7204]: level=info ts=2020-10-05T17:16:20.465Z caller=node_exporter.go:112 collector=time
Oct 05 17:16:20 amazon-linux node_exporter[7204]: level=info ts=2020-10-05T17:16:20.465Z caller=node_exporter.go:112 collector=timex
Oct 05 17:16:20 amazon-linux node_exporter[7204]: level=info ts=2020-10-05T17:16:20.465Z caller=node_exporter.go:112 collector=udp_queues
Oct 05 17:16:20 amazon-linux node_exporter[7204]: level=info ts=2020-10-05T17:16:20.465Z caller=node_exporter.go:112 collector=uname
Oct 05 17:16:20 amazon-linux node_exporter[7204]: level=info ts=2020-10-05T17:16:20.465Z caller=node_exporter.go:112 collector=vmstat
Oct 05 17:16:20 amazon-linux node_exporter[7204]: level=info ts=2020-10-05T17:16:20.465Z caller=node_exporter.go:112 collector=xfs
Oct 05 17:16:20 amazon-linux node_exporter[7204]: level=info ts=2020-10-05T17:16:20.466Z caller=node_exporter.go:112 collector=zfs
Oct 05 17:16:20 amazon-linux node_exporter[7204]: level=info ts=2020-10-05T17:16:20.466Z caller=node_exporter.go:191 msg="Listening on" address=:9100
Oct 05 17:16:20 amazon-linux node_exporter[7204]: level=info ts=2020-10-05T17:16:20.466Z caller=tls_config.go:170 msg="TLS is disabled and it cannot b...tp2=false
Hint: Some lines were ellipsized, use -l to show in full.

If you have firewalld running enable prometheus service.

sudo firewall-cmd --add-service=prometheus --permanent
sudo firewall-cmd --reload

Access the Prometheus Web UI on http://(server_hostname_or_IP_Address):9090/ from your client machine.

This is a confirmation that Prometheus server is working as expected.

Our next guide will go into detail on monitoring server uptime with Prometheus. And in later series into metrics graphing with Grafana.s

Other Monitoring guides:

How To Install LibreNMS On Oracle Linux

Install Zabbix 5 LTS With Nginx on Oracle Linux

LEAVE A REPLY

Please enter your comment!
Please enter your name here

8 + sixteen =