« AudioVideoStreamer with Flashcom. First Approach | Inicio | bugs in FCS »

Get the stats of your apps in flashcom

Here are two similar but a bit differents ways of get stats of your apps. both of them use a persisten Shared objet but, one get the global stats with application.getStats() and override the So, and the other one get the stats of each client session with clien.getStats() and add the values to the persisten SharedObject. You can use both in the same app

let's see the codes

Case one

application.onAppStart=function(){ //So onAppStart. there is created when the app starts the first time my_so=SharedObject.get("el_so",true); mis_stats={bytes_in:0, bytes_out:0, msg_in:0, msg_out:0, msg_dropped:0, total_connects:0, total_disconnects:0}; my_so.setProperty("appStats", mis_stats); }; application.onConnect=function(newClient){ application.acceptConnection(newClient); trace("new user"); }; application.onDisconnect=function(oldClient){ trace("User disconnected"); stats = application.getStats(); trace("Total bytes received: " + stats.bytes_in); trace("Total bytes sent : " + stats.bytes_out); trace("RTMP messages received : " + stats.msg_in); trace("RTMP messages sent : " + stats.msg_out); trace("RTMP messages dropped : " + stats.msg_dropped); trace("Total clients connected : " + stats.total_connects); trace("Total clients disconnected : " + stats.total_disconnects); //Give data to SO my_so.setProperty("appStats", stats); //force to save my_so.flush(); //Let´s check that all is ok //get so slot var the_stats=my_so.getProperty("appStats"); //see data on screen trace("check data"); for(var prop in the_stats){ trace(prop+" : "+the_stats[prop]); } };

the other way is

application.onAppStart=function(){ my_so=SharedObject.get("el_so",true); mis_stats={bytes_in:0, bytes_out:0, msg_in:0, msg_out:0, msg_dropped:0, ping_rtt:0}; my_so.setProperty("appStats", mis_stats); }; application.onConnect=function(newClient){ application.acceptConnection(newClient); trace("nuevo usuario conectado"); }; application.onDisconnect=function(oldClient){ trace("user disconnected"); stats = oldClient.getStats(); trace("Total bytes received : " + stats.bytes_in); trace("Total bytes sent : " + stats.bytes_out); trace("RTMP messages received : " + stats.msg_in); trace("RTMP messages sent: " + stats.msg_out); trace("RTMP messages dropped : " + stats.msg_dropped); trace("Ping roundtrip time: " + stats.ping_rtt); //Let´s add the stats of the session to the total stats //get so slot var the_stats=my_so.getProperty("appStats"); //add values for (var prop in the_stats){ the_stats[prop]=the_stats[prop]+stats[prop]; } //save my_so.setProperty("appStats", the_stats); //Force to save to disk my_so.flush(); //Let´s check //get SO data var comprobacion=my_so.getProperty("appStats"); //on screen trace("Comprobación de los datos"); for(var prop in comprobacion){ trace(prop+" : "+comprobacion[prop]); } };

and that's all. You must see the traces on your communciation app inspector. Te client side to this sample is only this.

nc=new NetConnection(); nc.onStatus=function(info){ trace(info.level); trace(info.code); } a.onRelease=function(){ nc.connect("rtmp:/test"); } b.onRelease=function(){ nc.close(); }

As always, sorry for my horrible english