Hi (sorry for HTML email, I hate it too, but there is some code in the message)

Today with Trustin mod on IoService for adding session life cycle listening, I made a StatCollector class for collecting stats on session throughput in bytes and in PDU (note to Emmanuel : no it's not for you this one ;) ).

Second addition is an IoService MBean and an IoSessionMBean for displaying stats and utility function with JMX.


It's commited in my sandbox and work with last MINA's trunk :
http://svn.apache.org/viewvc/directory/sandbox/jvermillard/jmx/src/

How to add the MBean to an IoService :

acceptor = new SocketAcceptor();
       
         // JMX instrumentation
        try {
            IoServiceManager iosm=new IoServiceManager(acceptor);
            MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();  
            ObjectName name = new ObjectName("com.acme.test:type=IoServiceManager,name=MyMINAServer");
            mbs.registerMBean(iosm, name);
           
        } catch (JMException e) {
            logger.error("JMX Exception : ",e);
        }

Now if for each session of the service you want a MBean binded to the session for managing it individualy add :

    acceptor.addListener(new IoServiceListener() {

            public void serviceActivated( IoService service, SocketAddress serviceAddress, IoHandler handler, IoServiceConfig config )
            {
            }

            public void serviceDeactivated( IoService service, SocketAddress serviceAddress, IoHandler handler, IoServiceConfig config )
            {
            }

            public void sessionCreated( IoSession session )
            {
                try {
                    IoSessionManager sessMgr=new IoSessionManager(session);
                    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();  
                    ObjectName name = new ObjectName("com.acme.test.session:type=IoSessionManager,name="+session.getRemoteAddress().toString().replace(':','/'));
                    mbs.registerMBean(sessMgr, name);
                } catch (JMException e) {
                    logger.error("JMX Exception : ",e);
                }      
            }

            public void sessionDestroyed( IoSession session )
            {
                try {
                    ObjectName name = new ObjectName("com.acme.test.session:type=IoSessionManager,name="+session.getRemoteAddress().toString().replace(':','/'));
                    ManagementFactory.getPlatformMBeanServer().unregisterMBean(name);
                } catch (JMException e) {
                    logger.error("JMX Exception : ",e);
                }      
            }
        });

When your server is started, you can fire JConsole (installed with jdk 1.5) click on MBeans tab and got to you can see your IoServiceManagerBeam. For start collecting stats click on "startCollectingStats" and giving a polling time in milliseconds (5000 is a good value).

The IoSession MBean will display the stats related to the session, a list of currently installed filter, some other stat and the possiblity to add/remove a LoggingFilter at the begining or end of the filter.

The stat collecting is a huge subject and I usualy have only 2 or 3 connections on my tiny embedded servers ;)
So any code review, test, critisim and idea welcomed and helpfull !

Julien

P.S : Rumors of MINA 1.0 without JMX support are greatly exagerated ;)

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to