1. 程式人生 > >Prometheus(二):Prometheus 監控Windows機器

Prometheus(二):Prometheus 監控Windows機器

一、安裝wmi-exporter

首先在需要監控的Windows機器上安裝wmi_exporter。wmi_exporter下載地址:https://github.com/martinlindhe/wmi_exporter/releases

 

 下載後,雙擊即可完成安裝。

完成安裝後,會自動建立一個開機自啟的服務

 

 

 

驗證服務是否啟動,預設wmi-exporter埠為9182

瀏覽器訪問  http://192.168.56.1:9182/metrics  (Windows系統IP地址:9182埠),顯示資料,則服務開啟成功。

 

 二、修改Prometheus配置

進入Prometheus的安裝資料夾,開啟Prometheus配置檔案

#  cd /usr/local/prometheus
#  vim prometheus.yml

在scrape_configs標籤下,新增以下內容,配置監控

- job_name: 'Windows'
    static_configs:
    - targets: ['192.168.56.1:9182']
      labels:
        instance: Windows

以下是Prometheus.yml 檔案全部內容

# my global config
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.
  # scrape_timeout is set to the global default (10s).

# Alertmanager configuration
alerting:
  alertmanagers:
  - static_configs:
    - targets:
      # - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'prometheus'

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
    - targets: ['localhost:9090']

  - job_name: 'Linux'
    static_configs:
    - targets: ['192.168.56.201:9100']
      labels:
        instance: Linux

  - job_name: 'Windows'
    static_configs:
    - targets: ['192.168.56.1:9182']
      labels:
        instance: Windows

儲存退出,重啟Prometheus服務

#  systemctl restart prometheus

瀏覽器訪問 http://192.168.56.200:9090/targets  檢視監控資訊

 

 可以看到,Windows機器已經加入進來。

三、配置Grafana

新增dashboard

Grafana官方為我們提供了很多dashboard頁面,可直接下載使用。瀏覽器訪問 https://grafana.com/grafana/dashboards 下載所需要的dashboard頁面

此處我們使用Windows 監控的dashboard,dashboard Id為:10467

 

 然後開啟我們的Grafana監控頁面,開啟dashboard的管理頁面

 

 

 

 點選【import】按鈕

 

 然後將我們剛才的dashboard Id (10467) 複製進去

 

 Grafana會自動識別dashboard Id 。

然後點選【change】按鈕,生成一個隨機的UID,然後點選下方輸入框,選擇我們之前建立的資料來源Prometheus,最後點選【Import】按鈕,即可完成匯入。

 

 匯入成功後,會自動開啟該Dashboard,即可看到我們剛才設定好的Windows監控

 

 至此Prometheus監控Windows機器,配置完成。