1. 程式人生 > 其它 >Prometheus監控部署使用node-exporter監控主機

Prometheus監控部署使用node-exporter監控主機

Prometheus監控部署

前提條件

  • 已部署docker
  • 已部署grafana
  • 需要開放 3000 9100 和 9090 埠

啟動node-exporter

docker run --name node-exporter -d  \
  --restart=always \
  -p 9100:9100 \
  -v "/proc:/host/proc:ro" \
  -v "/sys:/host/sys:ro" \
  -v "/:/rootfs:ro" \
  --net="host" \
  prom/node-exporter

啟動prometheus

新建目錄prometheus,編輯配置檔案prometheus.yml

mkdir /opt/prometheus
cd /opt/prometheus/
vim prometheus.yml

內容如下:

global:
  scrape_interval:     60s
  evaluation_interval: 60s

scrape_configs:
  - job_name: prometheus
    static_configs:
      - targets: ['localhost:9090']
        labels:
          instance: prometheus

  - job_name: Host monitoring
    static_configs:
      - targets: ['192.168.3.101:9100']
        labels:
          instance: localhost

注意:修改IP地址,這裡的192.168.3.101就是本機地址

啟動prometheus

docker run  --name prometheus -d  \
  --restart=always \
  -p 9090:9090 \
  -v /opt/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml  \
  prom/prometheus

訪問prometheus web頁面

瀏覽器輸入 http://192.168.91.132:9090 ;點選 Status-->Targets 訪問Targets效果如下:

如果狀態沒有UP起來,請等待2分鐘左右。

新增資料來源

訪問grafana web介面,新增資料來源

點選Data Source, 選擇Add data source

選擇Prometheus,在URL中填寫Prometheus的訪問地址,點選Save & Test,出現綠色提示,則新增成功

匯入Dashboard

資源下載地址:https://goodrain-delivery.oss-cn-hangzhou.aliyuncs.com/zhonggonggaoke/nodeexporter.json

將該json檔案上傳至grafana,點選import即可

監控頁面