Sample script for retrieving publishing point status information

If you have read my previous blog here, you probably already know that in IIS Media Services 4.0 we’re exposing more detailed runtime status information about the live smooth streaming publishing points through RSCA APIs. The “Details” page of the publishing point UI retrieves information through the same APIs. As promised, here I’m publishing a sample Java script that we use internally to test those RSCA APIs. RSCA APIs were already used in IIS Media Services 3.0 to control the publishing point states (start/stop/shutdown). Ezequiel Jadib wrote a nice blog here showing how to use managed code to call RSCA APIs which you can reference if you want to port the sample script to managed code.

To run the sample script below, do cscript pubpointstats.js "Default Web Site" /test.isml when the publishing point is running and it will print out all the runtime status information. The schema of the RSCA APIs is included in “%SystemDrive%\Windows\System32\inetsrv\config\schema\IISMedia_schema.xml”.

//
// Checking input arguments
//
if(WScript.Arguments.length < 2 )
{
    WScript.Echo("Usage: pubpointstats.js <site name> <virtual path>");
    WScript.Echo("Example: cscript pubpointstats.js \"Default Web Site\" /test.isml");
    WScript.Quit(-1);
}

//
// Preparing site and path arguments
//
var site = WScript.Arguments(0);
var path = WScript.Arguments(1);
var index = path.lastIndexOf("/");
if(index == -1 )
{
    WScript.Echo(" Invalid path: " + path);
    WScript.Quit(-1);
}

var name = path.substring(index + 1);

WScript.Echo("Looking for publishing point: " + name + " under path:" + path);

//
// Setting up the RSCA method call through IIS configuration
//   
var ahAdmin = new ActiveXObject("Microsoft.ApplicationHost.AdminManager");
var liveSection = ahAdmin.GetAdminSection("system.webServer/media/liveStreaming", "MACHINE/WEBROOT/APPHOST/DEFAULT WEB SITE");
var method = liveSection.Methods.Item("GetPublishingPoints");
var methodInstance = method.CreateInstance();
methodInstance.Input.GetPropertyByName("siteName").Value = site;
methodInstance.Input.GetPropertyByName("virtualPath").Value = path;

//
// Execute the first method to get the instance of the publishing point
//
methodInstance.Execute();

var publishingPoints = methodInstance.Output.Collection

if(publishingPoints.Count == 0 )
{
    WScript.Echo("No publishing point " + WScript.Arguments(1) + " in site " + WScript.Arguments(0));
    WScript.Quit(-1);
}

var pubPoint = publishingPoints.Item(0);

//
// Execute GetInputStreams() RSCA call on the publishing point
//
method =  pubPoint.Methods.Item("GetInputStreams");
methodInstance = method.CreateInstance();
methodInstance.Execute();

//
// Print out publishing point attributes
//
var lastError = pubPoint.GetPropertyByName("lastError");
WScript.Echo("Last Error: " + lastError.Value);

var state = pubPoint.GetPropertyByName("state");
WScript.Echo("Current State: " + state.Schema.PossibleValues.Item(state.Value).Name);

var archivePath = pubPoint.GetPropertyByName("archivePath");
WScript.Echo("archivePath: " + archivePath.Value);

var inputStreams = methodInstance.Output.Collection
WScript.Echo("Number of Input Streams: " + inputStreams.Count);

//
// Looping through all input streams and print out stream level attributes
//
for (var i=0; i<inputStreams.Count; i++)
{
    var inputStream = inputStreams.Item(i);
    WScript.Echo("Stream " + i);
    WScript.Echo("\tStream ID: " + inputStream.GetPropertyByName("id").Value);
    var state =inputStream.GetPropertyByName("state");
    WScript.Echo("\tCurrent State: " + state.Schema.PossibleValues.Item(state.Value).Name);
    WScript.Echo("\tArchive File Name: " + inputStream.GetPropertyByName("archiveFileName").Value);

    var tracks = inputStream.GetElementByName("tracks").Collection;

    for (var n = 0; n < tracks.Count; n++)
    {
        var track = tracks.Item(n);
        WScript.Echo("\t\t-------------- Track " + n + " ------------------");
        WScript.Echo("\t\tTrack Name: " + track.GetPropertyByName("name").Value);
        WScript.Echo("\t\tTrack ID: " + track.GetPropertyByName("id").Value);
        WScript.Echo("\t\tEncoded Bitrate: " + track.GetPropertyByName("encodedBitrate").Value);
        WScript.Echo("\t\tIncoming Bitrate: " + track.GetPropertyByName("incomingBitrate").Value);
        WScript.Echo("\t\tIncoming Fragment Timestamp: " + track.GetPropertyByName("incomingFragmentTimestamp").Value);
        WScript.Echo("\t\tIncoming Fragment Duration: " + track.GetPropertyByName("incomingFragmentDuration").Value);
                WScript.Echo("\t\tIncoming Fragment Wait Time (ms): " + track.GetPropertyByName("incomingFragmentWaitTimeMs").Value);
        WScript.Echo("\t\tRequest per Second: " + track.GetPropertyByName("requestRate").Value);
    }

    var sources = inputStream.GetElementByName("sources").Collection;
    for (var n = 0; n < sources.Count; n++)
    {
        var source = sources.Item(n);
        WScript.Echo("\t\t-------------- Source " + n + " ------------------");
        WScript.Echo("\t\tSource Name: " + source.GetPropertyByName("name").Value);
        WScript.Echo("\t\tStatus String: " + source.GetPropertyByName("statusString").Value);
    }

    var sinks = inputStream.GetElementByName("sinks").Collection;
    for (var n = 0; n < sinks.Count; n++)
    {
        var sink = sinks.Item(n);
        WScript.Echo("\t\t-------------- Sink " + n + " ------------------");
        WScript.Echo("\t\tSink Name: " + sink.GetPropertyByName("name").Value);
        WScript.Echo("\t\tStatus String: " + sink.GetPropertyByName("statusString").Value);
    }
}

//
// Execute GetOutputStreams() RSCA call to get output info.
// Tracks are grouped into streams by their type (audio, video) in the output. Same as shown in the client manifest.
//
method =  pubPoint.Methods.Item("GetOutputStreams");
methodInstance = method.CreateInstance();
methodInstance.Execute();

var outputStreams = methodInstance.Output.Collection
WScript.Echo("Number of Output Streams: " + outputStreams.Count);

for (var i=0; i<outputStreams.Count; i++)
{
    var outputStream = outputStreams.Item(i);
    WScript.Echo("Stream " + i);
    WScript.Echo("\tStream Name: " + outputStream.GetPropertyByName("name").Value);
    WScript.Echo("\tLast Output Fragment Timestamp: " + outputStream.GetPropertyByName("lastOutputFragmentTimestamp").Value);
}

No Comments