2020-11-30 09:31:37 +00:00
|
|
|
$ErrorActionPreference = 'Stop'
|
|
|
|
Set-StrictMode -Version 3
|
|
|
|
|
|
|
|
# cd to location of script
|
|
|
|
$script_path = $MyInvocation.MyCommand.Path
|
|
|
|
$working_dir = Split-Path $script_path
|
|
|
|
Push-Location $working_dir
|
|
|
|
|
2024-09-10 22:34:10 +00:00
|
|
|
if (-not (Test-Path -Path '..\windows_exporter.exe')) {
|
|
|
|
Write-Output "..\windows_exporter.exe not found. Consider running \`go build\` first"
|
|
|
|
}
|
|
|
|
|
2020-11-30 09:31:37 +00:00
|
|
|
$temp_dir = Join-Path $env:TEMP $(New-Guid) | ForEach-Object { mkdir $_ }
|
|
|
|
|
2020-12-02 05:10:49 +00:00
|
|
|
# Create temporary directory for textfile collector
|
|
|
|
$textfile_dir = "$($temp_dir)/textfile"
|
|
|
|
mkdir $textfile_dir | Out-Null
|
|
|
|
Copy-Item 'e2e-textfile.prom' -Destination "$($textfile_dir)/e2e-textfile.prom"
|
|
|
|
|
2020-11-30 09:31:37 +00:00
|
|
|
# Omit dynamic collector information that will change after each run
|
2024-09-10 22:34:10 +00:00
|
|
|
$skip_re = "^(go_|windows_exporter_build_info|windows_exporter_collector_duration_seconds|windows_exporter_perflib_snapshot_duration_seconds|windows_exporter_scrape_duration_seconds|process_|windows_textfile_mtime_seconds|windows_cpu|windows_cs|windows_logical_disk|windows_physical_disk|windows_memory|windows_net|windows_os|windows_process|windows_service_process|windows_system|windows_perfdata|windows_textfile_mtime_seconds)"
|
2020-11-30 09:31:37 +00:00
|
|
|
|
|
|
|
# Start process in background, awaiting HTTP requests.
|
|
|
|
# Use default collectors, port and address: http://localhost:9182/metrics
|
|
|
|
$exporter_proc = Start-Process `
|
|
|
|
-PassThru `
|
2022-02-26 08:40:05 +00:00
|
|
|
-FilePath ..\windows_exporter.exe `
|
2024-09-10 22:34:10 +00:00
|
|
|
-ArgumentList "--log.level=debug","--web.disable-exporter-metrics","--collectors.enabled=[defaults],cpu_info,textfile,process,perfdata,scheduled_task","--collector.process.include=explorer.exe","--collector.scheduled_task.include=.*WinSAT","--collector.service.include=Themes","--collector.textfile.directories=$($textfile_dir)",@"
|
|
|
|
--collector.perfdata.objects="[{\"object\":\"Processor Information\",\"instance_label\":\"core\",\"instances\":[\"*\"],\"counters\":{\"% Processor Time\":{},\"% Privileged Time\":{}}},{\"object\":\"Memory\",\"counters\":{\"Cache Faults/sec\":{\"type\":\"counter\"}}}]"
|
|
|
|
"@ `
|
2020-11-30 09:31:37 +00:00
|
|
|
-WindowStyle Hidden `
|
|
|
|
-RedirectStandardOutput "$($temp_dir)/windows_exporter.log" `
|
|
|
|
-RedirectStandardError "$($temp_dir)/windows_exporter_error.log"
|
|
|
|
|
2022-02-26 21:34:50 +00:00
|
|
|
# Exporter can take some time to start
|
2024-09-10 22:34:10 +00:00
|
|
|
for ($i=1; $i -le 1; $i++) {
|
2022-02-26 21:34:50 +00:00
|
|
|
Start-Sleep 10
|
|
|
|
|
|
|
|
$netstat_output = netstat -anp tcp | Select-String 'listening'
|
|
|
|
if ($netstat_output -like '*:9182*') {
|
2024-08-11 13:47:59 +00:00
|
|
|
break
|
2022-02-26 21:34:50 +00:00
|
|
|
}
|
|
|
|
Write-Host "Waiting for exporter to start"
|
|
|
|
}
|
2020-11-30 09:31:37 +00:00
|
|
|
|
2024-08-05 13:50:41 +00:00
|
|
|
try {
|
|
|
|
$response = Invoke-WebRequest -UseBasicParsing -URI http://127.0.0.1:9182/metrics
|
|
|
|
} catch {
|
|
|
|
Write-Host "STDOUT"
|
|
|
|
Get-Content "$($temp_dir)/windows_exporter.log"
|
|
|
|
Write-Host "STDERR"
|
|
|
|
Get-Content "$($temp_dir)/windows_exporter_error.log"
|
|
|
|
|
|
|
|
throw $_
|
|
|
|
}
|
2020-11-30 09:31:37 +00:00
|
|
|
# Response output must be split and saved as UTF-8.
|
|
|
|
$response.content -split "[`r`n]"| Select-String -NotMatch $skip_re | Set-Content -Encoding utf8 "$($temp_dir)/e2e-output.txt"
|
2024-09-10 22:34:10 +00:00
|
|
|
try {
|
|
|
|
Stop-Process -Id $exporter_proc.Id
|
|
|
|
} catch {
|
|
|
|
Write-Host "STDOUT"
|
|
|
|
Get-Content "$($temp_dir)/windows_exporter.log"
|
|
|
|
Write-Host "STDERR"
|
|
|
|
Get-Content "$($temp_dir)/windows_exporter_error.log"
|
|
|
|
|
|
|
|
throw $_
|
|
|
|
}
|
|
|
|
|
2020-11-30 09:31:37 +00:00
|
|
|
$output_diff = Compare-Object (Get-Content 'e2e-output.txt') (Get-Content "$($temp_dir)/e2e-output.txt")
|
|
|
|
|
|
|
|
# Fail if differences in output are detected
|
|
|
|
if (-not ($null -eq $output_diff)) {
|
2024-09-10 22:34:10 +00:00
|
|
|
$output_diff | Format-Table -AutoSize | Out-String -Width 10000
|
2023-11-04 19:51:35 +00:00
|
|
|
|
|
|
|
Write-Host "STDOUT"
|
|
|
|
Get-Content "$($temp_dir)/windows_exporter.log"
|
|
|
|
Write-Host "STDERR"
|
|
|
|
Get-Content "$($temp_dir)/windows_exporter_error.log"
|
2024-08-11 13:47:59 +00:00
|
|
|
|
2024-09-10 22:34:10 +00:00
|
|
|
(Get-Content "$($temp_dir)/e2e-output.txt") | Set-Content -Encoding utf8 "e2e-output.txt"
|
|
|
|
|
2020-11-30 09:31:37 +00:00
|
|
|
exit 1
|
|
|
|
}
|