#'------------------------------------------------------------------------- #' end2end-cpu #' #' Beschreibung #' Einfache CPU rechnung mit misst die Zeit. Wenn die CPU anderweitig beschäftigt ist, dauert auch der Test länger #' #' Achtung: Das Skript kann nur mit CTRL-C abgebrochen werden #' Timer() gibt die milliseconds zwischen 00:00 und der aufrufzeit in Sekunden zur+ck (single) #' #' 20190723 Erste Version abgeleitet von end2end-file #'------------------------------------------------------------------------- [Cmdletbinding()] param( [string]$Reportfilename = 'end2end-cpu.csv', # CSVFile to write results [ValidateRange(0,65535)] [long]$IdleTime = 200, # time in MS to sleep between two writes [ValidateRange(0,65535)] [long]$samples = 10, # nuber of samples to generate output [ValidateRange(0,65535)] [long]$Alarmdelta = 1000, # limit in ms to reach for triggering an alarm [string]$smtpserver="", # Specify SMTP-Servername, sender and recipient to get a message [string]$smtpfrom="", [string]$smtpto="", [switch]$sendtopipeline = $false ) Set-PSDebug -strict $ErrorActionPreference = "Continue"; $verbosepreference = "SilentlyContinue"; #$verbosepreference = "Continue"; $DebugPreference = "SilentlyContinue"; #$DebugPreference = "Continue"; $WarningPreference="Continue"; $Error.Clear(); #Write-EventLog -Message "end2end-cpu started with $Testfilename" -EntryType Information -EventId 0 -Source end2end-cpu -LogName Application write-host "end2end-cpu: gestartet" write-host "end2end-cpu: reportfile:" $Reportfilename write-host "end2end-cpu: idletime :" $IdleTime write-host "end2end-cpu: Samples :" $samples write-host "end2end-cpu: alarmdelta:" $Alarmdelta $host.ui.RawUI.WindowTitle = "end2end-cpu" write-host "end2end-cpu: Start Loop to write... Press X to end script" [string]$processindicator=".|/-\" $summary = [pscustomobject][ordered] @{ timestamp = ((get-date).ToUniversalTime().tostring("u")) count = [int]0 min=[int]::Maxvalue avg=[int]0 max=[int]0 slow=[int]0 fail=[int]0 lastperformance=[long]0 status="OK" } $summary.status="START" $summary | export-csv -path $Reportfilename -append -notypeinformation $summary.status="RUN" [bool]$abbruch = $False while (!$abbruch) { $summary.count++ $summary.status = "OK" Write-Host "`r" -nonewline #`b`b`b`b`b`b" -ForegroundColor Green -nonewline write-host "$($summary.count.tostring("0000")) " -ForegroundColor green -nonewline write-host "$($summary.slow.tostring("0000")) " -ForegroundColor yellow -nonewline write-host "$($summary.fail.tostring("0000")) " -ForegroundColor red -nonewline Write-host "$($processindicator[$summary.count%$processindicator.Length])" -nonewline # Write Testfile and measure tome try { $count = 0 $performance = (measure-command {1..1000| ForEach-Object {$count++}}).totalmilliseconds } catch { #write-host "E" -NoNewline -ForegroundColor red $summary.fail++ $summary.status="FAIL" } if (!($summary.status -eq "FAIL")) { if ($summary.avg -eq 0 ) { $summary.avg = [int]$performance # First run } else { if (($performance - $summary.avg) -gt $Alarmdelta) { $message = "Diskprobe ALARM: Fileaccess exceeded limit `r`n" $summary.status="SLOW" $message = $message + "`t Mittelwert: `t" + ($summary.avg/1000) + "s `r`n" $message = $message + "`t Aktueller Wert: `t" + $performance/1000 + "s `r`n" $message = $message + "`t Alarmdelta: `t" + $alarmdelta/1000 + " s `r`n" $message = $message + "`t Idletime: `t" + $IdleTime + " s `r`n" $message = $message + "`t Testfilename: `t" + $Testfilename + " s" #write-host "S" -ForegroundColor yellow $summary.slow++ #write-host $message #Write-EventLog -Message $message -EntryType Warning -EventId 2 -Source end2end-cpu -LogName Application if ($smtpserver -ne "") { write-host "Sending SMTP-Alertmessage" Send-MailMessage ` -SmtpServer $smtpserver ` -From $smtpfrom ` -To $smtptp ` -Subject "End2EndFile Alarm" ` -Body $message } if ($Reportfilename -ne ""){ write-verbose " Export Data to ArchivCSV $($Reportfilename)" $summary.status="Slow" $summary | export-csv -path $Reportfilename -append -notypeinformation $summary.status="OK" } } else { $summary.avg = [int]( $summary.avg + ($performance - $summary.avg)/10) # verschiebe mittelwert median by 10% } } if ($performance -gt $summary.max){ $summary.max = [int]$performance } if ($performance -lt $summary.min){ $summary.min = [int]$performance } if ($summary.count -ge $samples) { write-host " Min/Avg/Max:$($summary.min.tostring(""0""))/$($summary.avg.tostring(""0""))/$($summary.max.tostring(""0""))" if ($Reportfilename -ne "") { $summary | export-csv -path $Reportfilename -append -notypeinformation } if ($sendtopipeline) { $summary } $summary.timestamp = ((get-date).ToUniversalTime().tostring("u")) $summary.count = 0 $summary.max = 0 $summary.avg=0 $summary.slow=0 $summary.fail=0 $summary.min=[int]::Maxvalue } } Start-Sleep -Milliseconds $IdleTime # check for exit condition if ([console]::KeyAvailable) { if (([system.console]::readkey($true)).key -eq "X") { Write-host "Key X detected - shutting down" $abbruch = $True } else { write-host "Press X to terminate" } } } $summary.status="END" $summary | export-csv -path $Reportfilename -append -notypeinformation Write-host "end2end-cpu: End"