# ============================================================================== # Watch-StressLive.ps1 - Live Interactive Dashboard for ClassNotify Stability Harness # ============================================================================== [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 try { $Host.UI.RawUI.WindowTitle = "ClassNotify 稳定性压测实时监控看板 (Live HUD)" } catch {} $harnessSessions = "C:\ProgramData\ClassNotify-TestHarness\sessions" function Format-Sec($s) { if ($null -eq $s -or $s -eq 0) { return "0.00s" } return ("{0:N2}s" -f [double]$s) } while ($true) { $latestStateFile = Get-ChildItem -Path $harnessSessions -Filter "session-state.json" -Recurse -ErrorAction SilentlyContinue | Sort-Object LastWriteTime -Descending | Select-Object -First 1 -ExpandProperty FullName if (-not $latestStateFile -or -not (Test-Path $latestStateFile)) { Clear-Host Write-Host "==============================================================================" -ForegroundColor Cyan Write-Host " ClassNotify 稳定性压测实时监控看板 (Live HUD) " -ForegroundColor Cyan Write-Host "==============================================================================" -ForegroundColor Cyan Write-Host "`n[等待中] 正在检测压测会话,未发现正在运行的 session-state.json..." -ForegroundColor Yellow Start-Sleep -Seconds 2 continue } try { $raw = [System.IO.File]::ReadAllText($latestStateFile, [System.Text.Encoding]::UTF8) $state = $raw | ConvertFrom-Json } catch { Start-Sleep -Milliseconds 500 continue } $startTime = [DateTime]::Parse($state.startedUtc).ToLocalTime() $elapsed = (Get-Date) - $startTime $elapsedStr = ("{0:D2}h {1:D2}m {2:D2}s" -f [int]$elapsed.TotalHours, $elapsed.Minutes, $elapsed.Seconds) $percent = [Math]::Min(100.0, [Math]::Round(($elapsed.TotalMinutes / 360.0) * 100, 1)) Clear-Host Write-Host "==============================================================================" -ForegroundColor Cyan Write-Host " ClassNotify 稳定性压测实时监控看板 (Live HUD) " -ForegroundColor Cyan Write-Host "==============================================================================" -ForegroundColor Cyan Write-Host (" 会话编号: {0,-28} 当前阶段: {1}" -f $state.sessionId, $state.currentPhase) -ForegroundColor White Write-Host (" 启动时间: {0,-28} 持续时间: {1} (目标: 06h 00m)" -f $startTime.ToString("yyyy-MM-dd HH:mm:ss"), $elapsedStr) -ForegroundColor White # Progress Bar $barWidth = 40 $completedWidth = [int](($percent / 100.0) * $barWidth) $bar = ("#" * $completedWidth) + ("-" * ($barWidth - $completedWidth)) Write-Host (" 物理进度: [{0}] {1,5}%" -f $bar, $percent) -ForegroundColor Green Write-Host "------------------------------------------------------------------------------" -ForegroundColor DarkGray # Key Metrics Write-Host " [业务指标]" -ForegroundColor Yellow Write-Host (" 已发送通知: {0,-8} 已确认(ACK): {1,-8} 丢失率: {2}" -f $state.stats.NotificationsSent, $state.stats.NotificationsAcked, $state.stats.NotificationsLost) Write-Host "`n [故障注入与自愈 (Part A)]" -ForegroundColor Yellow $wpfRec = "$($state.stats.WpfRecovered)/$($state.stats.WpfKilled)" $svcRec = "$($state.stats.ServiceRecovered)/$($state.stats.ServiceKilled)" $netRec = "$($state.stats.NetworkRecovered)/$($state.stats.NetworkCuts)" Write-Host (" WPF 客户端杀除自愈: {0,-12} (P50: {1}, P95: {2}, Max: {3})" -f $wpfRec, (Format-Sec $state.recoveryLatency.wpf.P50), (Format-Sec $state.recoveryLatency.wpf.P95), (Format-Sec $state.recoveryLatency.wpf.Max)) Write-Host (" 系统服务杀除自愈 : {0,-12} (P50: {1}, P95: {2}, Max: {3})" -f $svcRec, (Format-Sec $state.recoveryLatency.service.P50), (Format-Sec $state.recoveryLatency.service.P95), (Format-Sec $state.recoveryLatency.service.Max)) Write-Host (" 网络阻断与恢复 : {0,-12}" -f $netRec) Write-Host (" 升降级演练成功 : {0} 升级 / {1} 回滚" -f $state.stats.UpdatesSucceeded, $state.stats.RollbacksSucceeded) Write-Host "`n [核心六零红线监测]" -ForegroundColor Yellow $cLoss = if ($state.stats.NotificationsLost -eq 0) { "0 [PASS]" } else { "$($state.stats.NotificationsLost) [FAIL]" } $cLie = if ($state.stats.StateLies -eq 0) { "0 [PASS]" } else { "$($state.stats.StateLies) [FAIL]" } $cMan = if ($state.stats.ManualActionsRequired -eq 0) { "0 [PASS]" } else { "$($state.stats.ManualActionsRequired) [FAIL]" } $cCred = if ($state.stats.CredentialLoss -eq 0) { "0 [PASS]" } else { "$($state.stats.CredentialLoss) [FAIL]" } $cEsc = if ($state.stats.CanaryEscapes -eq 0) { "0 [PASS]" } else { "$($state.stats.CanaryEscapes) [FAIL]" } Write-Host (" 永久丢消息: {0,-16} 假健康/撒谎: {1,-16} 人工干预: {2}" -f $cLoss, $cLie, $cMan) -ForegroundColor Green Write-Host (" 凭证丢失 : {0,-16} 灰度逃逸 : {1}" -f $cCred, $cEsc) -ForegroundColor Green Write-Host "------------------------------------------------------------------------------" -ForegroundColor DarkGray Write-Host " [最近 5 条实机事件日志]" -ForegroundColor Cyan $logs = @($state.eventLog) $lastLogs = $logs | Select-Object -Last 5 foreach ($lg in $lastLogs) { $color = switch ($lg.Level) { "Success" { "Green" } "Error" { "Red" } "Warning" { "Yellow" } Default { "Gray" } } $timeStr = [DateTime]::Parse($lg.TimestampUtc).ToLocalTime().ToString("HH:mm:ss") Write-Host (" [{0}] [{1,-7}] {2}" -f $timeStr, $lg.Level, $lg.Message) -ForegroundColor $color } Write-Host "==============================================================================" -ForegroundColor Cyan Write-Host " 提示: 压测在后台全自动执行,此窗口仅作为实时看板。按 Ctrl+C 可关闭看板(不影响后台压测)。" -ForegroundColor DarkGray if ($state.currentPhase -eq "Completed") { Write-Host "`n[完成] 压测已全部执行完毕!" -ForegroundColor Green break } Start-Sleep -Seconds 2 }