windows_exporter支持自启动安装
windows_exporter-0.31.0-beta.2-amd64.exe(裸的可执行文件,而不是 .msi 安装包),需要 手动注册为 Windows 服务,使其支持 开机自启动。
一、前提准备
- 将
windows_exporter-0.31.0-beta.2-amd64.exe放到一个固定目录,例如:
C:\Program Files\windows_exporter\
- 重命名(可选,但建议):
将文件重命名为 windows_exporter.exe(简洁统一)。
二、使用 sc.exe 注册为服务
命令:
1 | sc.exe create windows_exporter ^ |
参数说明:
binPath=后面是可执行文件的完整路径(必须加双引号)start= auto表示设置为“开机自动启动”DisplayName=设置服务显示名(可选)
三、启动服务
1 | sc start windows_exporter |
或者使用 PowerShell:
1 | # 服务启动 |
四、验证是否运行成功
打开浏览器访问:
http://localhost:9182/metrics
你应该可以看到 Prometheus 格式的监控数据。
五、启用特定的 collectors
如果你只想启用指定的 metrics(比如只启用 CPU 和内存),修改 binPath:
1 | sc.exe delete windows_exporter |
然后重新启动服务。
六、卸载服务
1 | sc stop windows_exporter |
七、总结
| 步骤 | 命令 |
|---|---|
| 注册服务 | sc.exe create ... |
| 设置自启动 | start= auto |
| 启动服务 | sc start windows_exporter |
| 检查服务状态 | Get-Service windows_exporter |
| 卸载服务 | sc delete windows_exporter |