prometheus + windows_exporter监控windows(十二)

一、下载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

名称

说明

是否默认开启

adActive Directory Domain Services×
adcsActive Directory Certificate Services×
adfsActive Directory Federation Services×
cacheCache metrics×
cpuCPU usage
cpu_infoCPU Information×
cs“Computer System” metrics(system properties, num cpu / total memory)
containerContainer metrics×
dfsrDFSR metrics×
dhcpDHCP Server×
dnsDNS Server×
exchangeExchange metrics×
hypervHyper-V hosts×
iisIIS sites and applications×
logical_diskLogical disks, disk I/O
logonUser logon sessions×
memoryMemory usage metrics×
msmqMSMQ queues×
mssqlSQL 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×
netNetwork interface I/O
osOS metrics (memory, processes, users)
processPer-process metrics×
remote_fxRemoteFX protocol (RDP) metrics×
serviceService state metrics
smtpIIS SMTP Server×
systemSystem calls
tcpTCP connections×
timeWindows Time Service×
thermalzoneThermal information×
terminal_servicesTerminal services (RDS)×
textfileRead prometheus metrics from a text file
vmwarePerformance counters installed by the Vmware Guest agent×
### 回答1: 可以使用PrometheusWindows Exporter监控Windows批处理脚本,该Exporter会收集服务器上的性能指标,并将其发送到Prometheus服务器,以便Prometheus可以对其进行监控。 ### 回答2: Prometheus是一种开源的监控解决方案,Windows_exporterPrometheus的一个工具,用于监控Windows操作系统的指标。要使用Windows_exporter监控批处理脚本,可以按照以下步骤进行操作: 1. 下载和安装Windows_exporter:访问Windows_exporter的GitHub页面,下载最新的可执行文件。 2. 配置Windows_exporter:在Windows_exporter的安装目录下,创建一个配置文件(如windows_exporter.yml),并配置要监控的批处理脚本的相关信息,例如脚本的路径等。 3. 启动Windows_exporter:使用管理员权限打开命令提示符,并导航到Windows_exporter的安装目录,执行以下命令启动Windows_exporter: ``` windows_exporter.exe --collector.batchfile.path="Path\to\script.bat" --config.windows_exporter.yml ``` 其中,--collector.batchfile.path参数指定要监控的批处理脚本的路径,--config.windows_exporter.yml参数指定配置文件的路径。 4. 配置Prometheus:在Prometheus的配置文件(prometheus.yml)中添加一个新的job,用于抓取Windows_exporter提供的指标。示例如下: ```yaml - job_name: 'windows' static_configs: - targets: ['localhost:9182'] ``` 其中,'localhost:9182'是Windows_exporter默认的监听地址,可根据实际情况进行修改。 5. 重启Prometheus:保存并关闭Prometheus的配置文件,重启Prometheus服务,使其能够加载新的配置。 6. 查看监控指标:访问Prometheus的Web界面,可以通过查询PromQL语句来查看和分析批处理脚本的监控指标。例如,查询批处理脚本执行次数的指标可以使用以下PromQL语句: ``` script_batchfile_total{job="windows"} ``` 通过这些步骤,您可以使用Windows_exporter监控批处理脚本,并通过Prometheus来收集和分析这些监控指标。 ### 回答3: Prometheus是一个开源的监控系统,可以用于监控各种应用、服务和服务器。Windows_exporterPrometheus的一个插件,可以用于监控Windows系统的各种指标。 要使用windows_exporter监控批处理脚本,首先需要在Windows系统上安装和配置Prometheuswindows_exporter。可以到Prometheus官方网站上下载最新版本的Prometheus,并按照文档中的步骤进行安装和配置。 安装好Prometheus后,需要下载并安装windows_exporter。在windows_exporter的GitHub页面上可以找到最新的发布版本。下载后,将windows_exporter解压到一个合适的目录。 接下来,需要创建一个用于监控批处理脚本的配置文件。在Prometheus的配置文件(prometheus.yml)中添加以下内容: ```yaml scrape_configs: - job_name: 'my_batch_scripts' static_configs: - targets: ['localhost:9182'] ``` 其中,job_name可以自定义,targets是windows_exporter的默认监听端口。 保存并关闭配置文件后,需要启动Prometheuswindows_exporter。在命令行中导航到Prometheus的安装目录,执行以下命令启动Prometheus: ``` prometheus.exe --config.file=prometheus.yml ``` 再打开一个新的命令行窗口,导航到windows_exporter的安装目录,执行以下命令启动windows_exporter: ``` windows_exporter.exe ``` 启动后,Prometheus将开始收集和存储windows_exporter提供的所有指标。可以通过Prometheus的Web界面(默认为localhost:9090)查看和查询这些指标。 接下来,可以根据批处理脚本的需要,编写相关的指标规则和警报规则。通过Prometheus的查询语言和警报规则语言,可以实现对批处理脚本的监控和告警。 总结来说,要使用windows_exporter监控批处理脚本,需要安装和配置Prometheuswindows_exporter,创建一个用于批处理脚本的配置文件,启动Prometheuswindows_exporter,并进行指标和警报规则的配置。通过Prometheus的Web界面进行监控和查询。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值