[CmdletBinding()] param( [datetime]$StartDate = (Get-Date).Date.AddHours(9), [string]$SSHUser = "stressuser", [switch]$ResetKillSwitch ) Set-StrictMode -Version Latest $ErrorActionPreference = "Stop" $BasePath = $PSScriptRoot $KillFile = Join-Path $BasePath "KILL" $LogPath = Join-Path $BasePath "Logs" $RunStamp = Get-Date -Format "yyyyMMdd-HHmmss" $LogFile = Join-Path $LogPath "stress-$RunStamp.log" $VMs = @( 113..120 | ForEach-Object { "10.52.70.$_" } 113..120 | ForEach-Object { "10.52.68.$_" } ) $Schedule = @( [pscustomobject]@{ Offset = [timespan]::FromHours(0); Load = 30 } [pscustomobject]@{ Offset = [timespan]::FromHours(1); Load = 40 } [pscustomobject]@{ Offset = [timespan]::FromHours(2); Load = 50 } [pscustomobject]@{ Offset = [timespan]::FromHours(3); Load = 60 } [pscustomobject]@{ Offset = [timespan]::FromHours(4); Load = 70 } [pscustomobject]@{ Offset = [timespan]::FromHours(5); Load = 80 } [pscustomobject]@{ Offset = [timespan]::FromHours(7); Load = 70 } [pscustomobject]@{ Offset = [timespan]::FromHours(8); Load = 60 } ) $EndTime = $StartDate.AddDays(1) New-Item -ItemType Directory -Path $LogPath -Force | Out-Null function Write-Log { param([string]$Message) $line = "{0} {1}" -f (Get-Date -Format "yyyy-MM-dd HH:mm:ss"), $Message Write-Host $line Add-Content -LiteralPath $LogFile -Value $line } function Invoke-VMCommand { param( [string]$VM, [string]$Command, [switch]$Quiet ) $output = & ssh -o BatchMode=yes -o ConnectTimeout=8 "$SSHUser@$VM" $Command 2>&1 $exitCode = $LASTEXITCODE if (-not $Quiet -and $output) { $output | ForEach-Object { Write-Log "[$VM] $_" } } return $exitCode } function Stop-AllStress { param([string]$Reason) Write-Log "STOP: $Reason" foreach ($vm in $VMs) { $rc = Invoke-VMCommand -VM $vm -Command "sudo -n /usr/bin/pkill -x stress-ng || true" -Quiet if ($rc -eq 0) { Write-Log "[$vm] stress-ng beendet bzw. war nicht aktiv." } else { Write-Log "WARNUNG: [$vm] konnte nicht gestoppt werden (SSH-Code $rc)." } } } function Assert-NoKillSwitch { if (Test-Path -LiteralPath $KillFile) { throw "NOT-AUS aktiv: $KillFile" } } function Wait-Until { param([datetime]$Time) while ((Get-Date) -lt $Time) { Assert-NoKillSwitch $seconds = [math]::Min(10, [math]::Max(1, ($Time - (Get-Date)).TotalSeconds)) Start-Sleep -Seconds $seconds } } function Set-StressLoad { param([int]$Load) Assert-NoKillSwitch Write-Log "Setze CPU-Ziellast auf allen VMs auf $Load %." foreach ($vm in $VMs) { $command = "sudo -n /usr/bin/pkill -x stress-ng 2>/dev/null || true; nohup sudo -n /usr/bin/stress-ng --cpu 0 --cpu-load $Load --timeout 26h >/tmp/stress-ng.log 2>&1