一、安裝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機器,配置完成。
