42 lines
1.2 KiB
PowerShell
42 lines
1.2 KiB
PowerShell
param(
|
|
[string]$HostName = "192.168.4.1",
|
|
[int]$Port = 80,
|
|
[double]$IntervalSeconds = 1
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
$pushScript = Join-Path $scriptDir "push-metrics-http.ps1"
|
|
$pidFile = Join-Path $scriptDir "metrics-ap-push.pid"
|
|
$logFile = Join-Path $scriptDir "metrics-ap-push.log"
|
|
$errFile = Join-Path $scriptDir "metrics-ap-push.err.log"
|
|
|
|
if (Test-Path $pidFile) {
|
|
$oldPid = Get-Content $pidFile -ErrorAction SilentlyContinue
|
|
if ($oldPid -and (Get-Process -Id ([int]$oldPid) -ErrorAction SilentlyContinue)) {
|
|
Write-Host "AP metrics push is already running. PID: $oldPid"
|
|
exit 0
|
|
}
|
|
}
|
|
|
|
$args = @(
|
|
"-NoProfile",
|
|
"-ExecutionPolicy", "Bypass",
|
|
"-File", "`"$pushScript`"",
|
|
"-HostName", $HostName,
|
|
"-Port", $Port,
|
|
"-IntervalSeconds", $IntervalSeconds
|
|
)
|
|
|
|
$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 "AP metrics push started. PID: $($process.Id)"
|
|
Write-Host "Log: $logFile"
|