Version: 9.4.30.v20200611 |

Statistics Handler
Previous | Chapter 18. Provided Servlets, Filters, and Handlers Home | Next

##### Contact the core Jetty developers at www.webtide.com

private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ... scalability guidance for your apps and Ajax/Comet projects ... development services for sponsored feature development

## Statistics Handler

### Info

- Classname: `org.eclipse.jetty.server.handler.StatisticsHandler`
- Maven Artifact: org.eclipse.jetty:jetty-server
- Javadoc: http://www.eclipse.org/jetty/javadoc/9.4.30.v20200611/org/eclipse/jetty/server/handler/StatisticsHandler.html

### Usage

Jetty currently has two levels of request statistic collection:

- Subclasses of `AbstractConnector` class optionally can collect statistics about connections as well as number of requests.
- The `StatisticsHandler` class may be used to collect request statistics.

In addition to these, subclasses of the `SessionHandler` and `DefaultSessionCache` classes optionally can collect session statistics.

`AbstractConnector`, `SessionHandler` and `DefaultSessionCache` statistics are turned off by default and must either be configured manually for each instance or turned on via JMX interface. The `StatisticsHandler` is not included in default Jetty configuration, and needs to be configured manually.

> ### Note

> To view statistics, you have to be able to connect to Jetty using either JConsole or some other JMX agent. See Using JMX with Jetty for more information.

### Connector statistics

Detailed statistics on connection duration and number of requests are only collated when a connection is closed. The current and maximum number of connections are the only "live" statistics.

The following example shows how to turn on connector statistics in Jetty xml. This example comes from within `jetty-http.xml`.

      <Call name="addConnector">
        <Arg>
          <New class="org.eclipse.jetty.server.ServerConnector">
            <Arg name="server"><Ref refid="Server" /></Arg>
            <Arg name="factories">
              <Array type="org.eclipse.jetty.server.ConnectionFactory">
                <Item>
                  <New class="org.eclipse.jetty.server.HttpConnectionFactory">
                    <Arg name="config"><Ref refid="httpConfig" /></Arg>
                  </New>
                </Item>
              </Array>
            </Arg>
            <Set name="host"><Property name="jetty.host" /></Set>
            <Set name="port"><Property name="jetty.http.port" default="8080" /></Set>
            <Set name="idleTimeout">30000</Set>
            <!-- Enable Connection Statistics -->
            <Call name="addBean">
              <Arg>
                  <New id="ConnectionStatistics" class="org.eclipse.jetty.io.ConnectionStatistics"/>
              </Arg>
            </Call>
          </New>
        </Arg>
      </Call>

### Request Statistics

To collect request statistics a `StatisticsHandler` must be configured as one of the handlers of the server. Typically this can be done as the top level handler, but you may choose to configure a statistics handler for just one context by creating a context configuration file. You can enable the `StatisticsHandler` by activating the `stats` modules on the command line.

    $ java -jar {$jetty.home}/start.jar --add-to-start=stats

Alternately, if you are making multiple changes to the Jetty configuration, you could include statistics handler configuration into your own Jetty xml configuration. The following fragment shows how to configure a top level statistics handler:

        <Get id="oldhandler" name="handler" />
      <Set name="handler">
        <New id="StatsHandler" class="org.eclipse.jetty.server.handler.StatisticsHandler">
          <Set name="handler"><Ref refid="oldhandler" /></Set>
        </New>
      </Set>

### Session Statistics

Session handling is built into Jetty for any servlet or webapp context. Detailed statistics on session duration are only collated when a session is closed. The current, minimum, and maximum number of sessions are the only "live" statistics. The session statistics are enabled by default and do not need to be configured.

Previous | Top | Next
Debug Handler | Home | IP Access Handler

See an error or something missing? Contribute to this documentation at Github!(Generated: 2020-06-11)