Caucho maker of Resin Server | Application Server (Java EE Certified) and Web Server


 

Resin Documentation

home company blog docs 
app server 
 Resin Server | Application Server (Java EE Certified) and Web Server
 

jmx


JMX Consoles provide access to both the MBean's that Resin publishes for information about and control of the Resin server and Application specific MBeans.

JDK 5.0 and JMX

JDK 5.0 includes a JMX implementation that is used to provide local and remote administration of a Resin server.

Start Resin and allow local JMX administration
win> ./resin.exe -Dcom.sun.management.jmxremote
unix> bin/resin.sh -Dcom.sun.management.jmxremote
Start jconsole
win> jconsole.exe
unix> jconsole

Choose Resin's JVM from the "Local" list.
Start Resin and allow remote JMX administration
win> ./resin.exe -Dcom.sun.management.jmxremote.port=9999
unix> bin/resin.sh -Dcom.sun.management.jmxremote.port=9999

Without some configuration effort, the previous command will not work. Password configuration and SSL configuration is required by the JDK implementation of remote JMX. Detailed instructions are included in the JDK documentation.

The following is useful for testing, but should be done with caution as the port is not protected by password or by SSL, and if not protected by a firewall is accessible by anyone who can guess the port number.

Start Resin and remote JMX - disable password checking and SSL

win> ./resin.exe -Dcom.sun.management.jmxremote.port=9999
                    -Dcom.sun.management.jmxremote.ssl=false
                    -Dcom.sun.management.jmxremote.authenticate=false

unix> bin/resin.sh -Dcom.sun.management.jmxremote.port=9999 \
                      -Dcom.sun.management.jmxremote.ssl=false \
                      -Dcom.sun.management.jmxremote.authenticate=false
Start jconsole
win> jconsole.exe
unix> jconsole

Enter the host name and port number (9999) on the "Remote" tab
Setting a password for remote JMX access
$ cd $JAVA_HOME/jre/lib/management
$ cp jmxremote.password.template jmxremote.password
$ chmod u=rw jmxremote.password
$ vi jmxremote.password

Set a password for "monitorRole" and "controlRole":

monitorRole 12monitor
controlRole 55control
Start Resin and remote JMX - disable SSL

win> ./resin.exe -Dcom.sun.management.jmxremote.port=9999
                    -Dcom.sun.management.jmxremote.ssl=false

unix> bin/resin.sh -Dcom.sun.management.jmxremote.port=9999 \
                      -Dcom.sun.management.jmxremote.ssl=false

Start jconsole
win> jconsole.exe
unix> jconsole
  1. Enter the host name and port number (9999) on the "Remote" tab
  2. Enter the username and password on the "Remote" tab

Instrumenting Resources

Instrumenting resources so JMX can manage them consists of the following steps:

  1. For a class MyFoo, create an interface MyFooMBean with the management interface.
  2. Class MyFoo would implement the MyFooMBean interface.
  3. Register MyFoo with the JMX server.

Instrumenting a servlet

Resin will automatically register any servlet which implement an MBean interface. By default, the JMX name will be:

web-app:j2eeType=Servlet,name=servlet-name
ObjectName attributes
ATTRIBUTEVALUE
j2eeTypeServlet
WebModulethe contextPath
J2EEApplicationthe host?
J2EEServerthe server-id?

The domain is web-app, the type property is javax.servlet.Servlet and the name property is the value of Servlet's <servlet-name>.

JMX clients will use the name to manage the servlet. For example, a client might use the pattern web-app:type=javax.servlet.Servlet,* to retrieve all managed servlets.

MyServletMBean.java
package test;

public interface MyServletMBean {
  public int getCount();
}
MyServlet.java
package test;

import java.io.*;
import javax.servlet.*;

public class MyServlet extends GenericServlet implements MyServletMBean {
  private int count;

  public int getCount()
  {
    return count;
  }

  public void service(ServletRequest request,
                      ServletResponse response)
    throws IOException
  {
    PrintWriter out = response.getWriter();

    count++;

    out.println("Hello, world");
  }
}

Managing Resources

Managing resources uses the JMX API, primarily using the javax.management.MBeanServer object. In Resin, each web-app has its own MBeanServer.

Getting the Count attribute
import javax.management.*;

...

MBeanServer server = MBeanServerFactory.createMBeanServer();

ObjectName name = new ObjectName("web-app:j2eeType=javax.servlet.Servlet," +
                                 "name=hello");

Object value = server.getAttribute(name, "Count");

out.println("Count: " + value);

Interpreting the proxy cache hit ratio

The proxy cache is Resin's internal proxy cache (in Resin Pro). The hit ratio marks what percentage of requests are served out of the cache, i.e. quickly, and which percentage are taking the full time.

The proxy cache hit ratio is useful for seeing if you can improve your application's performance with better caching. For example, if you had a news site like www.cnn.com, you should have a high hit rate to make sure you're not overtaxing the database.

If you have a low value, you might want to look at your heavily used pages to see if you can cache more.


Copyright © 1998-2015 Caucho Technology, Inc. All rights reserved. Resin ® is a registered trademark. Quercustm, and Hessiantm are trademarks of Caucho Technology.