Ashwin
Ashwin

Reputation: 13537

Is it possible to query Jetty Server for stats?

I am looking to send statistics like the number of requests being handled by the jetty server, the number of requests waiting in queue etc. I would like to periodically send this as a count to my statsd agent to be able to plot it on Grafana. But I could not find any public apis on the Server class that expose such metrics.
I am guessing there are other people who are already doing it. I would like to know if there is a standard way to fetch these metrics programatically?

Upvotes: 4

Views: 1197

Answers (2)

Sergey Tselovalnikov
Sergey Tselovalnikov

Reputation: 6036

Jetty provides an API to collect and expose statistics - StatisticsHandler. The handler can expose metrics via JMX but it doesn't have a built-in integration with StatsD.

In order to integrate it with StatsD manually, you could use one of the java statsd clients, e.g. java-statsd-client. For instance, you could schedule a task to read the data from the StatisticsHandler and send it to the StatsD agent using the abovementioned library.

Upvotes: 1

Mark Bramnik
Mark Bramnik

Reputation: 42491

If you're using spring boot actuator it should already gather metrics from jetty's http connection thread pool + Micrometer used by spring boot for metering already provides an integration with StatsD. I believe it manually sets up the jetty's http connection pool so that it already exposes all the relevant metrics.

Otherwise you'll have to implement this feature "manually":

One possible implementation is using JMX to expose Connection thread pool statistics when you setup the jetty server.

The way to setup the JMX server can differ depending on how do use jetty. But in general I've found this SO thread that talks about the monitoring pool of jetty.

Then you could read these values from JMX MBean and integrate with stats.d agent. One possible way of such an integration might be jmxtrans. Disclaimer: I've never used it by myself so can't say nothing about it.

Upvotes: 0

Related Questions