Skip to content

Commit

Permalink
Jetty 12: Cleanup StatisticsHandler (#9291)
Browse files Browse the repository at this point in the history
#9145 cleanup statistics

Signed-off-by: Ludovic Orban <[email protected]>
  • Loading branch information
lorban authored Feb 7, 2023
1 parent d02932f commit b87f938
Show file tree
Hide file tree
Showing 15 changed files with 145 additions and 2,949 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ The following fragment shows how to configure a top level statistics handler:
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<Call name="insertHandler">
<Arg>
<New id="StatsHandler" class="org.eclipse.jetty.server.handler.StatisticsHandler"/>
<New id="StatisticsHandler" class="org.eclipse.jetty.server.handler.StatisticsHandler"/>
</Arg>
</Call>
</Configure>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ Server applications can read these values and use them internally, or expose the

[source,java,indent=0]
----
include::../../{doc_code}/org/eclipse/jetty/docs/programming/server/http/HTTPServerDocs.java[tags=statsHandler]
include::../../{doc_code}/org/eclipse/jetty/docs/programming/server/http/HTTPServerDocs.java[tags=statisticsHandler]
----

The `Handler` tree structure looks like the following:
Expand All @@ -258,6 +258,14 @@ Server
└── ContextHandler N
----

It is possible to act on those statistics by subclassing `StatisticsHandler`.
For instance, `StatisticsHandler.MinimumDataRateHandler` can be used to enforce a minimum read rate and a minimum write rate based of the figures collected by the `StatisticsHandler`:

[source,java,indent=0]
----
include::../../{doc_code}/org/eclipse/jetty/docs/programming/server/http/HTTPServerDocs.java[tags=dataRateHandler]
----

[[pg-server-http-handler-use-util-secure-handler]]
====== SecuredRedirectHandler -- Redirect from HTTP to HTTPS

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -927,9 +927,9 @@ public void rewriteHandler() throws Exception
// end::rewriteHandler[]
}

public void statsHandler() throws Exception
public void statisticsHandler() throws Exception
{
// tag::statsHandler[]
// tag::statisticsHandler[]
Server server = new Server();
ServerConnector connector = new ServerConnector(server);
server.addConnector(connector);
Expand All @@ -945,7 +945,29 @@ public void statsHandler() throws Exception
statsHandler.setHandler(contextCollection);

server.start();
// end::statsHandler[]
// end::statisticsHandler[]
}

public void dataRateHandler() throws Exception
{
// tag::dataRateHandler[]
Server server = new Server();
ServerConnector connector = new ServerConnector(server);
server.addConnector(connector);

// Create the MinimumDataRateHandler with a minimum read rate of 1KB per second and no minimum write rate.
StatisticsHandler.MinimumDataRateHandler dataRateHandler = new StatisticsHandler.MinimumDataRateHandler(1024L, 0L);

// Link the MinimumDataRateHandler to the Server.
server.setHandler(dataRateHandler);

// Create a ContextHandlerCollection to hold contexts.
ContextHandlerCollection contextCollection = new ContextHandlerCollection();
// Link the ContextHandlerCollection to the MinimumDataRateHandler.
dataRateHandler.setHandler(contextCollection);

server.start();
// end::dataRateHandler[]
}

public void securedHandler() throws Exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
<!-- =============================================================== -->

<Configure id="Server" class="org.eclipse.jetty.server.Server">
<!-- Collects request stats -->
<Call name="insertHandler">
<Arg>
<New id="StatsHandler" class="org.eclipse.jetty.server.handler.StatisticsHandler">
<Set name="gracefulShutdownWaitsForRequests"><Property name="jetty.statistics.gracefulShutdownWaitsForRequests" default="true"/></Set>
</New>
<New id="StatisticsHandler" class="org.eclipse.jetty.server.handler.StatisticsHandler"/>
</Arg>
</Call>
<!-- Collects connection stats -->
<Call name="addBeanToAllConnectors">
<Arg>
<New class="org.eclipse.jetty.io.ConnectionStatistics"/>
Expand Down
13 changes: 13 additions & 0 deletions jetty-core/jetty-server/src/main/config/modules/statistics.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html

[description]
Enables statistics collection for the server.

[tags]
server

[depend]
server

[xml]
etc/jetty-statistics.xml
25 changes: 0 additions & 25 deletions jetty-core/jetty-server/src/main/config/modules/stats.mod

This file was deleted.

Loading

0 comments on commit b87f938

Please sign in to comment.