Performance Monitor counter search


How often do you head to Performance Monitor to only spend what seems like an age finding the counter that you want? Is Batch Requests/sec in SQL Statistics or Access Methods? Is Page Lookups/sec in Buffer Manager or SQL Statitics?

Well, I eventually got around to making this search a lot easier for myself, with the help of some PowerShell.

If you open up ISE and paste in Get-Counter -ComputerName $env:COMPUTERNAME -ListSet * you'll get a long list of all counter sets on your computer. (Yep, it's really long add | select -first 10 if you just want a flavour of whats returned and not the whole set).

You will see that the CounterSetName in the results equates to the group headers in the Performance Monitor UI

Counters01Counters02

OK, this is useful, let's filter the output a bit Get-Counter -ComputerName $env:COMPUTERNAME -ListSet * | Where-Object countersetname -Like '*sql*'

This brings us all the counter set names that have 'sql' in them. This is better than every set but still a lot of clicking around to find a particular counter.

We can see in the above image that the counter set has a Paths property, let's explore that with (Get-Counter -ListSet 'SQLServer:databases').Paths.

Counters03

Now this is excellent, we have a list of counter paths that are within the SQLServer:Databases set.

The next step is to simply refine the function a little and add a varaible for the name (or part of name) for the counter we are trying to track down:

(Get-Counter -ComputerName $env:COMPUTERNAME -ListSet *).paths | ? {$_ -like "`*$CounterName`*"} | Write-Output

I have wrapped this in a function and added it to my profile so I can now locate any Performance Monitor counter really quickly.

Comments (0)

Skip to main content