Repository navigation
Expand file tree
/
Copy pathmonitor_core.ps1
More file actions
executable file
·118 lines (100 loc) · 4.02 KB
/
Copy pathmonitor_core.ps1
File metadata and controls
executable file
·118 lines (100 loc) · 4.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/env pwsh
<#
InternetQualityMonitor Core Runner (Windows / PowerShell)
- Mirrors monitor_core.sh behavior
- Performs a measurement (collection) step, then an analysis step for the same SITUATION
Usage examples (PowerShell):
# Defaults: Situation=Unknown, Parallel=1, Iterations=1, AnalysisBatches=15
./monitor_core.ps1
# Override via parameters
./monitor_core.ps1 -Situation "Home_CorporateLaptop_CorpProxy_SequencedTest" -Parallel 2 -Iterations 1 -AnalysisBatches 15
# Or via environment variables
$env:SITUATION = "Home_CorpLaptop"; $env:PARALLEL = "2"; ./monitor_core.ps1
Prereqs:
- Go installed and on PATH
- PowerShell 7+ recommended (but script uses compatible constructs)
- Alternatively, you can run the .sh scripts using Git Bash or WSL
#>
param(
[string]$Situation,
[int]$Parallel,
[int]$Iterations,
[string]$OutDir,
[string]$OutBasename,
[string]$LogLevel,
[string]$Sites,
[string]$GoArgs,
[int]$AnalysisBatches
)
$ErrorActionPreference = "Stop"
# Resolve defaults from env or use fallbacks
if (-not $Situation) { $Situation = $env:SITUATION; if (-not $Situation) { $Situation = "Unknown" } }
if (-not $Parallel) {
if ($env:PARALLEL) { [int]$Parallel = $env:PARALLEL } else { $Parallel = 1 }
}
if (-not $Iterations) {
if ($env:ITERATIONS) { [int]$Iterations = $env:ITERATIONS } else { $Iterations = 1 }
}
if (-not $OutDir) { $OutDir = if ($env:OUT_DIR) { $env:OUT_DIR } else { $PSScriptRoot } }
if (-not $OutBasename) { $OutBasename = if ($env:OUT_BASENAME) { $env:OUT_BASENAME } else { "monitor_results" } }
if (-not $LogLevel) { $LogLevel = if ($env:LOG_LEVEL) { $env:LOG_LEVEL } else { "info" } }
if (-not $Sites) { $Sites = if ($env:SITES) { $env:SITES } else { "./sites.jsonc" } }
if (-not $GoArgs) { $GoArgs = if ($env:GO_ARGS) { $env:GO_ARGS } else { "" } }
if (-not $AnalysisBatches) { $AnalysisBatches = if ($env:ANALYSIS_BATCHES) { [int]$env:ANALYSIS_BATCHES } else { 15 } }
$env:ANALYSIS_BATCHES = "$AnalysisBatches"
# Move to repo root (script directory)
Set-Location $PSScriptRoot
# Result file path
$ResultFile = Join-Path -Path $OutDir -ChildPath ("{0}.jsonl" -f $OutBasename)
# Short host (best-effort)
$short_host = $env:COMPUTERNAME
if (-not $short_host) { $short_host = "unknown" }
$short_host = $short_host.ToLowerInvariant()
Write-Host "[core-run] situation=$Situation host=$short_host parallel=$Parallel iterations=$Iterations out=$ResultFile"
Write-Host ""
Write-Host "#########################################################"
Write-Host "# Monitorstep: Measure fresh results into new batch #"
Write-Host "#########################################################"
Write-Host "[monitor-run] parallel=$Parallel iterations=$Iterations situation='$Situation' log_level='$LogLevel' sites='$Sites' out='$ResultFile' analysis_batches=$AnalysisBatches"
Write-Host ""
# Build arg list for collection step
$collectArgs = @(
"run", "./src/main.go",
"--analyze-only=false",
"--parallel=$Parallel",
"--iterations=$Iterations",
"--situation=$Situation",
"--log-level=$LogLevel",
"--sites=$Sites",
"--out=$ResultFile"
)
if ($GoArgs) { $collectArgs += ($GoArgs -split ' ') }
# Execute collection
& go @collectArgs
$status = $LASTEXITCODE
if ($status -eq 0) {
Write-Host "[core-run] complete -> $ResultFile (appended)"
Write-Host ""
Write-Host "##############################################"
Write-Host "# Analysis step: summarize recent batches #"
Write-Host "##############################################"
Write-Host "[analysis-run] situation='$Situation' batches=$AnalysisBatches file='$ResultFile'"
Write-Host ""
$analysisArgs = @(
"run", "./src/main.go",
"--analyze-only=true",
"--analysis-batches=$AnalysisBatches",
"--situation=$Situation",
"--out=$ResultFile"
)
& go @analysisArgs
$analysisStatus = $LASTEXITCODE
if ($analysisStatus -ne 0) {
Write-Host "[analysis-run] FAILED (exit=$analysisStatus)" -ForegroundColor Red
exit $analysisStatus
}
exit 0
} else {
Write-Host "[core-run] FAILED (exit=$status)" -ForegroundColor Red
exit $status
}