Creating and using PLA data collector sets

In the previous two recipes, you retrieved individual counter objects either by using Get-Counter or via WMI. That works, but retrieving performance data is slow. It took over a minute and 40 seconds to retrieve the performance counters in a local machine's Memory counter set. Using these methods for large-scale performance data collection does not scale well.

The PLA subsystem provides an efficient mechanism to perform the data collection. PLA allows you to create a data collector set. This is an object representing the counters whose values you wish to collect. Once you create the data collector set, you can direct Windows to start collecting the data and to output it for later analysis. You have options as to how to output the data—you can use a binary log file, a comma-delimited file, and more. Once you have the data collected and output, you can analyze it, as you can see in the Reporting on performance data recipe.

There is no direct cmdlet support for setting up and using performance data collection. Instead, you use the PLA COM objects that are built into Windows.

Getting ready

You run this on SRV1, a domain-joined server.

How to do it...

  1. Create and populate a new performance data collector set:
    $Name   = 'SRV1 Collector Set'
    $SRV1CS = New-Object -COM Pla.DataCollectorSet
    $SRV1CS.DisplayName                = $Name
    $SRV1CS.Duration                   = 12*3600  # 12 hours - 19:00
    $SRV1CS.SubdirectoryFormat         = 1 
    $SRV1CS.SubdirectoryFormatPattern  = 'yyyy-MM'
    $JPHT = @{
      Path      = "$Env:SystemDrive"
      ChildPath = "PerfLogsAdmin$Name"
    }
    $SRV1CS.RootPath = Join-Path @JPHT
    $SRV1Collector = $SRV1CS.DataCollectors.CreateDataCollector(0)
    $SRV1Collector.FileName              = "$Name_"
    $SRV1Collector.FileNameFormat        = 1 
    $SRV1Collector.FileNameFormatPattern = "-MM-dd"
    $SRV1Collector.SampleInterval        = 15
    $SRV1Collector.LogFileFormat         = 3 # BLG format
    $SRV1Collector.LogAppend             = $True
  2. Define counters of interest:
    $Counters = @(
          'MemoryPages/sec',
          'MemoryAvailable MBytes', 
          'Processor(_Total)\% Processor Time', 
          'PhysicalDisk(_Total)\% Disk Time',
          'PhysicalDisk(_Total)Disk Transfers/sec' ,
          'PhysicalDisk(_Total)Avg. Disk Sec/Read',
          'PhysicalDisk(_Total)Avg. Disk Sec/Write',
          'PhysicalDisk(_Total)Avg. Disk Queue Length'
    )
  3. Add the counters to the collector:
    $SRV1Collector.PerformanceCounters = $Counters
  4. Create a schedule—start tomorrow morning at 07:00:
    $StartDate =
      Get-Date -Day $((Get-Date).Day+1) -Hour 7 -Minute 0 -Second 0
    $Schedule = $SRV1CS.Schedules.CreateSchedule()
    $Schedule.Days = 127
    $Schedule.StartDate = $StartDate
    $Schedule.StartTime = $StartDate
  5. Create, add, and start the collector set:
    try
    {
        $SRV1CS.Schedules.Add($Schedule)
        $SRV1CS.DataCollectors.Add($SRV1Collector) 
        $SRV1CS.Commit("$Name" , $null , 0x0003) | Out-Null
        $SRV1CS.Start($false);
    }
    catch 
    {
        Write-Host "Exception Caught starting PLA DC: " $_.Exception 
        Return
    }

How it works...

In step 1, you create and configure a new data collector set object (on SRV1). In step 2, you specify the performance counters you wish the data collector to collect. With step 3, you add those counters to the data collector. In step 4, you create a schedule telling the data collector when it should collect data. Finally, in step 5, you save the data collection details and start the data collection.

None of these steps produce output.

There's more...

In step 1, you assign the data collector's LogFileFormat to be 1. This tells PLA to create a log in binary format. When you create a data collector set, you could alternatively output using comma-separated values or tab-separated values, or as SQL records.

Setting the data collector's LogFileFormat property to 1 creates data in a comma-separated value format, while setting the property to 2 results in a tab-separated value format. Depending on the tools you use to analyze the output, different formats may be more appropriate.

In the GitHub repository supporting this book, you can find alternatives to this recipe that store the logging data in comma-separated and tab-separated formats. Note that other recipes in this chapter use different log file formats.

Adding a counter set and activating it generates data, and that consumes disk space. After using a counter set to analyze an issue, you might wish to stop data collection and possibly remove the counter set; you could do that as follows:

# Stop data collection
$DCStRemote = New-Object -COM Pla.DataCollectorSet
$Name = 'SRV1 Collector Set'
$DCstRemote.Query($Name,'LocalHost')
$DCstRemote.Stop($true)
# Remove the counter set 
$DCstRemote.Delete()

As noted, the steps in this recipe produce no output. Once you have completed the steps in this recipe, you can view the data collector inside perfmon, which looks like this:

There's more...
..................Content has been hidden....................

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