Mirza's Documentation SiteMirza's Documentation Site
Home
Deploy on Virtual Machine
SSL Certificate Assignment
Install Metrics Management
Home
Deploy on Virtual Machine
SSL Certificate Assignment
Install Metrics Management
  • Install Metrics Management

    • Install Prometheus
    • Install Grafana

Install Metrics Management

How to install some metrics management in our app/virtual machine

Install Prometheus

  1. Download prometheus from here
wget https://github.com/prometheus/prometheus/releases/download/v2.51.1/prometheus-2.51.1.linux-amd64.tar.gz
  1. Download node exporter
wget https://github.com/prometheus/node_exporter/releases/download/v1.7.0/node_exporter-1.7.0.linux-amd64.tar.gz
  1. Create user and group for prometheus
sudo groupadd --system prometheus
sudo useradd --system -s /sbin/nologin -g prometheus prometheus
  1. 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
  1. 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/
  1. Check prometheus
prometheus --version
  1. Create folder for prometheus config and library store
sudo mkdir /etc/prometheus && sudo mkdir /var/lib/prometheus
  1. Change ownership of prometheus library store to user and group prometheus
sudo chown -R prometheus:prometheus /var/lib/prometheus/
  1. Move all prometheus config to prometheus folder
sudo mv consoles/ console_libraries/ prometheus.yml /etc/prometheus/
  1. 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
  1. Reload the daemon
sudo systemctl daemon-reload
  1. Start prometheus service
sudo systemctl enable --now prometheus.service
  1. Move node-exporter to bin folder
sudo mv node_exporter-1.7.0.linux-amd64/node_exporter /usr/local/bin/ 
  1. 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
  1. Reload the daemon and start node-exporter service
sudo systemctl daemon-reload && sudo systemctl enable --now node-exporter.service
  1. 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"]
  1. Restart prometheus service
sudo systemctl restart prometheus.service

Install Grafana

  1. Install the prerequisite packages
sudo apt-get install -y apt-transport-https software-properties-common wget
  1. 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
  1. 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
  1. Update the package
sudo apt-get update
  1. Install grafana
sudo apt-get install grafana
  1. Start grafana-server service
sudo systemctl enable --now grafana-server.service
  1. Check grafana in http://localhost:3000
    Init Username: admin
    Password: admin
Last Updated: 7/20/2024, 6:59:15 AM
Contributors: azrimadit