windows_exporter部署
1、下载部署文件
https://github.com/prometheus-community/windows_exporter
2、部署
把 windows_exporter-0.25.1-amd64.exe 拷贝到C盘根目录下
管理员方式运行CMD
sc create windows_exporter binpath= C:\windows_exporter-0.25.1-amd64.exe type= own start= auto displayname= windows_exporter
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=10.0.0.1:端口
这里的IP地址,可以写虚拟机的实际IP地址
3、删除部署服务
如果想删除这个服务,只需要在服务列表里面将此服务停掉,然后服务启动设置为手动,最后在cmd命令行窗口输入下面的命令,即可删除服务。
sc delete windows_exporter
4、采集指标
名称 | 说明 | 是否默认开启 |
---|---|---|
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 | × |
5、配置其他指标
默认收集只收集了cpu,cs,logical_disk,net,os,service,system,textfile相关的指标,若要开启其他的,需配置—collectors.enabled
1.新增C:\config.yml文件
collectors:
enabled: "[defaults],process,cpu_info,memory,remote_fx,tcp"
collector:
service:
services-where: "Name='windows_exporter'"
log:
level: warn
2.修改windows启动参数
sc config windows_exporter binPath= "\"C:\windows_exporter-0.25.1-amd64.exe\" --config.file=\"C:\config.yml\" "
3.重启windows_exporter服务
sc stop windows_exporter
sc start windows_exporter
6、批处理安装脚本
@ECHO OFF
mode con cols=60 lines=20
setlocal EnableDelayedExpansion
color 0E
title windows_exporter配置
PUSHD %~DP0 & cd /d "%~dp0"
%1 %2
mshta vbscript:createobject("shell.application").shellexecute("%~s0","goto :runas","","runas",1)(window.close)&goto :eof
:runas
::上面是以管理员模式运行
::下面是填写自己的脚本
cls
::启动windows_exporter
set exporter=windows_exporter-0.25.1-amd64.exe
set port=9180
set serve=windows_exporter
set remote_ip=10.201.216.85
echo 设置windows_exporter为服务
sc create %serve% binPath= "\"C:\%exporter%\" --web.listen-address=:%port%" type= own start= auto displayname= %serve%
echo 启动服务
REM 检查服务是否已存在并尝试启动
sc query %serve% | findstr /I "RUNNING" > nul
if %errorlevel% NEQ 0 (
REM 服务没有启动,正在启动中...
net start %serve%
) else (
REM 服务已经停止中.
net stop %serve%
sc config %serve% binPath= "\"C:\%exporter%\" --web.listen-address=:%port%" type= own start= auto displayname= %serve%
REM 服务已经重新启动中.
net start %serve%
)
::添加防火墙action=block禁止 allow允许
netsh advfirewall firewall delete rule name="%serve%"
echo 防火墙添加 远程端口%port% 成功
netsh advfirewall firewall add rule name="%serve%" dir=in action=allow protocol=tcp localport=%port% remoteip=%remote_ip%
echo.
echo 部署完成按任意键关闭
pause >nul
del /f %~f0