#'------------------------------------------------------------------------- #' end2dend-file #' #' Beschreibung #' Schreibt kontinuierlich in eine Datei und misst die Dauer dafür #' #' Vorgehensweise #' - Initialisiert einen String mit vorgegebener Größe und schreibt diesen mit einstellbarer Pause auf die Festplatte #' #' Voraussetzung #' - Schreibrechte im Zielverzeichnis #' #' 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) #' #' Version 1.0 (09. Nov 2007 ) #' Erste Version abgeleitet von DiskTest 1.1 #' Version 1.1 (14. Dez 2007 ) #' Mehr Detailausgabe #' Version 1.2 (24. Jul 2010) #' parametrisierung #' Version 1.3 (01. Jul 2012) # bugfixing. #' Version 1.4 (15. Jan 2013) # undefined variables, missing brackes result in wrong counting of max and median, SMTPMail #' Version 1.4 (05. Jul 2015) # Umstellen auf ByteBuffer und schreiben mit [system.io.file] # 20190722 FC Umstellung Testfile auf aktuelles Verzeichnis, kleinere CodeFixes, bessere Ausgabe uafauf Bildschirm und CSV #'------------------------------------------------------------------------- [Cmdletbinding()] param( [string]$Testfilename = '.\end2end-file.tmp', # testfile to write, can be any UNC or local path [string]$Reportfilename = 'end2end-file.csv', # CSVFile to write results [ValidateRange(0,65535)] [long]$IdleTime = 100, # time in MS to sleep between two writes [ValidateRange(0,65535)] [long]$samples = 10, # nuber of samples to generate output [ValidateRange(0,([long]::Maxvalue))] [long]$Buffersize = 1024, # size in bytes of buffer to write [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="" ) Set-PSDebug -strict $ErrorActionPreference = "Continue"; $verbosepreference = "SilentlyContinue"; #$verbosepreference = "Continue"; $DebugPreference = "SilentlyContinue"; #$DebugPreference = "Continue"; $WarningPreference="Continue"; $Error.Clear(); #Write-EventLog -Message "End2End-File started with $Testfilename" -EntryType Information -EventId 0 -Source end2end-File -LogName Application write-host "end2end-file: gestartet" write-host "end2end-file: testfile :" $Testfilename write-host "end2end-file: reportfile:" $Reportfilename write-host "end2end-file: idletime :" $IdleTime write-host "end2end-file: Samples :" $samples write-host "end2end-file: buffersize:" $Buffersize write-host "end2end-file: alarmdelta:" $Alarmdelta $host.ui.RawUI.WindowTitle = "End2End-File" write-host "end2end-file: Initialize Buffer START" [string]$buffer="end2end-file:" [string]$buffer = ([System.String]$buffer).PadLeft(($Buffersize-13),"a") #$buffer2 = [system.text.encoding]::ASCII.GetBytes($buffer); write-host "end2end-file: 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 { $performance = (measure-command { $buffer | Out-File -FilePath $Testfilename }).Milliseconds } catch { #write-host "E" -NoNewline -ForegroundColor red $summary.fail++ $summary.status="FAIL" } #[system.io.file]::WriteAllBytes($Testfilename,$buffer2) # ca 1ms lokal if (!($summary.status -eq "FAIL")) { if ($summary.avg -eq 0 ) { $summary.avg = $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 Buffersize: `t" + $Buffersize + " Bytes `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-File -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 = $summary.avg + ($performance - $summary.avg)/10 # verschiebe mittelwert median by 10% } } if ($performance -gt $summary.max){ $summary.max = $performance } if ($performance -lt $summary.min){ $summary.min = $performance } if ($summary.count -gt $samples) { " Min/Avg/Max:$($summary.min)/$($summary.avg.tostring(000))/$($summary.max) Speed:{0:N2} MB/Sek" -f ($buffersize/($summary.avg+0.1)) $summary | export-csv -path $Reportfilename -append -notypeinformation $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-File: End"