aLockdown on a Wednesday night. Server performance monitoring scripts. Wednesday night during lock down. Let’s do some scripting to get details from a few dozen servers.

Feb 24, 2021 | Uncategorized | 0 comments

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.

Here’s a great resource on the Microsoft website that details the various inbound ports required for various services that run on Windows.

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

Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.