Calculate total bandwidth (inbound and outbound) of a published stream
I have a requirement to measure the total bandwidth used by a live event. This would include the inbound bandwidth, either re-streaming from Shoutcast or from a Flash client. Plus the total bandwidth consumed by all resulting play streams, whether they are Flash clients, Cupertino streaming, etc.
Is there a reasonable approach to this using the Java API? It would be preferable to be able to do this programatically and in real-time, rather than by parsing log files.
Have a look at the IOMedia object for each type of client this does provide the information you need.
A quick off the top of my head piece of code
IVHost ThisVHostIns = VHostSingleton.getInstance("_defaultVHost_");
IApplication ThisApp = ThisVHostIns.getApplication("myapplicationname");
// Warning you should iterate across Application Instances here not just
// _definst_, however this is just a framework example
IApplicationInstance ThisAppIns = ThisApp.getAppInstance("_definst_");
List<IClient> RTMPClients = ThisAppIns.getClients();
// Example only for RTMPClients
double rateOutAvg = 0;
double rateInAvg = 0;
Iterator<IClient> ClientIter = RTMPClients.iterator ( ) ;
while ( ClientIter.hasNext() )
IClilent ThisClient = ClientIter.next();
if ( ThisClient == null )
IOPerformanceCounter Test = ThisClient.getMediaIOPerformanceCounter();
long ByteRateOut = Test.getMessagesOutBytes();
long ByteRateIn = Test.getMessagesInBytes();
double SecondsConnected = ThisClient.getTimeRunningSeconds();
rateOutAvg += ByteRateOut/SecondsConnected;
rateInAvg += ByteRateIn/SecondsConnected;
// Bitrate for RTMP clients average is
getLogger().info("Output rate is "+rateOutAvg);
getLogger().info("Input rate is "+rateInAvg);
you will need to do the HTTP and RTP clients as the above only shows RTMP being run through and calculated.
If you want it periodically then you would need to set up a work thread to run through this at set time intervals.