Prometheus is an open-source systems monitoring and alerting toolkit originally built at SoundCloud. This recipe describes how to install prometheus and node exporter (a famous metrics collector/exporter for hardware and OS metrics exposed by *NIX kernels) on Ubuntu systems with systemd.
useradd -m -s /bin/bash prometheus
passwd prometheus
su - prometheus
wget https://github.com/prometheus/prometheus/releases/download/v2.16.0/prometheus-2.16.0.linux-amd64.tar.gz
tar -xf prometheus-2.16.0.linux-amd64.tar.gz
mv prometheus-2.16.0.linux-amd64/ prometheus/
mkdir -p ~/prometheus/data
wget https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz
mv node_exporter-0.18.1.linux-amd64 node_exporter
vim prometheus/prometheus.yml
and insert
- job_name: 'node_exporter'
static_configs:
- targets: ['localhost:9100']
in section scrape_config
exit
vim /etc/systemd/system/prometheus.service
Insert:
[Unit]
Description=Prometheus Server
Documentation=https://prometheus.io/docs/introduction/overview/
After=network-online.target
[Service]
User=prometheus
Restart=on-failure
#Change this line if you download the
#Prometheus on different path user
ExecStart=/home/prometheus/prometheus/prometheus \
--config.file=/home/prometheus/prometheus/prometheus.yml \
--storage.tsdb.path=/home/prometheus/prometheus/data
[Install]
WantedBy=multi-user.target
vim /etc/systemd/system/node_exporter.service
Insert:
[Unit]
Description=Node Exporter
Wants=network-online.target
After=network-online.target
[Service]
User=prometheus
ExecStart=/home/prometheus/node_exporter/node_exporter
[Install]
WantedBy=default.target
systemctl daemon-reload
systemctl start prometheus
systemctl enable prometheus
systemctl start node_exporter
systemctl enable node_exporter
systemctl status prometheus
systemctl status node_exporter
Browse to localhost:9090
to see the servers metrics.