如何安装和配置Windows Exporter

更新时间:
复制 MD 格式

本文介绍如何安装和配置Windows Exporter。

步骤一:安装Windows Exporter

  1. 以管理员身份登录Windows系统。

  2. 下载Windows ExporterECSWindows系统内。

  3. 鼠标双击上一步骤中下载的安装包文件windows_exporter-1.22.0-amd64.msi,或者执行命令msiexec /i windows_exporter-1.22.0-amd64.msi,即可完成安装。

    • 默认安装到C:\Program Files (x86)\windows_exporter目录。

    • 默认监听端口是9182。

    • 默认采集指标:cpu、cpu_info、memory、process、tcp、cs、logical_disk、net、os、system、textfile、time。

    配置文件 config.yml 的内容示例:

    
    collectors:
     enabled: cpu,cpu_info,memory,process,tcp,cs,logical_disk,net,os,system,time,logon,textfile
    collector:
     scheduled_task:
      blacklist: /Microsoft/.+
    log:
     level: info
    scrape:
     timeout-margin: 0.5
    telemetry:
     addr: ":9182"
     path: /metrics
     max-requests: 5
    

    安装完成后,windows_exporter 自动注册为 Windows 服务,启动类型为自动,服务状态为正在运行。可通过服务管理控制台(services.msc)确认。

  4. 确认Exporter是否正常工作。即执行命令curl localhost:{监听端口}/metrics或者通过浏览器访问localhost:{监听端口}/metrics,观察是否有正常的Prometheus Metric返回。如果有正常的Metric返回,说明Exporter已正常工作。

    监听端口:需要替换为您实际的监听端口。

    安装目录 C:\Program Files (x86)\windows_exporter 包含 textfile_inputs 文件夹、config.yml 和 windows_exporter.exe。config.yml 配置示例:

    
    collectors:
      enabled: cpu,cpu_info,memory,process,tcp,cs,logical_disk,net,os,system,time,logon,textfile
    collector:
      scheduled_task:
        blacklist: /Microsoft/.+
    log:
      level: info
    scrape:
      timeout-margin: 0.5
    telemetry:
      addr: ":9182"
      path: /metrics
      max-requests: 5
    

    通过浏览器访问 http://localhost:9182/metrics 验证 Exporter 运行正常,返回 Prometheus 格式指标:

    
    # HELP go_gc_duration_seconds A summary of the pause duration of garbage collection cycles.
    # TYPE go_gc_duration_seconds summary
    go_gc_duration_seconds{quantile="0"} 0
    go_gc_duration_seconds{quantile="0.25"} 0
    go_gc_duration_seconds{quantile="0.5"} 0
    go_gc_duration_seconds{quantile="0.75"} 0.0002118
    go_gc_duration_seconds{quantile="1"} 0.0007327
    go_gc_duration_seconds_sum 0.0031355
    go_gc_duration_seconds_count 24
    # HELP go_goroutines Number of goroutines that currently exist.
    # TYPE go_goroutines gauge
    go_goroutines 14
    # HELP go_info Information about the Go environment.
    # TYPE go_info gauge
    go_info{version="go1.19.6"} 1
    # HELP go_memstats_alloc_bytes Number of bytes allocated and still in use.
    # TYPE go_memstats_alloc_bytes gauge
    go_memstats_alloc_bytes 4.227856e+06
    # HELP go_memstats_alloc_bytes_total Total number of bytes allocated, even if freed.
    # TYPE go_memstats_alloc_bytes_total counter
    go_memstats_alloc_bytes_total 3.5879624e+07
    # HELP go_memstats_buck_hash_sys_bytes Number of bytes used by the profiling bucket hash table.
    # TYPE go_memstats_buck_hash_sys_bytes gauge
    go_memstats_buck_hash_sys_bytes 1.46185e+06
    # HELP go_memstats_frees_total Total number of frees.
    # TYPE go_memstats_frees_total counter
    go_memstats_frees_total 80306
    # HELP go_memstats_gc_sys_bytes Number of bytes used for garbage collection system metadata.
    # TYPE go_memstats_gc_sys_bytes gauge
    go_memstats_gc_sys_bytes 7.639728e+06
    # HELP go_memstats_heap_alloc_bytes Number of heap bytes allocated and still in use.
    # TYPE go_memstats_heap_alloc_bytes gauge
    go_memstats_heap_alloc_bytes 4.227856e+06
    # HELP go_memstats_heap_idle_bytes Number of heap bytes waiting to be used.
    # TYPE go_memstats_heap_idle_bytes gauge
    go_memstats_heap_idle_bytes 5.767168e+06
    # HELP go_memstats_heap_inuse_bytes Number of heap bytes that are in use.
    # TYPE go_memstats_heap_inuse_bytes gauge
    go_memstats_heap_inuse_bytes 6.520832e+06
    # HELP go_memstats_heap_objects Number of allocated objects.
    # TYPE go_memstats_heap_objects gauge
    go_memstats_heap_objects 17582
    # HELP go_memstats_heap_released_bytes Number of heap bytes released to OS.
    # TYPE go_memstats_heap_released_bytes gauge
    go_memstats_heap_released_bytes 5.767168e+06
    

步骤二:配置Windows Exporter

您可以根据业务监控需求,修改Config配置文件,例如修改端口、增加或删除监控项等。具体详情,请参见Windows Exporter官方文档。修改Config后,您需要执行命令sc stop windows_exporter && sc start windows_exporter或者通过Windows服务控制台,重启Exporter Service。在 Windows 服务管理控制台中,右键单击 windows_exporter 服务,选择所有任务(K) > 重新启动(E),重启该服务。

步骤三:配置ECS的标签

可观测监控 Prometheus 版可以通过识别ECS的标签实现服务发现(Service Discovery),因此您需要在Windows ECS上配置标签{自定义标签}:{自定义标签值},例如:ecs_os:windows,以便可观测监控 Prometheus 版能够识别到。如果您已经存在合适的标签来标识所有Windows ECS,则可以忽略此步骤。在 ECS 实例的实例详情页面底部的标签区域,确认已添加标签 ecs_os : windows。如需修改,可单击编辑标签

后续操作

Windows Exporter配置完成后,您可以在可观测监控 Prometheus 版控制台完成接入配置并查看其监控数据。具体操作,请参见如何使用Prometheus监控Windows