Jetty has a bunch of JMX instrumentation available, but it is normally not active by default. There is a little bit of documentation out there describing it, but not a simple explanation of how to really enable it. I eventually figured it out, so here goes.
This was all tested with Jetty 6.1.22 and Java 1.6u16.
At the top of your jetty.xml, setup the MBeanServer by adding this:
<Call id="MBeanServer" class="java.lang.management.ManagementFactory" name="getPlatformMBeanServer"/> <Get id="Container" name="container"> <Call name="addEventListener"> <Arg> <New class="org.mortbay.management.MBeanContainer"> <Arg><Ref id="MBeanServer"/></Arg> <Call name="start" /> </New> </Arg> </Call> </Get>
Then, at the bottom of your jetty.xml add this (sets a request stats handler as top-level handler, see here for more):
<Get id="oldhandler" name="handler"/> <Set name="handler"> <New id="StatsHandler" class="org.mortbay.jetty.handler.AtomicStatisticsHandler"> <Set name="handler"><Ref id="oldhandler"/></Set> </New> </Set>
Note that the order in which this stuff appears in the jetty.xml file matters. If you don't setup the MBeanServer at the beginning, subsequent components won't register themselves with JMX. This was the key that I missed out on at first, but finally realized after reading this post on the jetty-user mailing list.
You may also want to make sure you have statsOn enabled on your Connector:
<Call name="addConnector"> <Arg> <New class="org.mortbay.jetty.nio.SelectChannelConnector"> <Set name="host"><SystemProperty name="jetty.host" /></Set> <Set name="port"><SystemProperty name="jetty.port" default="8080"/></Set> <Set name="maxIdleTime">30000</Set> <Set name="Acceptors">2</Set> <Set name="statsOn">true</Set> <Set name="confidentialPort">8443</Set> <Set name="lowResourcesConnections">5000</Set> <Set name="lowResourcesMaxIdleTime">5000</Set> </New> </Arg> </Call>
For command line monitoring of these stats, JMXTerm seems reasonable.
Now, if you want to remotely monitor these stats with jconsole or VisualVM and you've got a firewall... that's another story, and is a complete clusterfuck (not Jetty's fault though). I will write more on that topic later. Read the comments in etc/jetty-jmx.xml that ships with Jetty to see more.