Using WMI to retrieve performance counters

Another way to access performance information is via WMI. You can use either the WMI or the CIM cmdlets to access a large number of performance counters, as an alternative to using Get-Counter.

When using WMI, the naming structure for counter information is different from using Get-Counter. With WMI, counters are exposed via separate WMI classes whose names are slightly different from those you use with Get-Counter. Effectively, with WMI, each performance counter set is a WMI class.

You find the WMI performance counters in the ROOTCimV2 namespace; they have names that begin with Win32_Perf. For example, the Memory performance counter set contains 36 separate counters. The Win32_PerfFormattedData_PerfOS_Memory WMI class contains 46 properties, including the numerous individual performance counters.

With WMI, you get all the measurements back in one call to Get-CimInstance, whereas you would need to call Get-Counter for each counter sample. This provides better performance than you see with Get-Counter, but WMI is still fairly slow when compared to the PLA data collector sets you use in later recipes in this chapter.

This recipe gets performance counters from local and remote machines using the CIM cmdlet set. The CIM cmdlet set is preferable to the older WMI commands as it is a little faster, and it can make use of WinRM for remote sessions.

Getting ready

You run this recipe on SRV1. This recipe uses the CIM cmdlets. You could revise this recipe to make use of the WMI cmdlets, which might be useful in cases where you are communicating with an older system that does not have PowerShell remoting up and running.

How to do it...

  1. Find performance-related counters in the RootCimV2 namespace:
    Get-CimClass -ClassName Win32*perf* | Measure-Object |
      Select-Object -Property Count 
    Get-CimClass -ClassName Win32*perfFormatted* | Measure-Object |
      Select-Object -Property Count 
    Get-CimClass -ClassName Win32*perfraw* | Measure-Object |
      Select-Object -Property Count 
  2. Find key performance classes for the OS:
    Get-CimClass "win32_PerfFormatted*PerfOS*" |
      Select-Object -Property CimClassName
  3. Find key performance classes for the disk:
    Get-CimClass "Win32_PerfFormatted*Disk*" |
      Select-Object -Property CimClassName
  4. Find key performance classes for the disk:
    Get-CimInstance -ClassName Win32_PerfFormattedData_PerfOS_Memory |
      Select-Object -Property PagesPerSec, AvailableMBytes
  5. Get CPU counter samples:
    Get-CimInstance -ClassName Win32_PerfFormattedData_PerfOS_Processor |
      Where-Object Name -eq '_Total' |
        Select-Object -Property Name, PercentProcessortime
  6. Get CPU counter samples from a remote system:
    $CHT = @{
        ClassName     = 'Win32_PerfFormattedData_PerfOS_Memory'
        ComputerName  = 'DC1'
    }
    Get-CimInstance @CHT |
      Select-Object -Property PSComputerName, PagesPerSec,
                              AvailableMBytes

How it works...

In step 1, you search for the performance-related counters in the RootCIMV2 namespace, which looks like this:

How it works...

In step 2, you search for WMI classes relating to the OS performance, which looks like this:

How it works...

In step 3, you search for WMI classes relating to disk performance, which looks like this:

How it works...

In step 4, you get two memory counters from SRV1, which looks like this:

How it works...

In step 5, you retrieve the PerfOS_Processor class and display just the name and the percentage of CPU time being used on SRV1, which looks like this:

How it works...

With step 6, you retrieve the memory performance information, but remotely from DC1, which looks like this:

How it works...

There's more...

In step 1, you saw there were 172 WMI classes containing formatted data and the same number containing uncooked values, out of a total of 345 performance classes in the RootCIMV2 namespace on SRV1. The one additional class is Win32_Perf, which returns all the other performance class instances (on SRV1, using Get-CimInstance to return the class results in 2,891 entries).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.172.159