5 Replies Latest reply: Apr 10, 2012 4:30 AM by JayCharles RSS

    AppStats using onGetAppStats() in main.asc

    poojapooja

      Hi,

      I am trying to collect appstats using this code in main.asc.

      What is wrong here?

       

      application.onConnect = function( p_client, p_autoSenseBW )

      {

           this.acceptConnection(p_client);

         

           nc_poll=new NetConnection();

           nc_poll.connect("rtmp://localhost:1111/admin","admin","a1s2d3f4");

           nc_poll.call("getAppStats",new onGetAppStats(), "vod");   

          

          function onGetAppStats()

          {

          this.onResult = function(info)

          {

            trace("POOJA 1111");

            outputBox.text = "Info for "+appName.text+ " returned:" + newline;

            trace("POOJA 2222");

            printObj(info, outputBox);

           

          }

       

          }

       

          function printObj(obj, destination)

          {

           trace("POOJA 3333");

           for (var prop in obj)

          {

           destination.text += "\t";

           destination.text += prop + " = " + obj[prop] + newline;

           if (typeof (obj[prop]) == "object")

           {

           trace("POOJA 4444");

            printObj(obj[prop], destination);

           }

         }

        }

         

      }

       

      thanks

        • 1. Re: AppStats using onGetAppStats() in main.asc
          JayCharles Community Member

          1. Wait for the onStatus event from the NetConnection before invoking methods. Otherwise, you may be calling a method on a netconnection that hasn't been completed.

           

          2. Are you defining the nc_poll variable outside of the onConnect method? If not, the scope of nc_poll is the onConnect function, so when the function returns, the nc_poll variable will have gone out of scope, and will be eligible for garbage collection.

          • 2. Re: AppStats using onGetAppStats() in main.asc
            poojapooja Community Member

            Hi JayCharles,

            I think onStatus event is received as seen in logs:

            2012-04-09  16:39:05    16248   (s)2641173  ******RECEIVED ONSTATUS******   -

             

            Main.asc file code is as below, Pls help.


            var nc_poll;

             

            application.onConnect = function( p_client, p_autoSenseBW )

            {

              this.acceptConnection(p_client);

              nc_poll=new NetConnection();

              nc_poll.onStatus = function(info)

              {

               trace("******RECEIVED ONSTATUS******");

              }

            nc_poll.connect("rtmp://localhost:1111/admin","admin","admin123");

             

            function onGetAppStats()

              {

                this.onResult = function(info)

                {

                  trace("POOJA 1111");

                  outputBox.text = "Info for "+appName.text+ " returned:" + newline;

                  trace("POOJA 2222");

                  printObj(info, outputBox);

               }

              }

              function printObj(obj, destination)

              {

               trace("POOJA 3333");

               for (var prop in obj)

               {

                destination.text += "\t";

                destination.text += prop + " = " + obj[prop] + newline;

                if (typeof (obj[prop]) == "object")

                 {

                  trace("POOJA 4444");

                  printObj(obj[prop], destination);

                 }

               }

              }

             

            nc_poll.call("getAppStats",new onGetAppStats(), "vod");  

             

            }

            • 3. Re: AppStats using onGetAppStats() in main.asc
              JayCharles Community Member

              You're still calling getAppStats on the connection without being sure the connection is established. Invoke a method outside of onConnect in response to the onStatus event.

              • 4. Re: AppStats using onGetAppStats() in main.asc
                poojapooja Community Member

                Thanks Jay, i could write the correct code!!

                One query: This is giving stats when onConnect() is called from main.asc.

                If i need stats at just any time, where should i call admin api from?

                 

                thanks.

                 

                var nc_poll;

                application.onConnect = function( p_client, p_autoSenseBW )

                {

                  this.acceptConnection(p_client);

                  nc_poll=new NetConnection();

                  nc_poll.connect("rtmp://localhost:1111/admin","admin","admin");

                  nc_poll.onStatus = function(info)

                  {

                    if (info.code == "NetConnection.Connect.Success" && nc_poll.isConnected)

                    {

                      trace("We are connected");

                      nc_poll.call("getInstanceStats",new onGetInstanceStats(), "vod/_defInst_");  

                   }

                  }

                 

                  function onGetInstanceStats()

                  {

                    this.onResult = function(info)

                    {

                      trace("POOJA 1111");

                    var dataobj=info.data;

                    trace("TOTAL NUMBER OF CONNECTIONS CURRENTLY ACTIVE: " +dataobj.connected);

                    trace("NUMBER OF CONNECTION ATTEMPTS ACCEPTED BY THIS APPLICATION: "+dataobj.accepted);

                    trace("NUMBER OF BYTES READ BY THIS APPLICATION: " +dataobj.bytes_in);

                    trace("NUMBER OF SOCKET CONNECTIONS TO THE APPLICATION SINCE THE APPLICATION WAS STARTED: " +dataobj.total_connects);

                    trace("POOJA 2222");

                    }

                  }

                }

                • 5. Re: AppStats using onGetAppStats() in main.asc
                  JayCharles Community Member

                  Create the connection in your onAppStart method, rather than the onConnect method.

                   

                  Alternately, you can create a new class to manage this, and instantiate an instance of that class in your onAppStart.