38 lines
1.1 KiB
PowerShell
38 lines
1.1 KiB
PowerShell
param(
|
|
[int]$Port = 8789
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
$serverScript = Join-Path $scriptDir "serve-metrics-http.ps1"
|
|
$pidFile = Join-Path $scriptDir "metrics-http.pid"
|
|
$logFile = Join-Path $scriptDir "metrics-http.log"
|
|
$errFile = Join-Path $scriptDir "metrics-http.err.log"
|
|
|
|
if (Test-Path $pidFile) {
|
|
$oldPid = Get-Content $pidFile -ErrorAction SilentlyContinue
|
|
if ($oldPid -and (Get-Process -Id ([int]$oldPid) -ErrorAction SilentlyContinue)) {
|
|
Write-Host "Metrics HTTP server is already running. PID: $oldPid"
|
|
exit 0
|
|
}
|
|
}
|
|
|
|
$args = @(
|
|
"-NoProfile",
|
|
"-ExecutionPolicy", "Bypass",
|
|
"-File", "`"$serverScript`"",
|
|
"-Port", $Port
|
|
)
|
|
|
|
$process = Start-Process powershell.exe `
|
|
-ArgumentList $args `
|
|
-WindowStyle Hidden `
|
|
-RedirectStandardOutput $logFile `
|
|
-RedirectStandardError $errFile `
|
|
-PassThru
|
|
|
|
Set-Content -Path $pidFile -Value $process.Id -Encoding ascii
|
|
Write-Host "Metrics HTTP server started. PID: $($process.Id)"
|
|
Write-Host "URL: http://0.0.0.0:$Port/metrics.txt"
|