Mar 242010
 

I wanted to get the current number of connected users and used bandwidth of a publishing point on windows streaming media services. I had been watching this with the performance monitor, but I wanted something I could manipulate.

http://www.jkrb.de/jmk/docs/Perl5/PerfLib/PerfLib.html

http://docs.activestate.com/activeperl/5.8/lib/Win32/PerfLib.html

http://www.xav.com/perl/site/lib/Win32/PerfLib.html

http://technet.microsoft.com/en-us/library/cc730642%28WS.10%29.aspx

Sample code follows.

use Win32::PerfLib;
my $server = "servername";
Win32::PerfLib::GetCounterNames($server, %hashref);
%r_counter = map { $hashref{$_} => $_ } keys %hashref;
# retrieve the id for process object
$objectid = $r_counter{'Windows Media Publishing Points'};

# create connection to $server
$perflib = new Win32::PerfLib($server);
$proc_ref = {};
# get the performance data for the process object
$perflib->GetObjectList($objectid, $proc_ref);
$perflib->Close();
$instance_ref = $proc_ref->{Objects}->{$objectid}->{Instances};
foreach $p (sort keys %{$instance_ref})
{
if($instance_ref->{$p}->{Name} =~ /PUBLISHINGPOINT/) {
$hashref_ref = $instance_ref->{$p}->{Counters};
foreach $i (keys %{$hashref_ref})
{

Advertisement:

# Current Player Allocated Bandwidth (Kbps) (2888)
if($hashref_ref->{$i}->{CounterNameTitleIndex} == 2888)
{
$bandwidth = $hashref_ref->{$i}->{Counter};
}

# Current Connected Players (2892)
if($hashref_ref->{$i}->{CounterNameTitleIndex} == 2892)
{
$listeners = $hashref_ref->{$i}->{Counter};
}
}
}
}

#Print to console
print “Bandwidth: ” . $bandwidth . “t Listeners: ” . $listeners . “n”;

# Peak Player Allocated Bandwidth (Kbps) (2910)
# Total Streaming Players (2930)
# Current Streaming Players (2902)
# Current Streaming Players (2902)
# Total Outgoing Distribution Bytes Sent (2940)
# Total Outgoing Distribution Connections (2922)
# Current Connected Players (2892)
# Total Stream Terminations (2932)
# Current Outgoing Distribution Allocated Bandwidth (Kbps) (2890)
# Total Late Reads (2924)
# Current Player Allocated Bandwidth (Kbps) (2888)
# Current Player Allocated Bandwidth (Kbps) (2888)
# Total Advertisements (2934)
# Total Connected Players (2920)
# Peak Connected Players (2914)
# Total Player Bytes Sent (2938)
# Current Streaming RTSP Players (2900)
# Current Streaming HTTP Players (2894)
# Current Stream Error Rate (2906)
# Peak Outgoing Distribution Allocated Bandwidth (Kbps) (2912)
# Total Stream Errors (2928)
# Peak Outgoing Distribution Connections (2916)
# Peak Streaming Players (2918)
# Current Late Read Rate (2904)
# Current Streaming MMS Players (2896)
# Total File Bytes Read (2936)
# Total Stream Denials (2926)
# Current File Read Rate (Kbps) (2908)
# Current Outgoing Distribution Connections (2898)

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)