最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Prometheus 如何采集 Windows 主机的性能指标
时间:2026-08-23 08:04:48 编辑:袖梨 来源:一聚教程网
Prometheus 依赖 Windows Exporter 采集 Windows 主机指标,后者通过 WMI/API 暴露 /metrics 接口;需安装服务、配置启用收集器(如 cpu、memory)、在 prometheus.yml 中添加 target,并可通过 Grafana 导入 ID 12907 面板可视化。
Prometheus 本身不直接采集 Windows 主机指标,必须借助 Windows Exporter(原 wmi_exporter)作为中间桥梁。它运行在 Windows 上,通过 WMI 或系统 API 获取 CPU、内存、磁盘、网络等数据,并以 Prometheus 兼容的文本格式(/metrics)通过 HTTP 暴露出来,再由 Prometheus 定期拉取。
安装并启动 Windows Exporter
这是第一步,也是最关键的环节:
- 前往 GitHub Releases 页面,下载最新版
windows_exporter-*.amd64.msi(适用于 Windows Server 2016+ 或 Win10/11 21H2+) - 以管理员身份双击安装,全程默认下一步即可
- 安装后自动注册为 Windows 服务
windows_exporter,默认监听:9182 - 验证是否正常:浏览器访问
http://localhost:9182/metrics,能看到大量以# TYPE开头的指标文本,说明服务已就绪
配置要采集的指标项
Windows Exporter 默认启用基础收集器,但建议按需精简,避免冗余指标影响性能和存储:
- 常用核心收集器包括:
cpu、logical_disk、net、os、system、memory、service - 禁用不需要的项,例如光驱监控:
--collector.logical_disk.ignore-disk-types="CDROM" - 可通过命令行参数启动(如 PowerShell 中):
.windows_exporter.exe --collectors.enabled="cpu,logical_disk,net,os,system,memory" --web.listen-address=":9182" - 也可创建
config.yaml文件统一管理,更利于批量部署
让 Prometheus 抓取这些指标
修改 Prometheus 的配置文件 prometheus.yml,添加 Windows 主机目标:
- 在
scrape_configs下新增一个 job,例如:
- job_name: "windows"static_configs:- targets: ["192.168.1.100:9182"]# 替换为实际 Windows 主机 IPmetrics_path: /metrics
- 保存后重启 Prometheus,或发送 SIGHUP 重载配置
- 访问
http://localhost:9090/targets,确认该 target 状态为 UP - 在
http://localhost:9090/graph输入windows_cpu_usage_percent或windows_logical_disk_free_bytes等指标名,可查到实时数据
搭配 Grafana 做可视化展示
有了指标数据,下一步就是直观呈现:
- 启动 Grafana(如解压后运行
bingrafana-server.exe),访问http://localhost:3000 - 添加 Prometheus 数据源(URL 填
http://localhost:9090) - 导入社区成熟的 Windows 监控面板,例如 ID 为
12907的 Windows Exporter Full,它已预置 CPU、内存、磁盘、服务状态等关键视图 - 面板会自动识别你采集的指标,无需手动写太多 PromQL,开箱即用