Update: Get stream statistics from Wowza Media Server

Yesterday I discovered that the function in the article ‘Get stream statistics from Wowza Media Server’ was not working properly. It goes wrong when more Applications are loaded in Wowza. So I have changed the function and used ForEach loops instead of For loops. The For loop would also go wrong when there is only one stream in an Application. Because there is no count property in the XML object then.

Function Get-WowzaStreamStats{
    $webclient = new-Object System.Net.WebClient
    $webclient.credentials = new-Object system.Net.NetworkCredential("user", "password", "")
    [xml]$xml = $webclient.DownloadString("http://wowza-ip:8086/connectioncounts")

    foreach ($vhost in $xml.WowzaMediaServer.VHost) {
    
        foreach ($Application in $xml.WowzaMediaServer.VHost.Application) {

            foreach ($Stream in $Application.ApplicationInstance.Stream) {
                $Node = @{}
                
                $Node.TotalConnections = $Stream.SessionsTotal
                $Node.StreamName = $Stream.Name
                $Node.FlashConnections = $Stream.SessionsFlash
                $Node.SilverlightConnections = $Stream.SessionsSmooth
                $Node.RTSPConnections = $Stream.SessionsRTSP
                $Node.iOSConnections = $Stream.SessionsCupertino
                $Node.Application = $Application.name
                $Node.Vhost = $vhost.name
                
                $StreamStats = new-Object PSObject -Property $Node
                Write-Output $StreamStats
            }
        }
    }
}
Advertisements

Get stream statistics from Wowza Media Server

Recently I needed to know how many connections were made to a stream on our Wowza server, as real time as possible. For Windows Media Services you can use performance counters for that. And you can read these counters with PowerShell. I made a script for that in the past.

For Wowza I wanted something similar for that. The good thing is that Wowza has an xml interface that outputs the current connections. In default configuration you find the interface at http://wowza-ip:8086/connectioncounts. For humans the output is not very readable. So I made a function to parse the output.

Function Get-WowzaStreamStats{
    $webclient = new-Object System.Net.WebClient
    $webclient.credentials = new-Object system.Net.NetworkCredential("user", "password", "")
    [xml]$xml = $webclient.DownloadString("http://wowza-ip:8086/connectioncounts")

    for ($i=0; $i -lt $xml.WowzaMediaServer.VHost.Application.ApplicationInstance.Stream.Count; $i++) {
    $Node = @{}
    
    $Node.TotalConnections = $xml.WowzaMediaServer.VHost.Application.ApplicationInstance.Stream[$i].SessionsTotal
    $Node.StreamName = $xml.WowzaMediaServer.VHost.Application.ApplicationInstance.Stream[$i].Name
    $Node.FlashConnections = $xml.WowzaMediaServer.VHost.Application.ApplicationInstance.Stream[$i].SessionsFlash
    $Node.SilverlightConnections = $xml.WowzaMediaServer.VHost.Application.ApplicationInstance.Stream[$i].SessionsSmooth
    $Node.RTSPConnections = $xml.WowzaMediaServer.VHost.Application.ApplicationInstance.Stream[$i].SessionsRTSP
    $Node.iPadConnections = $xml.WowzaMediaServer.VHost.Application.ApplicationInstance.Stream[$i].SessionsCupertino
    
    $StreamStats = new-Object PSObject -Property $Node
    Write-Output $StreamStats
    }
}

The output of the function is an object. So you can use it in the pipeline. For example you can type:
Get-WowzaStreamStats | Where-Object {$_.StreamName –eq ‘name.stream’}