17 September, 2014

Read performance counter data remotely - OS

There was a day when there were a couple of boxes with sporadically and abnormally loaded CPU and had to catch when the CPU went up for a couple of minutes on any of them.

Instead of logging into each via RDP or open Perfmon against each host manually, here is a quick command line to get the aggregate CPU load from multiple hosts in one go.

PS C:\> while (1) { (("host1,host2,host3").split(",")) | % { get-counter "\\$_\Processor(_total)\% Processor Time" -maxsamples 1 | select -exp countersamples | select path,cookedvalue }| sort CookedValue -desc; sleep 60; clear}

Some explanation and other ideas:

  •  (("host1,host2,host3").split(","))
    create an array from the comma delimited list of hosts
  • get-counter "\\$_\Processor(_total)\% Processor Time" -maxsamples 1
    read counter from each host remotely. The counter can be replaced i something else needs to be monitored, other than CPU
  • select -exp countersamples | select path,cookedvalue
    Expand what's in the countersamples property and take only the 'path' and 'cookedvalue'
  • sort CookedValue -desc
    put  the largest value to the top
  • sleep 60; clear
    wait a minute, clear the screen and do it again in a while loop

It's not quick, not sophisticated, no bells and whistles around it but it does the job and gives you a sample of the CPU load periodically.

Hope it's useful.

No comments:

Post a Comment