How To Modify Collectors of Windows Exporter

Update: here’s a generalized version of this function that can be applied to other services

The follow cmdlets assumes that Prometheus Windows Exporter has already been installed. This is how to modify an existing instance:

# Example: Enabling Collectors for a Hyper-V Server
$serviceName='Windows_Exporter'
$enabledCollectors='os,cpu,cs,logical_disk,net,tcp,hyperv,service,textfile'
$wmiService=Get-WmiObject win32_service| ?{$_.Name -like "*$serviceName*"}
$exePath=[regex]::match($wmiService.PathName,'\"(.*)\"').groups[1]
$binaryPath = '\"' + $exePath + '\"' + " --log.format logger:eventlog?name=windows_exporter --collectors.enabled $enabledCollectors"
sc.exe config $serviceName binpath= $binaryPath
sc.exe qc windows_exporter
restart-service $serviceName

Leave a Reply

Your email address will not be published. Required fields are marked *