Popular Posts

Friday, August 7, 2020

Collect hardware metrics from physical Windows Servers

Background

It is often needed to monitor your server infrastructure in terms of performance metrics. Virtual servers could be monitored through hypervisor management software such as VMware vSphere and Microsoft Hyper-V. However, monitoring physical servers for hardware metrics in the absense of a monitoring solution could be a challenge.


Script/Commands

The following commands can be incorporated in your script to retrieve hardware metrics

$cpuUsage = [math]::Round((Get-Counter -ComputerName $server '\Processor(_Total)\% Processor Time' | 
select CounterSamples -ExpandProperty CounterSamples | select CookedValue -ExpandProperty CookedValue),0)

$os = Get-WmiObject -ComputerName $server win32_OperatingSystem

$memUsage = [math]::Round(100-(($os.FreePhysicalMemory/$os.TotalVisibleMemorySize)*100),0)

$freemem = [math]::Round($os.FreePhysicalMemory/1048576,0)

$memsize = [math]::Round($os.TotalVisibleMemorySize/1048576,0)

#Drive type 3 refers to local disk
Get-WmiObject -ComputerName $server win32_logicaldisk -Filter DriveType='3' | foreach {

$diskname = $_.DeviceID
$size = [math]::Round($_.Size/1GB,0)
$freesize = [math]::Round($_.FreeSpace/1GB,0)
$diskfree = [math]::Round(($freesize / $size)*100,0) #As a percentage

}

No comments:

Post a Comment