Windows机器的Prometheus指标导出器
作者:Sec-Labs | 发布时间:
项目地址
https://github.com/prometheus-community/windows_exporter
小编推荐
Windows_exporter是一个用于Windows机器的Prometheus出口程序。
相关技术点
- Prometheus指标
- Windows性能计数器
- WMI
项目用途
该项目用于收集Windows机器的各种性能指标,并将这些指标以Prometheus格式提供给监控系统。它包含多个收集器,可以收集不同的指标,例如CPU使用率、内存使用率、磁盘I/O、网络I/O等。用户可以根据需要启用或禁用这些收集器。Windows_exporter使用WMI和Windows性能计数器来收集数据,并将其转换为Prometheus格式。用户可以使用Prometheus和Grafana等工具可视化和分析这些指标,以监控Windows机器的性能和健康状况。
windows_exporter
用于 Windows 机器的 Prometheus exporter。
Collectors
| 名称 | 描述 | 默认启用 |
|---|---|---|
| ad | Active Directory Domain Services | |
| adcs | Active Directory Certificate Services | |
| adfs | Active Directory Federation Services | |
| cache | 缓存指标 | |
| cpu | CPU 使用率 | ✓ |
| cpu_info | CPU 信息 | |
| cs | "计算机系统" 指标(系统属性、CPU 数量/总内存) | ✓ |
| container | 容器指标 | |
| dfsr | DFSR 指标 | |
| dhcp | DHCP 服务器 | |
| dns | DNS 服务器 | |
| exchange | Exchange 指标 | |
| fsrmquota | Microsoft 文件服务器资源管理器(FSRM) 配额采集器 | |
| hyperv | Hyper-V 主机 | |
| iis | IIS 站点和应用程序 | |
| logical_disk | 逻辑磁盘、磁盘 I/O | ✓ |
| logon | 用户登录会话 | |
| memory | 内存使用指标 | |
| mscluster_cluster | MSCluster 集群指标 | |
| mscluster_network | MSCluster 网络指标 | |
| mscluster_node | MSCluster 节点指标 | |
| mscluster_resource | MSCluster 资源指标 | |
| mscluster_resourcegroup | MSCluster 资源组指标 | |
| msmq | MSMQ 队列 | |
| mssql | SQL Server 性能对象 指标 | |
| netframework_clrexceptions | .NET Framework CLR 异常 | |
| netframework_clrinterop | .NET Framework 互操作指标 | |
| netframework_clrjit | .NET Framework JIT 指标 | |
| netframework_clrloading | .NET Framework CLR 加载指标 | |
| netframework_clrlocksandthreads | .NET Framework 锁和线程指标 | |
| netframework_clrmemory | .NET Framework 内存指标 | |
| netframework_clrremoting | .NET Framework 远程指标 | |
| netframework_clrsecurity | .NET Framework 安全检查指标 | |
| net | 网络接口 I/O | ✓ |
| os | 操作系统指标(内存、进程、用户) | ✓ |
| process | 每个进程的指标 | |
| remote_fx | RemoteFX 协议(RDP)指标 | |
| scheduled_task | 计划任务指标 | |
| service | 服务状态指标 | ✓ |
| smtp | IIS SMTP 服务器 | |
| system | 系统调用指标 | ✓ |
| tcp | TCP 连接 | |
| teradici_pcoip | Teradici PCoIP 会话指标 | |
| time | Windows 时间服务 | |
| thermalzone | 温度信息 | |
| terminal_services | 终端服务(RDS) | |
| textfile | 从文本文件中读取 Prometheus 指标 | ✓ |
| vmware_blast | VMware Blast 会话指标 | |
| vmware | Vmware Guest 代理安装的性能计数器 |
有关每个收集器报告的指标、配置设置和使用示例的更多信息,请参见每个收集器的链接文档。### 筛选启用的收集器
默认情况下,windows_exporter将公开启用收集器的所有指标。这是收集指标的推荐方式,以避免比较不同族列的指标时出现错误。
对于高级用途,可以将可选的收集器列表传递给windows_exporter以筛选指标。 collect [] 参数可以多次使用。在Prometheus配置中,您可以在scrape config下使用此语法。
params:
collect[]:
- foo
- bar
这对于使不同的Prometheus服务器从节点收集特定指标非常有用。
标志
windows_exporter接受标志以配置某些行为。下面列出了配置导出器全局行为的标志,而每个收集器特定的标志在上面的相应收集器文档中进行了记录。
| 标志 | 描述 | 默认值 |
|---|---|---|
--web.listen-address |
导出器的主机:端口。 | :9182 |
--telemetry.path |
用于显示收集指标的URL路径。 | /metrics |
--telemetry.max-requests |
最大并发请求数。 0禁用。 | 5 |
--collectors.enabled |
要使用的收集器的逗号分隔列表。使用[defaults]作为占位符,该占位符会扩展包含默认情况下启用的所有收集器。" |
[defaults] |
--collectors.print |
如果为true,则打印可用的收集器并退出。 | |
--scrape.timeout-margin |
客户端允许的超时时间减去的秒数。调整以允许考虑开销或高负载。 | 0.5 |
--web.config.file |
用于设置TLS和Auth的[Web配置][web_config] | 无 |
安装
最新版本可以从发布页面下载。
每个版本提供一个.msi安装程序。安装程序将设置windows_exporter作为Windows服务,并在Windows防火墙中创建一个例外。
如果在没有任何参数的情况下运行安装程序,则导出器将使用启用的收集器、端口等默认设置运行。以下参数可用:
| 名称 | 描述 |
|---|---|
ENABLED_COLLECTORS |
与--collectors.enabled标志相同,提供启用的收集器的逗号分隔列表 |
LISTEN_ADDR |
要绑定到的IP地址。默认为0.0.0.0 |
LISTEN_PORT |
要绑定到的端口。默认为9182。 |
METRICS_PATH |
用于服务指标的路径。默认为/metrics |
TEXTFILE_DIR |
与--collector.textfile.directory标志相同,提供一个目录,从中读取指标的文本文件 |
REMOTE_ADDR |
允许设置逗号分隔的远程IP地址以用于Windows防火墙例外(允许列表)。默认为空字符串(任何远程地址)。 |
EXTRA_FLAGS |
允许传递完整的CLI标志。默认为空字符串。 |
通过msiexec将参数发送到安装程序。示例调用:
msiexec /i <path-to-msi-file> ENABLED_COLLECTORS=os,iis LISTEN_PORT=5000
具有自定义查询的示例服务收集器。
msiexec /i <path-to-msi-file> ENABLED_COLLECTORS=os,service --% EXTRA_FLAGS="--collector.service.services-where ""Name LIKE 'sql%'"""
在某些旧版本的Windows上,您可能需要用双引号括住参数值,以使安装命令正确解析:
msiexec /i C:\Users\Administrator\Downloads\windows_exporter.msi ENABLED_COLLECTORS="ad,iis,logon,memory,process,tcp,thermalzone" TEXTFILE_DIR="C:\custom_metrics\"
Kubernetes实现
在Windows Kubernetes上安装的详细步骤请参见此处。
支持的版本
windows_exporter支持Windows Server 2008R2及更高版本和桌面Windows 7及更高版本。
用法
go get -u github.com/prometheus/promu
go get -u github.com/prometheus-community/windows_exporter
cd $env:GOPATH/src/github.com/prometheus-community/windows_exporter
promu build -v
.\windows_exporter.exe
Prometheus指标将在localhost:9182上公开。## 示例
仅启用服务收集器并指定自定义查询
.\windows_exporter.exe --collectors.enabled "service" --collector.service.services-where "Name='windows_exporter'"
仅启用进程收集器并指定自定义查询
.\windows_exporter.exe --collectors.enabled "process" --collector.process.include="firefox.+"
当有多个具有相同名称的进程时,WMI将这些进程表示为 process-name#index。因此,为了获取所有进程而不仅仅是第一个进程,正则表达式 必须使用 .+。有关更多信息,请参见 process。
使用 --collectors.enabled 参数的 [defaults]
使用 [defaults] 与 --collectors.enabled 参数一起使用,可以扩展所有默认收集器。
.\windows_exporter.exe --collectors.enabled "[defaults],process,container"
这将在默认设置之上启用额外的进程和容器收集器。
使用配置文件
可以使用 --config.file 标志指定 YAML 配置文件,例如 .\windows_exporter.exe --config.file=config.yml。如果您使用的是绝对路径,请确保引用路径,例如 .\windows_exporter.exe --config.file="C:\Program Files\windows_exporter\config.yml"。
collectors:
enabled: cpu,cs,net,service
collector:
service:
services-where: "Name='windows_exporter'"
log:
level: warn
可以在 此处 找到示例配置文件。
配置文件注意事项
配置文件值可以与 CLI 标志混合使用,例如:
.\windows_exporter.exe --collectors.enabled=cpu,logon
log:
level: debug
CLI 标志优先于在配置文件中指定的值。
许可证
根据 MIT 发布。