prometheus监控windows系统主机
一、 windows_exporter的安装下载
- 安装包的下载
windows_exporter
官方下载地址:https://github.com/prometheus-community/windows_exporter/releases
2.windows_exporter下载完成后,双击即可运行。
默认端口是9182,在浏览器输入:localhost:9182即可打开如下页面。
为方便后续管理及使用,把windows_exporter注册为服务
3. 在注册表和服务数据库中创建windows_exporter服务项
sc create windows_exporter binpath= “C:\Program Files (x86)\windwos_exporter\windows_exporter-0.20.0-amd64.exe” type= own start= auto displayname= windows_exporter
注:binpath后接的是.exe程序所在的目录及程序名称
二、Prometheus增加windows_exporter配置
- 添加 prometheus.yml 配置: (需要注意文件格式)
- job_name: “windwos_exporter”
scrape_interval: 15s
static_configs:- targets: [“192.168.2.93:9182”,“192.168.2.94:9182”]
- 检查windows_exporter节点
重启prometheus,即可查看已经配置好的exporter
三,prometheus监控 windows主机报警规则
groups:
- 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}}"
- name: WindowsMemUsageAlerts
rules:
- alert: Windows内存使用率
expr: ((windows_cs_physical_memory_bytes - (windows_os_physical_memory_free_bytes)) /windows_cs_physical_memory_bytes) * 100 > 80
for: 1m
labels:
status: warning
annotations:
summary: "{{ $labels.instance }} 内存使用大于80%(目前使用:{{$value}}%)"
- name: WindowsDiskUsageAlerts
rules:
- alert: WindowsDiskUsage
expr: 100.0 - 100 * (windows_logical_disk_free_bytes / windows_logical_disk_size_bytes) > 85
for: 5m
labels:
severity: warning
annotations:
summary: "磁盘使用率 {{ $labels.instance }} 大于 85% (目前使用: {{ $value }}%)"
groups:
- name: WindowsCPUUsageAlerts
rules:
- alert: Windows CPU使用率
expr: 100 - (avg by (instance) (irate(windows_cpu_time_total{mode="idle"}[5m])) * 100) > 80
for: 5m
labels:
severity: warning
annotations:
description: "High CPU usage on {{ $labels.instance }}"
summary: "CPU使用率 {{ $labels.instance }} 大于 80% (current value: {{ $value }}%)"
```