Performance monitoring with Get-Counter

I last looked at the Get-Counter cmdlet back in 2009 when we were in the middle of CTP 3 for PowerShell 2.  its time for a revisit.

Gathering performance counter information provides a good look inside your systems to enable you to decide what is going on. If you look at the Performance Monitor utility you will see that there are a great many counters we could use. if you want to see them try running this

Get-Counter -ListSet *

A better bet is to start looking at the sets of counters

Get-Counter -ListSet * | sort CounterSetName | select CounterSetName –Unique

When we are looking at performance monitoring the list of usual suspects is fairly small:

  • CPU
  • Memory
  • Disk
  • Networking

These four areas usually start to define problem areas.  We can expand to other areas later.

CPU is always top of the list to look at. On my Windows 7 system I have Processor and Processor Information counter sets. Lets see what’s in them

PS> Get-Counter -ListSet Processor  | select -ExpandProperty counter
\Processor(*)\% Processor Time
\Processor(*)\% User Time
\Processor(*)\% Privileged Time
\Processor(*)\Interrupts/sec
\Processor(*)\% DPC Time
\Processor(*)\% Interrupt Time
\Processor(*)\DPCs Queued/sec
\Processor(*)\DPC Rate
\Processor(*)\% Idle Time
\Processor(*)\% C1 Time
\Processor(*)\% C2 Time
\Processor(*)\% C3 Time
\Processor(*)\C1 Transitions/sec
\Processor(*)\C2 Transitions/sec
\Processor(*)\C3 Transitions/sec

 

PS> Get-Counter -ListSet "Processor Information" | select -ExpandProperty counter
\Processor Information(*)\Processor State Flags
\Processor Information(*)\% of Maximum Frequency
\Processor Information(*)\Processor Frequency
\Processor Information(*)\Parking Status
\Processor Information(*)\% Priority Time
\Processor Information(*)\C3 Transitions/sec
\Processor Information(*)\C2 Transitions/sec
\Processor Information(*)\C1 Transitions/sec
\Processor Information(*)\% C3 Time
\Processor Information(*)\% C2 Time
\Processor Information(*)\% C1 Time
\Processor Information(*)\% Idle Time
\Processor Information(*)\DPC Rate
\Processor Information(*)\DPCs Queued/sec
\Processor Information(*)\% Interrupt Time
\Processor Information(*)\% DPC Time
\Processor Information(*)\Interrupts/sec
\Processor Information(*)\% Privileged Time
\Processor Information(*)\% User Time
\Processor Information(*)\% Processor Time

 

These sets seem a bit similar.  We’ll start with the Processor counters. * means all instances.

if we look at the processor counters again

Get-Counter -ListSet Processor 

CounterSetName     : Processor
MachineName        : .
CounterSetType     : MultiInstance
Description        : The Processor performance object consists of counters that measure aspects of processor activity.
                     The processor is the part of the computer that performs arithmetic and logical computations, initi
                     ates operations on peripherals, and runs the threads of processes.  A computer can have multiple p
                     rocessors.  The processor object represents each processor as an instance of the object.
Paths              : {\Processor(*)\% Processor Time, \Processor(*)\% User Time, \Processor(*)\% Privileged Time, \Processor(*)\Interrupts/sec...}
PathsWithInstances : {\Processor(0)\% Processor Time, \Processor(1)\% Processor Time, \Processor(_Total)\% Processor Time, \Processor(0)\% User Time...}
Counter            : {\Processor(*)\% Processor Time, \Processor(*)\% User Time, \Processor(*)\% Privileged Time, \Proc essor(*)\Interrupts/sec...}

 

The Paths and PathsWithInstances properties of each performance counter set contain the individual counter paths formatted as a string. So lets look at them.

PS> Get-Counter -ListSet Processor | select -ExpandProperty Paths
\Processor(*)\% Processor Time
\Processor(*)\% User Time
\Processor(*)\% Privileged Time
\Processor(*)\Interrupts/sec
\Processor(*)\% DPC Time
\Processor(*)\% Interrupt Time
\Processor(*)\DPCs Queued/sec
\Processor(*)\DPC Rate
\Processor(*)\% Idle Time
\Processor(*)\% C1 Time
\Processor(*)\% C2 Time
\Processor(*)\% C3 Time
\Processor(*)\C1 Transitions/sec
\Processor(*)\C2 Transitions/sec
\Processor(*)\C3 Transitions/sec

 

PS> Get-Counter -ListSet Processor | select -ExpandProperty PathsWithInstances
\Processor(0)\% Processor Time
\Processor(1)\% Processor Time
\Processor(_Total)\% Processor Time
\Processor(0)\% User Time
\Processor(1)\% User Time
\Processor(_Total)\% User Time
\Processor(0)\% Privileged Time
\Processor(1)\% Privileged Time
\Processor(_Total)\% Privileged Time
\Processor(0)\Interrupts/sec
\Processor(1)\Interrupts/sec
\Processor(_Total)\Interrupts/sec
\Processor(0)\% DPC Time
\Processor(1)\% DPC Time
\Processor(_Total)\% DPC Time
\Processor(0)\% Interrupt Time
\Processor(1)\% Interrupt Time
\Processor(_Total)\% Interrupt Time
\Processor(0)\DPCs Queued/sec
\Processor(1)\DPCs Queued/sec
\Processor(_Total)\DPCs Queued/sec
\Processor(0)\DPC Rate
\Processor(1)\DPC Rate
\Processor(_Total)\DPC Rate
\Processor(0)\% Idle Time
\Processor(1)\% Idle Time
\Processor(_Total)\% Idle Time
\Processor(0)\% C1 Time
\Processor(1)\% C1 Time
\Processor(_Total)\% C1 Time
\Processor(0)\% C2 Time
\Processor(1)\% C2 Time
\Processor(_Total)\% C2 Time
\Processor(0)\% C3 Time
\Processor(1)\% C3 Time
\Processor(_Total)\% C3 Time
\Processor(0)\C1 Transitions/sec
\Processor(1)\C1 Transitions/sec
\Processor(_Total)\C1 Transitions/sec
\Processor(0)\C2 Transitions/sec
\Processor(1)\C2 Transitions/sec
\Processor(_Total)\C2 Transitions/sec
\Processor(0)\C3 Transitions/sec
\Processor(1)\C3 Transitions/sec
\Processor(_Total)\C3 Transitions/sec

 

These are the strings we need to use to collect performance information.

 

Get-Counter -Counter "\Processor(_Total)\% Processor Time" -MaxSamples 10

returns 10 samples 1 second apart showing the total processor usage

I have two cores in my system so I might want to see what the individual cores are doing

 

Get-Counter -Counter "\Processor(_Total)\% Processor Time", "\Processor(0)\% Processor Time", "\Processor(1)\% Processor Time" -MaxSamples 10

Next time we’ll look at memory

Leave a Reply