From a5c1b721bc5491f052c0c8e872b12ffc509fc8bc Mon Sep 17 00:00:00 2001 From: Tommy Ludwig <8924140+shakuzen@users.noreply.github.com> Date: Tue, 14 May 2024 00:07:28 +0900 Subject: [PATCH] Update documentation for Jetty connection metrics The configuration necessary for getting all the Jetty connection metrics changed with gh-4514. This updates the corresponding documentation to include this. Closes gh-4981 --- docs/modules/ROOT/pages/reference/jetty.adoc | 30 ++++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/docs/modules/ROOT/pages/reference/jetty.adoc b/docs/modules/ROOT/pages/reference/jetty.adoc index bc624c22d4..c8b4d7b9a6 100644 --- a/docs/modules/ROOT/pages/reference/jetty.adoc +++ b/docs/modules/ROOT/pages/reference/jetty.adoc @@ -1,17 +1,41 @@ [[overview]] = Eclipse Jetty and Jersey Instrumentation +== Jetty + Micrometer supports binding metrics to Jetty through `Connection.Listener`. -You can collect metrics from Jetty by adding `JettyConnectionMetrics`, as follows: +You can collect metrics from a Jetty `Connector` by configuring it with `JettyConnectionMetrics`, as follows: [source,java] ---- Server server = new Server(0); - Connector connector = new ServerConnector(server); - connector.addBean(new JettyConnectionMetrics(registry, connector, Tags.of("foo", "bar")); + NetworkTrafficServerConnector connector = new NetworkTrafficServerConnector(server); + JettyConnectionMetrics metrics = new JettyConnectionMetrics(registry, connector); + connector.addBean(metrics); //<1> + connector.setNetworkTrafficListener(metrics); //<2> server.setConnectors(new Connector[] { connector }); ---- +<1> Register general connection metrics +<2> Registers metrics for bytes in/out on this connector + +Alternatively, you can apply the metrics instrumentation to all connectors on a `Server` as follows: + +[source,java] +---- +JettyConnectionMetrics.addToAllConnectors(server, registry); +---- + +Connection metrics can be configured on a client as well, but bytes in/out will not be available when instrumenting a client. + +.Configure instrumentation for a Jetty client +[source,java] +---- +HttpClient httpClient = new HttpClient(); +httpClient.addBean(new JettyConnectionMetrics(registry)); +---- + +== Jersey Micrometer also supports binding metrics to Jersey through `ApplicationEventListener`.