Performance counter for each instance of the process.

This topic contains 4 replies, has 2 voices, and was last updated by  Pavel 1 day, 20 hours ago.

  • Author
    Posts
  • #81575

    Pavel
    Participant

    Hi,
    I am trying to monitor each IIS instance on my machine.
    There are 3 of them that i can see in perfmon window:
    w3wp
    w3wp#1
    w3wp#2

    theCounter from the initiation:

    $theCounter=(get-counter -listset Process).PathsWithInstances | Where-Object { $_ -like "*w3wp*" -and 
                                                                $_ -like "*Processor Time*"} 

    has following output:
    PS C:\Windows\system32> $theCounter
    \Process(w3wp)\% Processor Time
    \Process(w3wp)\% Processor Time
    \Process(w3wp)\% Processor Time

    There are same 3 processes , but without the #

    It'ss causing problems when I am executing something like:

    Get-counter -Counter $theCounter -SampleInterval 2 -MaxSamples 10  | Export-counter -Force -Path  C:\theTest.blg

    In final BLG file I can see only one line and it is clear why – all numbers were written under same counter name.
    There is no possibility here to differentiate between processes.

    Any suggestions how can I get counters with the # ?

    Thanks.

  • #81592

    Don Jones
    Keymaster

    I'm not sure the perf counters actually distinguish. From their perspective, it's just like running multiple copies of Notepad, right? Let me dig into it a bit, though and see if I can figure it out.

  • #81610

    Pavel
    Participant

    Yes, exactly as few Notepads.
    Thanks.

  • #81655

    Pavel
    Participant

    I found some workaround using typeperf that gives me an IDs:

    $fo = [System.IO.Path]::GetTempFileName()
    typeperf -f CSV "\Process(*)\% Processor Time" -sc 1 -o $fo -y | Out-Null
    $t = import-csv $fo -Delimiter "," 
    $t

    Now the challenge is to get list of processes names from object $t, filtering it by specific process name "w3wp"...
    Any suggestions how to do it?

  • #82289

    Pavel
    Participant

    Hi,
    I just created some solution script for the issue.
    Putting it here to whom could be interested in it.
    It looks like:

    function getProcessesWithInstancesCounters($countersList)  {
        $fo = [System.IO.Path]::GetTempFileName()
        typeperf -f CSV $countersList -sc 1 -o $fo -y | Out-Null
        $t = (import-csv $fo) 
        $t=([regex]::replace([regex]::replace([string]$t, "(=[0-9]*)", ""),"[:}]","")  | Where-Object {$_ -like '*\\*' }) 
        $t=$t | Out-String 
        del $fo
        $t -split ";" 
    }
    
    $counters= ((getProcessesWithInstancesCounters (get-counter -ComputerName 1.10.241.61 -listset Process).Paths) | foreach {$_.Trim()} | Where-Object { 
                                                                  $_ -notlike "*Peak*" -and $_ -like "*w3wp*" -and (
                                                                $_ -like "*Processor Time*" -or
                                                                $_ -like "*Private Bytes*" -or
                                                                $_ -like "*Virtual Bytes*" -or
                                                                $_ -like "*Working Set*")}) 
    
    Get-counter -Counter $counters -SampleInterval 2 -MaxSamples 25 | Export-counter -Force -Path  D:\DeleteMe\PowerShell\ProcessDetiled.blg

You must be logged in to reply to this topic.