Install Metrics Management
How to install some metrics management in our app/virtual machine
Install Prometheus
- Download prometheus from here
wget https://github.com/prometheus/prometheus/releases/download/v2.51.1/prometheus-2.51.1.linux-amd64.tar.gz
- Download node exporter
wget https://github.com/prometheus/node_exporter/releases/download/v1.7.0/node_exporter-1.7.0.linux-amd64.tar.gz
- Create user and group for prometheus
sudo groupadd --system prometheus
sudo useradd --system -s /sbin/nologin -g prometheus prometheus
- Untar the .tar.gz file
tar -xvf prometheus-2.51.1.linux-amd64.tar.gz
tar -xvf node_exporter-1.7.0.linux-amd64.tar.gz
- Move prometheus and promtool from prometheus folder to bin folder
sudo mv prometheus-2.51.1.linux-amd64/prometheus prometheus-2.51.1.linux-amd64/promtool /usr/local/bin/
- Check prometheus
prometheus --version
- Create folder for prometheus config and library store
sudo mkdir /etc/prometheus && sudo mkdir /var/lib/prometheus
- Change ownership of prometheus library store to user and group prometheus
sudo chown -R prometheus:prometheus /var/lib/prometheus/
- Move all prometheus config to prometheus folder
sudo mv consoles/ console_libraries/ prometheus.yml /etc/prometheus/
- Create prometheus systemctl service file
sudo vim /etc/systemd/system/prometheus.service
[Unit]
Description=Prometheus
Documentation=https://prometheus.io/docs/introduction/overview
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
- Reload the daemon
sudo systemctl daemon-reload
- Start prometheus service
sudo systemctl enable --now prometheus.service
- Move node-exporter to bin folder
sudo mv node_exporter-1.7.0.linux-amd64/node_exporter /usr/local/bin/
- Create node-exporter systemctl service file
sudo vim /etc/systemd/system/node-exporter.service
[Unit]
Description=Prometheus exporter for machine metrics
[Service]
Restart=always
User=prometheus
ExecStart=/usr/local/bin/node_exporter
ExecReload=/bin/kill -HUP $MAINPID
TimeoutStopSec=20s
SendSIGKILL=no
[Install]
WantedBy=multi-user.target
- Reload the daemon and start node-exporter service
sudo systemctl daemon-reload && sudo systemctl enable --now node-exporter.service
- Adjust prometheus.yml file
sudo vim /etc/prometheus/prometheus.yml
global:
scrape_interval: 15s
evaluation_interval: 15s
alerting:
alertmanagers:
- static_configs:
- targets:
rule_files:
scrape_configs:
- job_name: "prometheus"
static_configs:
- targets: ["localhost:9090"]
- job_name: "node-exporter"
static_configs:
- targets: ["localhost:9100"]
- Restart prometheus service
sudo systemctl restart prometheus.service
Install Grafana
- Install the prerequisite packages
sudo apt-get install -y apt-transport-https software-properties-common wget
- Import GPG Key
sudo mkdir -p /etc/apt/keyrings/
wget -q -O - https://apt.grafana.com/gpg.key | gpg --dearmor | sudo tee /etc/apt/keyrings/grafana.gpg > /dev/null
- Add a repository for stable releases
echo "deb [signed-by=/etc/apt/keyrings/grafana.gpg] https://apt.grafana.com stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list
- Update the package
sudo apt-get update
- Install grafana
sudo apt-get install grafana
- Start grafana-server service
sudo systemctl enable --now grafana-server.service
- Check grafana in
http://localhost:3000
Init Username: admin
Password: admin