Wednesday, August 24, 2011

Storing 'Get-counter' data

You can do this:

((get-counter -counter '\\rmfvpc\TCPv4\Connections Established').countersamples) | % {$_.CookedValue}

and this:

(get-counter -counter '\\rmfvpc\TCPv4\Connections Established').Readings | findstr ^[0-9]

and this:

(get-counter -counter '\\rmfvpc\TCPv4\Connections Established' -continuous -sampleinterval 2)

but you can't do this:

(get-counter -counter '\\rmfvpc\TCPv4\Connections Established' -continuous -sampleinterval 2).countersamples

or this:

(get-counter -counter '\\rmfvpc\TCPv4\Connections Established' -continuous -sampleinterval 2).Readings

or this:

[array]$a=(get-counter -counter '\\rmfvpc\TCPv4\Connections Established' -continuous -sampleinterval 2)

Therefore I ended up with this (which works):

while($true) {foreach ($i in (get-counter -counter '\\rmfvpc\TCPv4\Connections Established')) {$i.Readings | findstr ^[0-9]};sleep -seconds 2}

or this:

while($true) {foreach ($i in (get-counter -counter '\\rmfvpc\TCPv4\Connections Established')) {$i.countersamples | % {$_.CookedValue}};sleep -seconds 2}

and one these (which also works):

while($true) {[array]$b+=foreach ($i in (get-counter -counter '\\rmfvpc\TCPv4\Connections Established').countersamples) {$i | % {$_.CookedValue}};sleep -seconds 2}

 while($true) {[array]$b+=foreach ($i in (get-counter -counter '\\rmfvpc\TCPv4\Connections Established')) {$i.Readings | findstr ^[0-9]};sleep -seconds 2}


But it all seems just a little ungainly!  Here's how I got there:

get-counter -ListSet * | findstr "CounterSetName" | Sort
CounterSetName     : .NET CLR Data
CounterSetName     : .NET Memory Cache 4.0
CounterSetName     : ASP.NET v4.0.30319
CounterSetName     : Authorization Manager Applications
CounterSetName     : Browser
CounterSetName     : Cache
CounterSetName     : Database

(get-counter -ListSet Memory).Counter  | Sort
\Memory\% Committed Bytes In Use
\Memory\Available Bytes
\Memory\Available KBytes
\Memory\Free & Zero Page List Bytes
\Memory\Free System Page Table Entries
\Memory\Modified Page List Bytes
(get-counter -ListSet 'TCPv4').Paths  | Sort
\TCPv4\Connection Failures
\TCPv4\Connections Active
\TCPv4\Connections Established
\TCPv4\Connections Passive
\TCPv4\Connections Reset
\TCPv4\Segments Received/sec
\TCPv4\Segments Retransmitted/sec
\TCPv4\Segments Sent/sec

get-counter -counter '\\rmfvpc\TCPv4\Connections Established' -continuous -sampleinterval 10

Timestamp                 CounterSamples
---------                 --------------
8/24/2011 10:36:24 AM     \\rmfvpc\tcpv4\connections established :

8/24/2011 10:36:34 AM     \\rmfvpc\tcpv4\connections established :

Update 08/30/2011:

This one liner:

while($true) {foreach ($i in (get-counter -counter '\\rmfvpc\TCPv4\Connections Established')) {write-host -backgroundcolor red "$($i.countersamples | % {$_.CookedValue}) Established Connections"};sleep -seconds 2;clear}

produces a nice flashing update of the number of TCPv4 connections. Looks like this:

No comments: