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