Merge remote-tracking branch 'origin/jetty-9.4.x' into jetty-10.0.x

This commit is contained in:
Lachlan Roberts 2020-09-25 15:20:25 +10:00
commit 11465791cc
2 changed files with 56 additions and 66 deletions

View File

@ -29,60 +29,25 @@
[[statistics-handler-usage]] [[statistics-handler-usage]]
==== Usage ==== Usage
Jetty currently has two levels of request statistic collection: Jetty currently has two main statistics collection mechanisms:
* Subclasses of `AbstractConnector` class optionally can collect statistics about connections as well as number of requests. * Instances of `ConnectionStatistics` can collect statistics for each connection of a connector.
* The `StatisticsHandler` class may be used to collect request statistics. * The `StatisticsHandler` class may be used to collect statistics for HTTP requests.
In addition to these, subclasses of the `SessionHandler` and `DefaultSessionCache` classes optionally can collect session statistics. The `StatisticsHandler` and `ConnectionStatistics` are not included in the default Jetty configuration, these need to be configured manually or enabled using the Jetty `stats` module on the command line.
[source, screen, subs="{sub-order}"]
....
$ java -jar {$jetty.home}/start.jar --add-to-start=stats
....
`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. In addition to these, the `SessionHandler` and `DefaultSessionCache` classes collect statistics for sessions.
The `StatisticsHandler` is not included in default Jetty configuration, and needs to be configured manually. These statistics are enabled by default and are accessible via JMX interface.
_____ _____
[NOTE] [NOTE]
To view statistics, you have to be able to connect to Jetty using either JConsole or some other JMX agent. See xref:using-jmx[] for more information. To view statistics, you have to be able to connect to Jetty using either JConsole or some other JMX agent. See xref:using-jmx[] for more information.
_____ _____
[[connector-statistics]]
==== 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.
//To learn how to turn on connector statistics please see the Jetty Statistics tutorial, although this is not recommended and it is best to use a JMX agent to select statistics only when needed.
The following example shows how to turn on connector statistics in Jetty xml.
This example comes from within `jetty-http.xml`.
[source, xml, subs="{sub-order}"]
----
<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]] [[request-statistics]]
==== Request Statistics ==== Request Statistics
@ -90,22 +55,53 @@ To collect request statistics a `StatisticsHandler` must be configured as one of
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. 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. You can enable the `StatisticsHandler` by activating the `stats` modules on the command line.
[source, screen, subs="{sub-order}"]
....
$ 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. 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: The following fragment shows how to configure a top level statistics handler:
[source, xml, subs="{sub-order}"] [source, xml, subs="{sub-order}"]
---- ----
<Get id="oldhandler" name="handler" /> <Configure id="Server" class="org.eclipse.jetty.server.Server">
<Set name="handler"> <Call name="insertHandler">
<New id="StatsHandler" class="org.eclipse.jetty.server.handler.StatisticsHandler"> <Arg>
<Set name="handler"><Ref refid="oldhandler" /></Set> <New id="StatsHandler" class="org.eclipse.jetty.server.handler.StatisticsHandler"/>
</New> </Arg>
</Set> </Call>
</Configure>
----
[[connection-statistics]]
==== Connection Statistics
Detailed statistics on connection duration and number of messages 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 connection statistics in the Jetty XML format.
[source, xml, subs="{sub-order}"]
----
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<Call name="addBeanToAllConnectors">
<Arg>
<New class="org.eclipse.jetty.io.ConnectionStatistics"/>
</Arg>
</Call>
</Configure>
----
A special variant of `ConnectionStatistics` called `IncludeExcludeConnectionStatistics` allows you to refine which types of connection you want to collect statistics for.
The following example shows how this can be used to record statistics only for WebSocket connections.
[source, xml, subs="{sub-order}"]
----
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<Call name="addBeanToAllConnectors">
<Arg>
<New class="org.eclipse.jetty.io.IncludeExcludeConnectionStatistics">
<Call name="include" arg="org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection"/>
</New>
</Arg>
</Call>
</Configure>
---- ----
[[session-statistics]] [[session-statistics]]

View File

@ -92,10 +92,7 @@ public class DefaultSessionCache extends AbstractSessionCache
{ {
if (id == null) if (id == null)
return null; return null;
return _sessions.get(id);
Session session = _sessions.get(id);
return session;
} }
@Override @Override
@ -177,21 +174,18 @@ public class DefaultSessionCache extends AbstractSessionCache
@Override @Override
public Session newSession(HttpServletRequest request, SessionData data) public Session newSession(HttpServletRequest request, SessionData data)
{ {
Session s = new Session(getSessionHandler(), request, data); return new Session(getSessionHandler(), request, data);
return s;
} }
@Override @Override
public Session newSession(SessionData data) public Session newSession(SessionData data)
{ {
Session s = new Session(getSessionHandler(), data); return new Session(getSessionHandler(), data);
return s;
} }
@Override @Override
public boolean doReplace(String id, Session oldValue, Session newValue) public boolean doReplace(String id, Session oldValue, Session newValue)
{ {
boolean result = _sessions.replace(id, oldValue, newValue); return _sessions.replace(id, oldValue, newValue);
return result;
} }
} }