You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Prometheus Windows Exporter文本文件采集器指标未生效求助

Windows Exporter Textfile采集器故障排查及分辨率监控替代方案

一、Textfile采集器无指标输出的排查步骤

1. 修正配置文件路径格式

你的配置中collectors.textfile路径使用单反斜杠,Windows环境下YAML配置需处理转义问题,建议修改为以下两种格式之一:

collectors:
  enabled: cpu,cs,logical_disk,net,os,service,system,textfile,process
  textfile: C:\\win_exporter\\resolution  # 双反斜杠转义
# 或者使用正斜杠
# textfile: C:/win_exporter/resolution

2. 验证文件权限与格式

  • 权限检查:确保Windows Exporter运行用户(默认是Local System)对C:\win_exporter\resolution文件夹及其中的.prom文件有读取权限。可右键文件夹→属性→安全选项卡,添加对应用户并赋予读取权限。
  • 文件格式检查:
    • 确认文件后缀为.prom,无拼写错误。
    • 保存文件时选择UTF-8无BOM编码(Windows记事本默认UTF-8带BOM会导致解析失败)。
    • 检查指标内容无全角空格、特殊字符,空行需为半角换行。

3. 查看Debug日志定位问题

打开C:\win_exporter\windows_exporter.log,搜索textfile相关日志:

  • 若出现failed to read file类错误,说明文件读取失败,需检查路径或权限。
  • 若出现invalid metric line类错误,说明指标格式不符合Prometheus规范,需修正.prom文件内容。

4. 直接验证Metrics端点

在浏览器或curl中访问http://localhost:9082/metrics,搜索resolution_present:

  • 若能找到该指标,说明是Prometheus侧配置问题(如scrape job未正确指向9082端口、标签匹配错误)。
  • 若找不到,说明Exporter未成功采集该文件,回到前几步排查。

二、监控Windows分辨率的替代方案

1. 启用Windows Exporter内置Video采集器

Windows Exporter自带video采集器,可直接从WMI获取显卡分辨率指标,无需自定义脚本:

  • 修改配置文件,在collectors.enabled中添加video:
collectors:
  enabled: cpu,cs,logical_disk,net,os,service,system,textfile,process,video
  • 重启Windows Exporter后,访问Metrics端点可看到以下指标:
    • windows_video_current_horizontal_resolution:当前水平分辨率
    • windows_video_current_vertical_resolution:当前垂直分辨率

2. 优化自定义脚本采集

若需保留自定义逻辑,可修改PowerShell脚本确保输出格式正确,示例脚本:

# 获取当前分辨率
$resolution = Get-WmiObject -Class Win32_VideoController | Select-Object CurrentHorizontalResolution, CurrentVerticalResolution
# 生成Prometheus指标
@"
# HELP windows_desktop_resolution_horizontal Current desktop horizontal resolution
# TYPE windows_desktop_resolution_horizontal gauge
windows_desktop_resolution_horizontal $($resolution.CurrentHorizontalResolution)
# HELP windows_desktop_resolution_vertical Current desktop vertical resolution
# TYPE windows_desktop_resolution_vertical gauge
windows_desktop_resolution_vertical $($resolution.CurrentVerticalResolution)
"@ | Out-File -FilePath "C:\win_exporter\resolution\resolution.prom" -Encoding UTF8 -NoNewline

注意脚本需以管理员权限运行,且输出文件为UTF-8无BOM格式。


内容的提问来源于stack exchange,提问作者GGrela

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.21 00:07:35