Skip to content

Instantly share code, notes, and snippets.

@stan1ey-shen
Last active March 12, 2025 10:08
Show Gist options
  • Save stan1ey-shen/0b5d658c0c5b3a92c5e0afc5ce19d30c to your computer and use it in GitHub Desktop.
Save stan1ey-shen/0b5d658c0c5b3a92c5e0afc5ce19d30c to your computer and use it in GitHub Desktop.

Grafana 監控 Node

Node Exporter 設定

Docker compose

services:
  node_exporter:
    image: quay.io/prometheus/node-exporter:v1.9.0
    container_name: node_exporter
    command:
      - '--path.rootfs=/host'
    network_mode: host
    pid: host
    restart: unless-stopped
    ports:
      - 9100:9100
    volumes:
      - '/:/host:ro,rslave'

Linux service

  1. 在 node 產生一個使用者, 用來執行服務:
    sudo useradd -s /bin/false node-exporter
  2. 下載 node exporter
    export NODE_EXPORTER_VERSION=1.9.0 && wget https://github.com/prometheus/node_exporter/releases/download/v$NODE_EXPORTER_VERSION/node_exporter-$NODE_EXPORTER_VERSION.linux-$(dpkg --print-architecture).tar.gz
  3. 解壓縮
    tar xvf node_exporter-$NODE_EXPORTER_VERSION.linux-$(dpkg --print-architecture).tar.gz -C /opt/node_exporter
  4. 新增一個 service 執行 node-exporter - /etc/systemd/system/node_exporter.service:
    [Unit]
    Description=Node Exporter
    Wants=network-online.target
    After=network-online.target
    
    [Service]
    User=node-exporter
    Type=simple
    ExecStart=/opt/node_exporter/node_exporter --collector.systemd
    
    [Install]
    WantedBy=multi-user.target
  5. 啟動服務:
    sudo systemctl daemon-reload
    sudo systemctl enable --now node_exporter
    sudo systemctl status node_exporter
  6. 測試:
    curl http://<PVE_HOST>:9100/metrics

Prometheus 設定

新增 config 抓 node exporter:

scrape_configs:
- job_name: node
  static_configs:
  - targets: ['localhost:9100']

Grafana 設定

匯入 dashboard - Node Exporter Full ID: 1860

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment