-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiskPerformance.ps1
More file actions
91 lines (67 loc) · 3.54 KB
/
DiskPerformance.ps1
File metadata and controls
91 lines (67 loc) · 3.54 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
#region Performance Measurement
$MeasureTimeSeconds=10
while ($true){
$LogicalDiskCounters = Get-Counter -ListSet "LogicalDisk" | select -expand PathsWithInstances | ? { $_ -match ":" -and ($_ -match "% Idle Time" -or $_ -match "Avg. Disk sec/Transfer" -or $_ -match "Avg. Disk Bytes/Transfer" ) }
$Counters = @(
#"\TCPIP Performance Diagnostics\TCP successful loss recovery episodes" #only newer OS supports
"\TCPv4\Segments Retransmitted/sec"
"\Processor(_Total)\% Processor Time"
"\memory\page reads/sec"
"\memory\available bytes"
"\memory\long-term average standby cache lifetime (s)"
)
$counters += $LogicalDiskCounters
try {
Write-Progress -Activity "Monitoring" -Status (get-date)
#Measuring
$PerformanceData = Get-Counter -ErrorAction Stop -Counter $Counters -MaxSamples 1 -SampleInterval $MeasureTimeSeconds
#region analysis
#Get-Counter -ListSet * | select -expand Paths | select-string "logicaldisk" | select-string "bytes"
$output=[pscustomobject]@{
DateTime=(get-date)
Bottleneck=@()
Message=@()
}
#region disk analysis
$DiskCounters=$PerformanceData.CounterSamples| ? path -match "logicaldisk" | Group-Object -Property Instancename
foreach ($DiskCounter in $DiskCounters){
$DriveLetter=$DiskCounter.name
$IdleTime=$DiskCounter.Group|? path -Match "idle time" | select -ExpandProperty CookedValue
[int]$KBytesPerTransfer=($DiskCounter.Group|? path -Match "Avg. Disk Bytes/Transfer" | select -ExpandProperty CookedValue)/1024
[int]$TransferTime=($DiskCounter.Group|? path -Match "disk sec/transfer" | select -ExpandProperty CookedValue)*1000
if ($IdleTime -lt 5 -and $TransferTime -gt 10){
$output.Bottleneck+="Disk $DriveLetter"
$output.message+="$DriveLetter idletime: $IdleTime%. $TransferTime ms. Bytes pr transfer: $KBytesPerTransfer KB"
}
}
#endregion
#region CPU
[int]$CPUUtil=$PerformanceData.CounterSamples|? path -Match "% processor time" | select -ExpandProperty CookedValue
if ($CPUUtil -gt 75){
$output.Bottleneck+="CPU"
$output.message+="CPU Utilization is $CPUUtil %"
}
#endregion
#region Network
[int]$Retransmits=$PerformanceData.CounterSamples|? path -Match "segments retransmitted" | select -ExpandProperty CookedValue
if ($Retransmits -gt 10){
$output.Bottleneck+="Network"
$output.message+="$Retransmits pps lost on the network"
}
#endregion
#region Memory
$availableGB=[math]::round((($PerformanceData.CounterSamples|? path -Match "available bytes" | select -ExpandProperty CookedValue) /1GB),1)
[int]$CacheLifetimeSeconds=($PerformanceData.CounterSamples|? path -Match "long-term average standby cache lifetime" | select -ExpandProperty CookedValue)
[int]$HardFaults=($PerformanceData.CounterSamples|? path -Match "page reads/sec" | select -ExpandProperty CookedValue)
if ($availableGB -gt 1){
$output.Bottleneck+="Memory"
$output.message+="$HardFaults Hardfaults/s. $availableGB GB available memory. Cachelifetime seconds: $CacheLifetimeSeconds"
}
#endregion
#endregion
}
catch {
}
$output|? bottleneck | ft
}