Prometheus 監控windows 主機和服務

一 安裝exporter

下載exporter:
https://github.com/martinlindhe/wmi_exporter

在windows服務執行:

.\wmi_exporter-0.11.1-amd64.exe --collector.service.services-where="Name LIKE 'MySql%' or Name='RemoteRegistry'"

可以將其註冊成服務隨windows系統啓動自動啓動

官網上有個例子使用msi文件安裝成服務,並設置擴展參數。但是在我的服務器上執行不成功(使用cmd執行時不成功,沒有使用powershell測試)。

msiexec /i <path-to-msi-file> ENABLED_COLLECTORS=os,service --% EXTRA_FLAGS="--collector.service.services-where ""Name LIKE 'sql%'"""

所以我是通過其它方式將其註冊成windows服務的,參見另外一篇博客。

二 添加到Prometheus,並配置告警規則

vim prometheus.yml

  - job_name: 'win-exporter'
    static_configs:
      - targets: ['192.168.0.100:9182']

vim rules/alert.rules

 - name: WindwosService
   rules:
   - alert: WindowsServiceDown 
     expr: wmi_service_state{state="running"} == 0
     for: 2m
     labels:
      team: node
     annotations:
      summary: "Host:{{$labels.instance}}; Service:{{$labels.name}} has been down 2 minutes!"
      description: "Host:{{$labels.instance}}; Service:{{$labels.name}} has been down 2 minutes!"
      value: "{{$value}}"

三 配置grafana

下載dashboard,並導入到grafana
https://grafana.com/grafana/dashboards/2129

這個dashboard只顯示service的概覽,沒有明細,如每個服務名和狀態。可以自己創建一個。

默認dashboard
在這裏插入圖片描述
自定義dashboard,當服務狀態正常時顯示綠色OK,當服務狀態異常時顯示紅色ERROR。
在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章