Objective: Monitor CPU, RAM and disk activity on 54 hosts running Windows 2016. If possible, also monitor for GPU RAM usage.
Why? I had a conversation today where the performance of this large cluster was questioned. I’m certain that the performance is well within tollerence but as they say, when you’re explaining, you’re losing. So I’m bypassing all of that and I’ve decided to use PowerShell to create a dashboard so that the service owners can independently track the realistic server usage.
I put the children to bed around 8pm. A coleague started migrating this server to a different VM cluster 2 minutes after I got logged in at about 10 past 8. After a moment of writing about how there’s not much else to do in the evenings other than catch up on work as a result of lockdown, I decided to try to save some time by getting the PowerShell commands written and in one place.
I wrote the scripts to grab CPU and RAM usage. They take Server as a parameter. They return the value as a per centage to two decimal places. Unfortunately, I couldn’t find a way of getting the per centage of free GPU RAM. But I know I can get this from the event viewer when I need to know if the server is running low.
I have the scripts running perfectly on my local machine but there’s a firewall rule on the network side blocking RPC. I’ve sent on a request to our fantastic senior network engineer so I’m sure the rules will be changed in the next day or two.
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 |
Function GetAvailableRam { param ( [Parameter(Position=0, Mandatory = $true, HelpMessage="Provide a server name")] [string] $Server ) [string] $Hostname = $Server + ".ad.dcu.ie" $a=0 $b=0 $strComputer = $Hostname $a=Get-WmiObject Win32_OperatingSystem -ComputerName $strComputer | fl *freePhysical* | Out-String $b=Get-WmiObject Win32_OperatingSystem -ComputerName $strComputer | fl *totalvisiblememory* | Out-String $a = $a -replace '\D+(\d+)','$1' $b = $b -replace '\D+(\d+)','$1' $FreeRam = [math]::Round($a/$b*10000)/100 $FreeRam } Function GetCPUPerformance { param ( [Parameter(Position=0, Mandatory = $true, HelpMessage="Provide a server name")] [string] $Server ) [string] $Hostname = $Server + ".ad.dcu.ie" $CPUAveragePerformance = (GET-COUNTER -ComputerName $Server -Counter "\Processor(_Total)\% Processor Time" -SampleInterval 2 -MaxSamples 5 |select -ExpandProperty countersamples | select -ExpandProperty cookedvalue | Measure-Object -Average).average # Write-Host "Average of CPU usage (calculated with 5 Sample with interval of 2 sec) :" $CPUAveragePerformance [math]::Round($CPUAveragePerformance,2) } Get-WmiObject -Computername $Server Win32_VideoController | select name, AdapterRAM,@{Expression={$_.adapterram/1MB};label="MB"} |
0 Comments