Install Node-exporter

Page content

Install node-exporter to provides detailed information about the system, including CPU, disk, and memory usage.

Download Node-exporter

cd /tmp
wget https://github.com/prometheus/node_exporter/releases/download/v0.16.0/node_exporter-0.16.0.linux-amd64.tar.gz
tar -xzf node_exporter-0.16.0.linux-amd64.tar.gz

Install binaris

sudo useradd -rs /bin/false node_exporter

sudo mv node_exporter*linux-amd64/node_exporter /usr/local/bin
mkdir -p /etc/node_exporter/data

chown -R node_exporter:node_exporter /etc/node_exporter

# host role based teg
cat <<EOF > /etc/node_exporter/data/roles.prom
machine_role{role="postfix"} 1
machine_role{role="apache"} 1
EOF

Create servis for Node-exporter

cat <<EOF > /etc/systemd/system/node_exporter.service
[Unit]
Description=Node Exporter
Wants=network-online.target
After=network-online.target

[Service]
User=node_exporter
Group=node_exporter
Type=simple
ExecStart=/usr/local/bin/node_exporter --collector.textfile.directory /etc/node_exporter/data/

[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable node_exporter
systemctl start node_exporter
systemctl status node_exporter

Configure Prometheus

nano /etc/prometheus/prometheus.yml
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.

alerting:
  alertmanagers:
  - static_configs:
    - targets:
       - localhost:9093

rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

scrape_configs:
  - job_name: 'prometheus_metrics'
    scrape_interval: 5s
    static_configs:
      - targets: ['prometheus01.devopstales.intra:9090']

  - job_name: 'node_exporter_metrics'
    scrape_interval: 5s
    static_configs:
      - targets: ['prometheus01.devopstales.intra:9100']