Search code examples
jettymicrometer

What does JettyConnectionMetrics count?


The Micrometer library has a JettyConnectionMetrics class which produces these metrics (among others):

# HELP jetty_connections_bytes_in_bytes Bytes received by tracked connections
# TYPE jetty_connections_bytes_in_bytes summary
jetty_connections_bytes_in_bytes_count 125.0
jetty_connections_bytes_in_bytes_sum 186955.0
# HELP jetty_connections_bytes_in_bytes_max Bytes received by tracked connections
# TYPE jetty_connections_bytes_in_bytes_max gauge
jetty_connections_bytes_in_bytes_max 1681.0

What does this actually count? What does tracked mean here?

If I add it to our (only one) connector will it contain every bytes received by the TCP connection?

I am right that it is updated only on connection close which could delay data when there is a HAProxy between real clients and Jetty (with keep-alive connections)?


Solution

  • What does this actually count?

    According to the code of this class, it measure the following points:

    • Messages received by tracked connections
    • Messages sent by tracked connections
    • Bytes received by tracked connections
    • Bytes sent by tracked connections
    • The maximum number of observed connections over a rolling 2-minute interval
    • The current number of open Jetty connections

    What does tracked mean here?

    Because JettyConnectionMetrics is Jetty's Connection.Listener, when registered into a Connector, it'll track all open and close events, i.e. whenever an I/O event occurs on that connector.

    If I add it to our (only one) connector will it contain every bytes received by the TCP connection?

    Yes, if you are using ServerConnector, that is the primary connector for the Jetty server over TCP/IP.

    I am right that it is updated only on connection close which could delay data when there is a HAProxy between real clients and Jetty (with keep-alive connections)?

    Yes, you're right, that is updated only when a connection closes. Depending how is this important for your metrics, you may consider disabling keep-alive connections and require always that connections get closed (make sure you understand the trade-offs of this change).