一、下载windows_exporter安装包

Windows Exporter 由 Prometheus Community 维护,官方地址是:https://github.com/prometheus-community/windows_exporter 。 当前版本是 v0.22.0 ,发行于 2023.03.27。

Windows Exporter 是一个采集 Windows 机器指标的采集器。支持 Windows Server 2008R2 以上版本或者 Windows 7 以上版本。

Windows Exporter 在发布的是时候提供了两种格式的文件,分别是 *.exe 和 *.msi 。

MSI (Microsoft Installers)是 Windows 的包管理器,类似于 Linux 的 rpm 。

Windows Exporter 每个版本都提供一个 .msi 安装程序。安装程序将 windows_exporter 设置为 Windows 服务,并在 Windows 防火墙中创建一个异常。

我们在使用的时候可以选择任意一种格式来进行安装。

1、本地下载

官网下载地址:https://github.com/prometheus-community/windows_exporter/releases

下载完成后,管理员直接运行windows_exporter-0.18.1-amd64.exe文件即可。

二、将windows_exporter注册为系统服务

使用windows_exporter插件采集Windows系统(服务器)的运行数据时,可能会因为系统故障宕机,需要在宕机恢复后,再手工启动windows_exporter插件。这个场景,对于系统运维来说是挺痛苦的,因此需要实现windows_exporter的后台运行和自动启动。不过这个不能像Linux系统那样,可以通过nohup &来实现程序的后台运行。不过,将目标程序注册为Windows服务,同样快捷方便。下面介绍如何将windows_exporter注册为Windows系统服务,并实现带参数启动,以及服务自启动配置。
【备注】下面的服务配置方法,在Windows Server 2016上配置以后,服务都可以成功启动,但是无法通过浏览器访问到metrics,目前原因不明。
首先,在Windows的CMD命令行中输入下面的命令,这里需要注意的是,等号“=”与值之间有一个空格,必需要保留,如果不保留,运行会出错。
C:\Users\Administrator>sc create windows_exporter binpath= C:\windows_exporter-0.18.1-amd64.exe type= own start= auto displayname= windows_exporter
[SC] CreateService 成功

备注:

1)windows_exporter插件默认放在C盘根目录下。        

2)sc create的用法说明:

C:\Users\Administrator>sc create
描述:
        在注册表和服务数据库中创建服务项。
用法:
        sc <server> create [service name] [binPath= ] <option1> <option2>...
 
选项:
注意: 选项名称包括等号。
      等号和值之间需要一个空格。
 type= <own|share|interact|kernel|filesys|rec>
       (默认 = own)
 start= <boot|system|auto|demand|disabled|delayed-auto>
       (默认 = demand)
 error= <normal|severe|critical|ignore>
       (默认 = normal)
 binPath= <BinaryPathName>
 group= <LoadOrderGroup>
 tag= <yes|no>
 depend= <依存关系(以 / (斜杠) 分隔)>
 obj= <AccountName|ObjectName>
       (默认 = LocalSystem)
 DisplayName= <显示名称>
 password= <密码>

服务注册成功之后,我们可以在Windows服务列表里面看到我们注册的windows_exporter服务。如下图所示:

选中服务,然后在右键菜单中点击属性,在属性对话框输入启动参数:

--telemetry.addr=127.0.0.1:9182

这里的IP地址,可以写虚拟机的实际地址,我本地PC就使用127.0.0.1

然后点击启动按钮,可以发现服务成功启动,如下图所示:

为了测试windows_exporter是否可以成功采集到监控数据,我们可以在浏览器里面访问下面的地址,来观察是否有数据返回,如果有,则说明服务启动、运行成功。

http://127.0.0.1:9182/metrics

如果想删除这个服务,只需要在服务列表里面将此服务停掉,然后服务启动设置为手动,最后在cmd命令行窗口输入下面的命令,即可删除服务。

C:\Users\Administrator>sc delete windows_exporter
[SC] DeleteService 成功

三、访问Windows Exporter

windows_exporter默认端口是9182,在浏览器输入:localhost:9182即可访问。

1、采集指标

这个列表是 Windows Exporter 支持采集的指标,有一些指标是启动后缺省会打开的,有一些是需要手动打开的。
https://github.com/prometheus-community/windows_exporter

名称

说明

是否默认开启

ad Active Directory Domain Services ×
adcs Active Directory Certificate Services ×
adfs Active Directory Federation Services ×
cache Cache metrics ×
cpu CPU usage
cpu_info CPU Information ×
cs “Computer System” metrics(system properties, num cpu / total memory)
container Container metrics ×
dfsr DFSR metrics ×
dhcp DHCP Server ×
dns DNS Server ×
exchange Exchange metrics ×
hyperv Hyper-V hosts ×
iis IIS sites and applications ×
logical_disk Logical disks, disk I/O
logon User logon sessions ×
memory Memory usage metrics ×
msmq MSMQ queues ×
mssql SQL Server Performance Objects metrics ×
netframework_clrexceptions .NET Framework CLR Exceptions ×
netframework_clrinterop .NET Framework Interop Metrics ×
netframework_clrjit .NET Framework JIT metrics ×
netframework_clrloading .NET Framework CLR Loading metrics ×
netframework_clrlocksandthreads .NET Framework locks and metrics threads ×
netframework_clrmemory .NET Framework Memory metrics ×
netframework_clrremoting .NET Framework Remoting metrics ×
netframework_clrsecurity .NET Framework Security Check metrics ×
net Network interface I/O
os OS metrics (memory, processes, users)
process Per-process metrics ×
remote_fx RemoteFX protocol (RDP) metrics ×
service Service state metrics
smtp IIS SMTP Server ×
system System calls
tcp TCP connections ×
time Windows Time Service ×
thermalzone Thermal information ×
terminal_services Terminal services (RDS) ×
textfile Read prometheus metrics from a text file
vmware Performance counters installed by the Vmware Guest agent ×
Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐