From dc7f11a2fd193651ae54442ced3c42c226df173e Mon Sep 17 00:00:00 2001 From: David Paulson Date: Thu, 6 Jan 2022 12:22:51 -0600 Subject: [PATCH 1/6] Created Localization of Performance Counters Logic --- .../Helpers/PerformanceCountersFunctions.ps1 | 188 ++++++++++++++++++ 1 file changed, 188 insertions(+) create mode 100644 Diagnostics/HealthChecker/Helpers/PerformanceCountersFunctions.ps1 diff --git a/Diagnostics/HealthChecker/Helpers/PerformanceCountersFunctions.ps1 b/Diagnostics/HealthChecker/Helpers/PerformanceCountersFunctions.ps1 new file mode 100644 index 0000000000..b111153edf --- /dev/null +++ b/Diagnostics/HealthChecker/Helpers/PerformanceCountersFunctions.ps1 @@ -0,0 +1,188 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +. $PSScriptRoot\..\..\..\Shared\Get-RemoteRegistrySubKey.ps1 +. $PSScriptRoot\..\..\..\Shared\Get-RemoteRegistryValue.ps1 +. $PSScriptRoot\Invoke-CatchActions.ps1 + +# Use this after the counters have been localized. +Function Get-CounterSamples { + param( + [Parameter(Mandatory = $true)] + [string[]]$MachineName, + + [Parameter(Mandatory = $true)] + [string[]]$Counter, + + [string]$CustomErrorAction = "Stop" + ) + Write-Verbose "Calling: $($MyInvocation.MyCommand)" + + try { + return (Get-Counter -ComputerName $MachineName -Counter $Counter -ErrorAction $CustomErrorAction).CounterSamples + } catch { + Write-Verbose "Failed ot get counter samples" + Invoke-CatchActions + } +} + +# Use this to localize the counters provided +Function Get-LocalizedCounterSamples { + param( + [Parameter(Mandatory = $true)] + [string[]]$MachineName, + + [Parameter(Mandatory = $true)] + [string[]]$Counter, + + [string]$CustomErrorAction = "Stop" + ) + + Write-Verbose "Calling: $($MyInvocation.MyCommand)" + $localizedCounters = @() + + foreach ($computer in $MachineName) { + + foreach ($currentCounter in $Counter) { + $counterObject = Get-CounterFullNameToCounterObject -FullCounterName $currentCounter + $localizedCounterName = Get-LocalizedPerformanceCounterName -ComputerName $computer -PerformanceCounterName $counterObject.CounterName + $localizedObjectName = Get-LocalizedPerformanceCounterName -ComputerName $computer -PerformanceCounterName $counterObject.ObjectName + $localizedFullCounterName = ($counterObject.FullName.Replace($counterObject.CounterName, $localizedCounterName)).Replace($counterObject.ObjectName, $localizedObjectName) + + if (-not ($localizedCounters.Contains($localizedFullCounterName))) { + $localizedCounters += $localizedFullCounterName + } + } + } + + return (Get-CounterSamples -MachineName $MachineName -Counter $localizedCounters -CustomErrorAction $CustomErrorAction) +} + +Function Get-LocalizedPerformanceCounterName { + [CmdletBinding()] + [OutputType('System.String')] + param( + [Parameter(Mandatory = $true)] + [string]$ComputerName, + + [Parameter(Mandatory = $true)] + [string]$PerformanceCounterName + ) + Write-Verbose "Calling: $($MyInvocation.MyCommand)" + + if ($null -eq $Script:EnglishOnlyOSCache) { + $Script:EnglishOnlyOSCache = @{} + } + + if ($null -eq $Script:Counter009Cache) { + $Script:Counter009Cache = @{} + } + + if ($null -eq $Script:CounterCurrentLanguageCache) { + $Script:CounterCurrentLanguageCache = @{} + } + + if (-not ($Script:EnglishOnlyOSCache.ContainsKey($ComputerName))) { + $perfLib = Get-RemoteRegistrySubKey -MachineName $ComputerName ` + -SubKey "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\009" ` + -CatchActionFunction ${Function:Invoke-CatchActions} + $englishOnlyOS = ($perfLib.GetSubKeyNames() | + Where-Object { $_ -like "0*" }).Count -eq 1 + $Script:EnglishOnlyOSCache.Add($ComputerName, $englishOnlyOS) + } + + if ($Script:EnglishOnlyOSCache[$ComputerName]) { + Write-Verbose "English Only Machine, return same value" + return $PerformanceCounterName + } + + if (-not ($Script:Counter009Cache.ContainsKey($ComputerName))) { + $enUSCounterKeys = Get-RemoteRegistryValue -MachineName $ComputerName ` + -SubKey "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\009" ` + -GetValue "Counter" ` + -ValueType "MultiString" ` + -CatchActionFunction ${Function:Invoke-CatchActions} + + if ($null -eq $enUSCounterKeys) { + Write-Verbose "No 'en-US' (009) 'Counter' registry value found." + return $null + } else { + $Script:Counter009Cache.Add($ComputerName, $enUSCounterKeys) + } + } + + if (-not ($Script:CounterCurrentLanguageCache.ContainsKey($ComputerName))) { + $currentCounterKeys = Get-RemoteRegistryValue -MachineName $ComputerName ` + -SubKey "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\CurrentLanguage" ` + -GetValue "Counter" ` + -ValueType "MultiString" ` + -CatchActionFunction ${Function:Invoke-CatchActions} + + if ($null -eq $currentCounterKeys) { + Write-Verbose "No 'localized' (CurrentLanguage) 'Counter' registry value found" + return $null + } else { + $Script:CounterCurrentLanguageCache.Add($ComputerName, $currentCounterKeys) + } + } + + $counterName = $PerformanceCounterName.ToLower() + Write-Verbose "Trying to query ID index for Performance Counter: $counterName" + $enUSCounterKeys = $Script:Counter009Cache[$ComputerName] + $currentCounterKeys = $Script:CounterCurrentLanguageCache[$ComputerName] + $counterIdIndex = ($enUSCounterKeys.ToLower().IndexOf("$counterName") - 1) + + if ($counterIdIndex -ge 0) { + Write-Verbose "Counter ID Index: $counterIdIndex" + Write-Verbose "Verify Value: $($enUSCounterKeys[$counterIdIndex + 1])" + $counterId = $enUSCounterKeys[$counterIdIndex] + Write-Verbose "Counter ID: $counterId" + $localizedCounterNameIndex = ($currentCounterKeys.IndexOf("$counterId") + 1) + + if ($localizedCounterNameIndex -gt 0) { + $localCounterName = $currentCounterKeys[$localizedCounterNameIndex] + Write-Verbose "Found Localized Counter Index: $localizedCounterNameIndex" + Write-Verbose "Localized Counter Name: $localCounterName" + return $localCounterName + } else { + Write-Verbose "Failed to find Localized Counter Index" + } + } else { + Write-Verbose "Failed to find the counter ID." + } +} + +Function Get-CounterFullNameToCounterObject { + param( + [Parameter(Mandatory = $true)] + [string]$FullCounterName + ) + + # Supported Scenarios + # \\adt-e2k13aio1\logicaldisk(harddiskvolume1)\avg. disk sec/read + # \logicaldisk(harddiskvolume1)\avg. disk sec/read + if (-not ($FullCounterName.StartsWith("\"))) { + throw "Full Counter Name Should start with '\'" + } elseif ($FullCounterName.StartsWith("\\")) { + $endOfServerIndex = $FullCounterName.IndexOf("\", 2) + $serverName = $FullCounterName.Substring(2, $endOfServerIndex - 2) + } else { + $endOfServerIndex = 0 + } + $startOfCounterIndex = $FullCounterName.LastIndexOf("\") + 1 + $endOfCounterObjectIndex = $FullCounterName.IndexOf("(") + + if ($endOfCounterObjectIndex -eq -1) { + $endOfCounterObjectIndex = $startOfCounterIndex - 1 + } else { + $instanceName = $FullCounterName.Substring($endOfCounterObjectIndex + 1, ($FullCounterName.IndexOf(")") - $endOfCounterObjectIndex - 1)) + } + + return [PSCustomObject]@{ + FullName = $FullCounterName + ServerName = $serverName + ObjectName = ($FullCounterName.Substring($endOfServerIndex + 1, $endOfCounterObjectIndex - $endOfServerIndex - 1)) + InstanceName = $instanceName + CounterName = $FullCounterName.Substring($startOfCounterIndex) + } +} From 2f683bff614340447aab3a3cbb1c9677a1a9b1db Mon Sep 17 00:00:00 2001 From: David Paulson Date: Mon, 10 Jan 2022 19:09:41 -0600 Subject: [PATCH 2/6] Added supported scenario for Get-CounterFullNameToCounterObject For some reason in my lab i have a double slash like this: \\adt-e2k13aio1\\logicaldisk(harddiskvolume1)\avg. disk sec/read --- .../Helpers/PerformanceCountersFunctions.ps1 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Diagnostics/HealthChecker/Helpers/PerformanceCountersFunctions.ps1 b/Diagnostics/HealthChecker/Helpers/PerformanceCountersFunctions.ps1 index b111153edf..b3a4e719c3 100644 --- a/Diagnostics/HealthChecker/Helpers/PerformanceCountersFunctions.ps1 +++ b/Diagnostics/HealthChecker/Helpers/PerformanceCountersFunctions.ps1 @@ -160,6 +160,7 @@ Function Get-CounterFullNameToCounterObject { # Supported Scenarios # \\adt-e2k13aio1\logicaldisk(harddiskvolume1)\avg. disk sec/read + # \\adt-e2k13aio1\\logicaldisk(harddiskvolume1)\avg. disk sec/read # \logicaldisk(harddiskvolume1)\avg. disk sec/read if (-not ($FullCounterName.StartsWith("\"))) { throw "Full Counter Name Should start with '\'" @@ -178,10 +179,15 @@ Function Get-CounterFullNameToCounterObject { $instanceName = $FullCounterName.Substring($endOfCounterObjectIndex + 1, ($FullCounterName.IndexOf(")") - $endOfCounterObjectIndex - 1)) } + $doubleSlash = 0 + if (($FullCounterName.IndexOf("\\", 2) -ne -1)) { + $doubleSlash = 1 + } + return [PSCustomObject]@{ FullName = $FullCounterName ServerName = $serverName - ObjectName = ($FullCounterName.Substring($endOfServerIndex + 1, $endOfCounterObjectIndex - $endOfServerIndex - 1)) + ObjectName = ($FullCounterName.Substring($endOfServerIndex + 1 + $doubleSlash, $endOfCounterObjectIndex - $endOfServerIndex - 1 - $doubleSlash)) InstanceName = $instanceName CounterName = $FullCounterName.Substring($startOfCounterIndex) } From 2067c84911d207006b323612121d019ae87c33c8 Mon Sep 17 00:00:00 2001 From: David Paulson Date: Mon, 10 Jan 2022 19:11:49 -0600 Subject: [PATCH 3/6] Use the Localized Counters for Network Interfaces --- .../ServerInformation/Get-OperatingSystemInformation.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Diagnostics/HealthChecker/DataCollection/ServerInformation/Get-OperatingSystemInformation.ps1 b/Diagnostics/HealthChecker/DataCollection/ServerInformation/Get-OperatingSystemInformation.ps1 index 521c3dee55..4fdb5c9564 100644 --- a/Diagnostics/HealthChecker/DataCollection/ServerInformation/Get-OperatingSystemInformation.ps1 +++ b/Diagnostics/HealthChecker/DataCollection/ServerInformation/Get-OperatingSystemInformation.ps1 @@ -16,7 +16,7 @@ . $PSScriptRoot\Get-TimeZoneInformationRegistrySettings.ps1 . $PSScriptRoot\Get-WmiObjectCriticalHandler.ps1 . $PSScriptRoot\Get-WmiObjectHandler.ps1 -. $PSScriptRoot\..\..\Helpers\Get-CounterSamples.ps1 +. $PSScriptRoot\..\..\Helpers\PerformanceCountersFunctions.ps1 Function Get-OperatingSystemInformation { Write-Verbose "Calling: $($MyInvocation.MyCommand)" @@ -73,7 +73,7 @@ Function Get-OperatingSystemInformation { $osInformation.NetworkInformation.HttpProxy = Get-HttpProxySetting $osInformation.InstalledUpdates.HotFixes = (Get-HotFix -ComputerName $Script:Server -ErrorAction SilentlyContinue) #old school check still valid and faster and a failsafe $osInformation.LmCompatibility = Get-LmCompatibilityLevelInformation - $counterSamples = (Get-CounterSamples -MachineNames $Script:Server -Counters "\Network Interface(*)\Packets Received Discarded") + $counterSamples = (Get-LocalizedCounterSamples -MachineName $Script:Server -Counter "\Network Interface(*)\Packets Received Discarded") if ($null -ne $counterSamples) { $osInformation.NetworkInformation.PacketsReceivedDiscarded = $counterSamples From 08014b1206b287778274b2b8f6e89a45e1456095 Mon Sep 17 00:00:00 2001 From: David Paulson Date: Mon, 10 Jan 2022 19:16:38 -0600 Subject: [PATCH 4/6] Simplified CAS Load Balancing Report Removed lot of code that isn't needed. Also added in the Localized Counter Feature. --- .../Features/Get-CasLoadBalancingReport.ps1 | 176 ++++++------------ 1 file changed, 58 insertions(+), 118 deletions(-) diff --git a/Diagnostics/HealthChecker/Features/Get-CasLoadBalancingReport.ps1 b/Diagnostics/HealthChecker/Features/Get-CasLoadBalancingReport.ps1 index 36cf42c5e3..034b6e0728 100644 --- a/Diagnostics/HealthChecker/Features/Get-CasLoadBalancingReport.ps1 +++ b/Diagnostics/HealthChecker/Features/Get-CasLoadBalancingReport.ps1 @@ -1,24 +1,10 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. +. $PSScriptRoot\..\Helpers\PerformanceCountersFunctions.ps1 Function Get-CASLoadBalancingReport { Write-Verbose "Calling: $($MyInvocation.MyCommand)" - #Connection and requests per server and client type values - $CASConnectionStats = @{} - $TotalCASConnectionCount = 0 - $AutoDStats = @{} - $TotalAutoDRequests = 0 - $EWSStats = @{} - $TotalEWSRequests = 0 - $MapiHttpStats = @{} - $TotalMapiHttpRequests = 0 - $EASStats = @{} - $TotalEASRequests = 0 - $OWAStats = @{} - $TotalOWARequests = 0 - $RpcHttpStats = @{} - $TotalRpcHttpRequests = 0 $CASServers = @() if ($null -ne $CasServerList) { @@ -42,17 +28,37 @@ Function Get-CASLoadBalancingReport { Exit } + Function DisplayKeyMatching { + param( + [string]$CounterValue, + [string]$DisplayValue + ) + return [PSCustomObject]@{ + Counter = $CounterValue + Display = $DisplayValue + } + } + #Request stats from perfmon for all CAS - $PerformanceCounters = @() - $PerformanceCounters += "\Web Service(Default Web Site)\Current Connections" - $PerformanceCounters += "\ASP.NET Apps v4.0.30319(_LM_W3SVC_1_ROOT_Autodiscover)\Requests Executing" - $PerformanceCounters += "\ASP.NET Apps v4.0.30319(_LM_W3SVC_1_ROOT_EWS)\Requests Executing" - $PerformanceCounters += "\ASP.NET Apps v4.0.30319(_LM_W3SVC_1_ROOT_mapi)\Requests Executing" - $PerformanceCounters += "\ASP.NET Apps v4.0.30319(_LM_W3SVC_1_ROOT_Microsoft-Server-ActiveSync)\Requests Executing" - $PerformanceCounters += "\ASP.NET Apps v4.0.30319(_LM_W3SVC_1_ROOT_owa)\Requests Executing" - $PerformanceCounters += "\ASP.NET Apps v4.0.30319(_LM_W3SVC_1_ROOT_Rpc)\Requests Executing" + $displayKeys = @{ + 1 = DisplayKeyMatching "Default Web Site" "Load Distribution" + 2 = DisplayKeyMatching "_LM_W3SVC_1_ROOT_Autodiscover" "AutoDiscover" + 3 = DisplayKeyMatching "_LM_W3SVC_1_ROOT_EWS" "EWS" + 4 = DisplayKeyMatching "_LM_W3SVC_1_ROOT_mapi" "MapiHttp" + 5 = DisplayKeyMatching "_LM_W3SVC_1_ROOT_Microsoft-Server-ActiveSync" "EAS" + 6 = DisplayKeyMatching "_LM_W3SVC_1_ROOT_owa" "OWA" + 7 = DisplayKeyMatching "_LM_W3SVC_1_ROOT_Rpc" "RpcHttp" + } + $perServerStats = @{} + $totalStats = @{} + $currentErrors = $Error.Count - $AllCounterResults = Get-Counter -ComputerName $CASServers -Counter $PerformanceCounters -ErrorAction SilentlyContinue + $counterSamples = Get-LocalizedCounterSamples -MachineName $CASServers -Counter @( + "\Web Service(*)\Current Connections", + "\ASP.NET Apps v4.0.30319(*)\Requests Executing" + ) ` + -CustomErrorAction "SilentlyContinue" + if ($currentErrors -ne $Error.Count) { $i = 0 @@ -64,110 +70,44 @@ Function Get-CASLoadBalancingReport { Write-Verbose("Failed to get some counters") } - foreach ($Result in $AllCounterResults.CounterSamples) { - $CasName = ($Result.Path).Split("\\", [System.StringSplitOptions]::RemoveEmptyEntries)[0] - $ResultCookedValue = $Result.CookedValue - - if ($Result.Path -like "*{0}*{1}" -f $CasName, $PerformanceCounters[0]) { - #Total connections - $CASConnectionStats.Add($CasName, $ResultCookedValue) - $TotalCASConnectionCount += $ResultCookedValue - } elseif ($Result.Path -like "*{0}*{1}" -f $CasName, $PerformanceCounters[1]) { - #AutoD requests - $AutoDStats.Add($CasName, $ResultCookedValue) - $TotalAutoDRequests += $ResultCookedValue - } elseif ($Result.Path -like "*{0}*{1}" -f $CasName, $PerformanceCounters[2]) { - #EWS requests - $EWSStats.Add($CasName, $ResultCookedValue) - $TotalEWSRequests += $ResultCookedValue - } elseif ($Result.Path -like "*{0}*{1}" -f $CasName, $PerformanceCounters[3]) { - #MapiHttp requests - $MapiHttpStats.Add($CasName, $ResultCookedValue) - $TotalMapiHttpRequests += $ResultCookedValue - } elseif ($Result.Path -like "*{0}*{1}" -f $CasName, $PerformanceCounters[4]) { - #EAS requests - $EASStats.Add($CasName, $ResultCookedValue) - $TotalEASRequests += $ResultCookedValue - } elseif ($Result.Path -like "*{0}*{1}" -f $CasName, $PerformanceCounters[5]) { - #OWA requests - $OWAStats.Add($CasName, $ResultCookedValue) - $TotalOWARequests += $ResultCookedValue - } elseif ($Result.Path -like "*{0}*{1}" -f $CasName, $PerformanceCounters[6]) { - #RPCHTTP requests - $RpcHttpStats.Add($CasName, $ResultCookedValue) - $TotalRpcHttpRequests += $ResultCookedValue - } - } - - - #Report the results for connection count - Write-Grey("") - Write-Grey("Connection Load Distribution Per Server") - Write-Grey("Total Connections: {0}" -f $TotalCASConnectionCount) - #Calculate percentage of connection load - $CASConnectionStats.GetEnumerator() | Sort-Object -Descending | ForEach-Object { - Write-Grey($_.Key + ": " + $_.Value + " Connections = " + [math]::Round((([int]$_.Value / $TotalCASConnectionCount) * 100)) + "% Distribution") - } + foreach ($counterSample in $counterSamples) { + $counterObject = Get-CounterFullNameToCounterObject -FullCounterName $counterSample.Path - #Same for each client type. These are request numbers not connection numbers. - #AutoD - if ($TotalAutoDRequests -gt 0) { - Write-Grey("") - Write-Grey("Current AutoDiscover Requests Per Server") - Write-Grey("Total Requests: {0}" -f $TotalAutoDRequests) - $AutoDStats.GetEnumerator() | Sort-Object -Descending | ForEach-Object { - Write-Grey($_.Key + ": " + $_.Value + " Requests = " + [math]::Round((([int]$_.Value / $TotalAutoDRequests) * 100)) + "% Distribution") + if (-not ($perServerStats.ContainsKey($counterObject.ServerName))) { + $perServerStats.Add($counterObject.ServerName, @{}) } - } - #EWS - if ($TotalEWSRequests -gt 0) { - Write-Grey("") - Write-Grey("Current EWS Requests Per Server") - Write-Grey("Total Requests: {0}" -f $TotalEWSRequests) - $EWSStats.GetEnumerator() | Sort-Object -Descending | ForEach-Object { - Write-Grey($_.Key + ": " + $_.Value + " Requests = " + [math]::Round((([int]$_.Value / $TotalEWSRequests) * 100)) + "% Distribution") + if (-not ($perServerStats[$counterObject.ServerName].ContainsKey($counterObject.InstanceName))) { + $perServerStats[$counterObject.ServerName].Add($counterObject.InstanceName, $counterSample.CookedValue) + } else { + Write-Verbose "This shouldn't occur...." + $perServerStats[$counterObject.ServerName][$counterObject.InstanceName] += $counterSample.CookedValue } - } - #MapiHttp - if ($TotalMapiHttpRequests -gt 0) { - Write-Grey("") - Write-Grey("Current MapiHttp Requests Per Server") - Write-Grey("Total Requests: {0}" -f $TotalMapiHttpRequests) - $MapiHttpStats.GetEnumerator() | Sort-Object -Descending | ForEach-Object { - Write-Grey($_.Key + ": " + $_.Value + " Requests = " + [math]::Round((([int]$_.Value / $TotalMapiHttpRequests) * 100)) + "% Distribution") + if (-not ($totalStats.ContainsKey($counterObject.InstanceName))) { + $totalStats.Add($counterObject.InstanceName, 0) } - } - #EAS - if ($TotalEASRequests -gt 0) { - Write-Grey("") - Write-Grey("Current EAS Requests Per Server") - Write-Grey("Total Requests: {0}" -f $TotalEASRequests) - $EASStats.GetEnumerator() | Sort-Object -Descending | ForEach-Object { - Write-Grey($_.Key + ": " + $_.Value + " Requests = " + [math]::Round((([int]$_.Value / $TotalEASRequests) * 100)) + "% Distribution") - } + $totalStats[$counterObject.InstanceName] += $counterSample.CookedValue } - #OWA - if ($TotalOWARequests -gt 0) { - Write-Grey("") - Write-Grey("Current OWA Requests Per Server") - Write-Grey("Total Requests: {0}" -f $TotalOWARequests) - $OWAStats.GetEnumerator() | Sort-Object -Descending | ForEach-Object { - Write-Grey($_.Key + ": " + $_.Value + " Requests = " + [math]::Round((([int]$_.Value / $TotalOWARequests) * 100)) + "% Distribution") - } - } + $keyOrders = $displayKeys.Keys | Sort-Object + + foreach ($key in $keyOrders) { + $currentDisplayKey = $displayKeys[$key] + $totalRequests = $totalStats[$currentDisplayKey.Counter] + + if ($totalRequests -le 0) { continue } + + Write-Grey "" + Write-Grey "Current $($currentDisplayKey.Display) Per Server" + Write-Grey "Total Requests: $totalRequests" - #RpcHttp - if ($TotalRpcHttpRequests -gt 0) { - Write-Grey("") - Write-Grey("Current RpcHttp Requests Per Server") - Write-Grey("Total Requests: {0}" -f $TotalRpcHttpRequests) - $RpcHttpStats.GetEnumerator() | Sort-Object -Descending | ForEach-Object { - Write-Grey($_.Key + ": " + $_.Value + " Requests = " + [math]::Round((([int]$_.Value / $TotalRpcHttpRequests) * 100)) + "% Distribution") + foreach ($serverKey in $perServerStats.Keys) { + if ($perServerStats.ContainsKey($serverKey)) { + $serverValue = $perServerStats[$serverKey][$currentDisplayKey.Counter] + Write-Grey "$serverKey : $serverValue Connections = $([math]::Round((([int]$serverValue / $totalRequests) * 100)))% Distribution" + } } } - Write-Grey("") } From d0921f6b81ccc38e474d2f55dc2cf295b9f06535 Mon Sep 17 00:00:00 2001 From: David Paulson Date: Mon, 10 Jan 2022 19:16:55 -0600 Subject: [PATCH 5/6] Delete Get-CounterSamples.ps1 --- .../Helpers/Get-CounterSamples.ps1 | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 Diagnostics/HealthChecker/Helpers/Get-CounterSamples.ps1 diff --git a/Diagnostics/HealthChecker/Helpers/Get-CounterSamples.ps1 b/Diagnostics/HealthChecker/Helpers/Get-CounterSamples.ps1 deleted file mode 100644 index 336e75dd32..0000000000 --- a/Diagnostics/HealthChecker/Helpers/Get-CounterSamples.ps1 +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright (c) Microsoft Corporation. -# Licensed under the MIT License. - -Function Get-CounterSamples { - param( - [Parameter(Mandatory = $true)][array]$MachineNames, - [Parameter(Mandatory = $true)][array]$Counters - ) - Write-Verbose "Calling: $($MyInvocation.MyCommand)" - - try { - $counterSamples = (Get-Counter -ComputerName $MachineNames -Counter $Counters -ErrorAction Stop).CounterSamples - } catch { - Invoke-CatchActions - Write-Verbose "Failed to get counter samples" - } - Write-Verbose "Exiting: $($MyInvocation.MyCommand)" - return $counterSamples -} From 075a4f889615c5cbf4299c2925f03d5f6ff53bd7 Mon Sep 17 00:00:00 2001 From: David Paulson Date: Mon, 10 Jan 2022 19:22:37 -0600 Subject: [PATCH 6/6] Updated Pester Testing for new cmdlet name --- Diagnostics/HealthChecker/Tests/HealthChecker.Tests.ps1 | 2 +- .../Tests/HealthCheckerTest.CommonMocks.NotPublished.ps1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Diagnostics/HealthChecker/Tests/HealthChecker.Tests.ps1 b/Diagnostics/HealthChecker/Tests/HealthChecker.Tests.ps1 index a563448885..17e7038f8f 100644 --- a/Diagnostics/HealthChecker/Tests/HealthChecker.Tests.ps1 +++ b/Diagnostics/HealthChecker/Tests/HealthChecker.Tests.ps1 @@ -216,7 +216,7 @@ Describe "Testing Health Checker by Mock Data Imports" { Assert-MockCalled Get-DnsClient -Exactly 1 Assert-MockCalled Get-NetAdapterRss -Exactly 1 Assert-MockCalled Get-HotFix -Exactly 1 - Assert-MockCalled Get-CounterSamples -Exactly 1 + Assert-MockCalled Get-LocalizedCounterSamples -Exactly 1 Assert-MockCalled Get-ServerRebootPending -Exactly 1 Assert-MockCalled Get-TimeZoneInformationRegistrySettings -Exactly 1 Assert-MockCalled Get-AllTlsSettingsFromRegistry -Exactly 1 diff --git a/Diagnostics/HealthChecker/Tests/HealthCheckerTest.CommonMocks.NotPublished.ps1 b/Diagnostics/HealthChecker/Tests/HealthCheckerTest.CommonMocks.NotPublished.ps1 index 261d28b71d..5cd0524ae2 100644 --- a/Diagnostics/HealthChecker/Tests/HealthCheckerTest.CommonMocks.NotPublished.ps1 +++ b/Diagnostics/HealthChecker/Tests/HealthCheckerTest.CommonMocks.NotPublished.ps1 @@ -86,7 +86,7 @@ Mock Get-HotFix { return Import-Clixml "$Script:MockDataCollectionRoot\OS\GetHotFix.xml" } -Mock Get-CounterSamples { +Mock Get-LocalizedCounterSamples { return Import-Clixml "$Script:MockDataCollectionRoot\OS\GetCounterSamples.xml" }