SECTION: 250-Configuration TITLE: 300stats QUESTION: Does Jetty support statistics gathering?

There are 2 sets of statistics available with Jetty. One is Jetty-specific, and the other conforms to the JSR77 specification. Both are accessible via the JMX console (see the README.TXT file for instructions on how to start Jetty with JMX) and the API.

Extended Jetty Statistics

To enable the Jetty-specific statistics, set statsOn to true in your Jetty configuration xml file before starting Jetty. There is an example of this in $JETTY_HOME/etc/jetty.xml. The relevant line is:


  <Set name="statsOn">true</Set>

You can also control statistics at runtime by using the JMX console or the API to call methods on the Server instance to: Statistics are gathered on a per-Server instance basis. Here are some of the statistics that Jetty will capture: Check the javadoc for the org.mortbay.http.HttpServer class for a full list of the statistics available.

JSR77 Statistics

In addition to the Jetty-specific statistics, since Jetty 5.1 the JSR77 specification is also supported.

To enable JSR77 style statistics, you will need the extra/jsr77 subproject. You can download it as part of the pre-built full Jetty release, or the pre-built extras package, or build it yourself from source (cd extras/jsr77; ant).

To enable the JSR77 statistics:

  1. add the following lines to your Jetty configuration xml file (copy from the $JETTY_HOME/etc/demo.xml file):
      
      <Set name="WebApplicationConfigurationClassNames">
        <Array type="java.lang.String">
          <Item>org.mortbay.jetty.servlet.XMLConfiguration</Item>
          <Item>org.mortbay.jetty.servlet.JettyWebConfiguration</Item>
          <Item>org.mortbay.jetty.servlet.jsr77.Configuration</Item>
        </Array>
      </Set>
      
      
  2. start Jetty with a command similar to:
    
      java -DSTART=extra/etc/start-jsr77.config -jar start.jar <name of your config file>
    
    
    For example, to enable JSR77 statistics for the demo shipped with Jetty:
    
      java -DSTART=extra/etc/start-jsr77.config -jar start.jar etc/demo-jmx.xml
    
    
The JMX console can be used to retrieve the statistics. There is one JSR77 object listed for each Servlet in each webapp. JSR77 objects are named according to the JSR77 spec, and will appear like so for Jetty:

  org.mortbay:J2EEServer=null,J2EEApplication=null,J2EEWebModule=<context-name>,j2EEType=Servlet,name=<servlet-name>

  eg
  org.mortbay:J2EEServer=null,J2EEApplication=null,J2EEWebModule=/servlets-examples,j2EEType=Servlet,name=HelloWorldExample 

For more information, refer to the JSR77 specification.