Merge "Add Jetty connection metrics" into stable-2.16
This commit is contained in:
@@ -58,6 +58,15 @@ objects needing finalization.
|
||||
|
||||
==== Jetty
|
||||
|
||||
* `http/server/jetty/connections/connections`: The current number of open connections
|
||||
* `http/server/jetty/connections/connections_total`: The total number of connections opened
|
||||
* `http/server/jetty/connections/connections_duration_max`: The max duration of a connection in ms
|
||||
* `http/server/jetty/connections/connections_duration_mean`: The mean duration of a connection in ms
|
||||
* `http/server/jetty/connections/connections_duration_stdev`: The standard deviation of the duration of a connection in ms
|
||||
* `http/server/jetty/connections/received_messages`: The total number of messages received
|
||||
* `http/server/jetty/connections/sent_messages`: The total number of messages sent
|
||||
* `http/server/jetty/connections/received_bytes`: Total number of bytes received by tracked connections
|
||||
* `http/server/jetty/connections/sent_bytes`: Total number of bytes sent by tracked connections"
|
||||
* `http/server/jetty/threadpool/active_threads`: Active threads
|
||||
* `http/server/jetty/threadpool/idle_threads`: Idle threads
|
||||
* `http/server/jetty/threadpool/reserved_threads`: Reserved threads
|
||||
|
||||
@@ -17,6 +17,7 @@ import com.google.common.collect.ImmutableSet;
|
||||
import com.google.gerrit.metrics.CallbackMetric;
|
||||
import com.google.gerrit.metrics.CallbackMetric0;
|
||||
import com.google.gerrit.metrics.Description;
|
||||
import com.google.gerrit.metrics.Description.Units;
|
||||
import com.google.gerrit.metrics.MetricMaker;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
@@ -45,27 +46,83 @@ public class JettyMetrics {
|
||||
metrics.newCallbackMetric(
|
||||
"http/server/jetty/threadpool/idle_threads",
|
||||
Integer.class,
|
||||
new Description("Idle threads").setGauge().setUnit("threads"));
|
||||
new Description("Idle threads").setGauge());
|
||||
CallbackMetric0<Integer> busyThreads =
|
||||
metrics.newCallbackMetric(
|
||||
"http/server/jetty/threadpool/active_threads",
|
||||
Integer.class,
|
||||
new Description("Active threads").setGauge().setUnit("threads"));
|
||||
new Description("Active threads").setGauge());
|
||||
CallbackMetric0<Integer> reservedThreads =
|
||||
metrics.newCallbackMetric(
|
||||
"http/server/jetty/threadpool/reserved_threads",
|
||||
Integer.class,
|
||||
new Description("Reserved threads").setGauge().setUnit("threads"));
|
||||
new Description("Reserved threads").setGauge());
|
||||
CallbackMetric0<Integer> queueSize =
|
||||
metrics.newCallbackMetric(
|
||||
"http/server/jetty/threadpool/queue_size",
|
||||
Integer.class,
|
||||
new Description("Queued requests waiting for a thread").setGauge().setUnit("requests"));
|
||||
new Description("Queued requests waiting for a thread").setGauge());
|
||||
CallbackMetric0<Boolean> lowOnThreads =
|
||||
metrics.newCallbackMetric(
|
||||
"http/server/jetty/threadpool/is_low_on_threads",
|
||||
Boolean.class,
|
||||
new Description("Whether thread pool is low on threads").setGauge());
|
||||
CallbackMetric0<Long> connections =
|
||||
metrics.newCallbackMetric(
|
||||
"http/server/jetty/connections/connections",
|
||||
Long.class,
|
||||
new Description("The current number of open connections").setGauge());
|
||||
CallbackMetric0<Long> connectionsTotal =
|
||||
metrics.newCallbackMetric(
|
||||
"http/server/jetty/connections/connections_total",
|
||||
Long.class,
|
||||
new Description("The total number of connections opened").setGauge());
|
||||
CallbackMetric0<Long> connectionDurationMax =
|
||||
metrics.newCallbackMetric(
|
||||
"http/server/jetty/connections/connections_duration_max",
|
||||
Long.class,
|
||||
new Description("The max duration of a connection")
|
||||
.setGauge()
|
||||
.setUnit(Units.MILLISECONDS));
|
||||
CallbackMetric0<Double> connectionDurationMean =
|
||||
metrics.newCallbackMetric(
|
||||
"http/server/jetty/connections/connections_duration_mean",
|
||||
Double.class,
|
||||
new Description("The mean duration of a connection")
|
||||
.setGauge()
|
||||
.setUnit(Units.MILLISECONDS));
|
||||
CallbackMetric0<Double> connectionDurationStDev =
|
||||
metrics.newCallbackMetric(
|
||||
"http/server/jetty/connections/connections_duration_stdev",
|
||||
Double.class,
|
||||
new Description("The standard deviation of the duration of a connection")
|
||||
.setGauge()
|
||||
.setUnit(Units.MILLISECONDS));
|
||||
CallbackMetric0<Long> receivedMessages =
|
||||
metrics.newCallbackMetric(
|
||||
"http/server/jetty/connections/received_messages",
|
||||
Long.class,
|
||||
new Description("The total number of messages received").setGauge());
|
||||
CallbackMetric0<Long> sentMessages =
|
||||
metrics.newCallbackMetric(
|
||||
"http/server/jetty/connections/sent_messages",
|
||||
Long.class,
|
||||
new Description("The total number of messages sent").setGauge());
|
||||
CallbackMetric0<Long> receivedBytes =
|
||||
metrics.newCallbackMetric(
|
||||
"http/server/jetty/connections/received_bytes",
|
||||
Long.class,
|
||||
new Description("Total number of bytes received by tracked connections")
|
||||
.setGauge()
|
||||
.setUnit(Units.BYTES));
|
||||
CallbackMetric0<Long> sentBytes =
|
||||
metrics.newCallbackMetric(
|
||||
"http/server/jetty/connections/sent_bytes",
|
||||
Long.class,
|
||||
new Description("Total number of bytes sent by tracked connections")
|
||||
.setGauge()
|
||||
.setUnit(Units.BYTES));
|
||||
|
||||
JettyServer.Metrics jettyMetrics = jetty.getMetrics();
|
||||
metrics.newTrigger(
|
||||
ImmutableSet.<CallbackMetric<?>>of(
|
||||
@@ -76,7 +133,16 @@ public class JettyMetrics {
|
||||
maxPoolSize,
|
||||
poolSize,
|
||||
queueSize,
|
||||
lowOnThreads),
|
||||
lowOnThreads,
|
||||
connections,
|
||||
connectionsTotal,
|
||||
connectionDurationMax,
|
||||
connectionDurationMean,
|
||||
connectionDurationStDev,
|
||||
receivedMessages,
|
||||
sentMessages,
|
||||
receivedBytes,
|
||||
sentBytes),
|
||||
() -> {
|
||||
minPoolSize.set(jettyMetrics.getMinThreads());
|
||||
maxPoolSize.set(jettyMetrics.getMaxThreads());
|
||||
@@ -86,6 +152,15 @@ public class JettyMetrics {
|
||||
reservedThreads.set(jettyMetrics.getReservedThreads());
|
||||
queueSize.set(jettyMetrics.getQueueSize());
|
||||
lowOnThreads.set(jettyMetrics.isLowOnThreads());
|
||||
connections.set(jettyMetrics.getConnections());
|
||||
connectionsTotal.set(jettyMetrics.getConnectionsTotal());
|
||||
connectionDurationMax.set(jettyMetrics.getConnectionDurationMax());
|
||||
connectionDurationMean.set(jettyMetrics.getConnectionDurationMean());
|
||||
connectionDurationStDev.set(jettyMetrics.getConnectionDurationStdDev());
|
||||
receivedMessages.set(jettyMetrics.getReceivedMessages());
|
||||
sentMessages.set(jettyMetrics.getSentMessages());
|
||||
receivedBytes.set(jettyMetrics.getReceivedBytes());
|
||||
sentBytes.set(jettyMetrics.getSentBytes());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ import java.util.concurrent.TimeUnit;
|
||||
import javax.servlet.DispatcherType;
|
||||
import javax.servlet.Filter;
|
||||
import org.eclipse.jetty.http.HttpScheme;
|
||||
import org.eclipse.jetty.io.ConnectionStatistics;
|
||||
import org.eclipse.jetty.jmx.MBeanContainer;
|
||||
import org.eclipse.jetty.server.Connector;
|
||||
import org.eclipse.jetty.server.ForwardedRequestCustomizer;
|
||||
@@ -117,9 +118,11 @@ public class JettyServer {
|
||||
|
||||
static class Metrics {
|
||||
private final QueuedThreadPool threadPool;
|
||||
private ConnectionStatistics connStats;
|
||||
|
||||
Metrics(QueuedThreadPool threadPool) {
|
||||
Metrics(QueuedThreadPool threadPool, ConnectionStatistics connStats) {
|
||||
this.threadPool = threadPool;
|
||||
this.connStats = connStats;
|
||||
}
|
||||
|
||||
public int getIdleThreads() {
|
||||
@@ -153,12 +156,49 @@ public class JettyServer {
|
||||
public boolean isLowOnThreads() {
|
||||
return threadPool.isLowOnThreads();
|
||||
}
|
||||
|
||||
public long getConnections() {
|
||||
return connStats.getConnections();
|
||||
}
|
||||
|
||||
public long getConnectionsTotal() {
|
||||
return connStats.getConnectionsTotal();
|
||||
}
|
||||
|
||||
public long getConnectionDurationMax() {
|
||||
return connStats.getConnectionDurationMax();
|
||||
}
|
||||
|
||||
public double getConnectionDurationMean() {
|
||||
return connStats.getConnectionDurationMean();
|
||||
}
|
||||
|
||||
public double getConnectionDurationStdDev() {
|
||||
return connStats.getConnectionDurationStdDev();
|
||||
}
|
||||
|
||||
public long getReceivedMessages() {
|
||||
return connStats.getReceivedMessages();
|
||||
}
|
||||
|
||||
public long getSentMessages() {
|
||||
return connStats.getSentMessages();
|
||||
}
|
||||
|
||||
public long getReceivedBytes() {
|
||||
return connStats.getReceivedBytes();
|
||||
}
|
||||
|
||||
public long getSentBytes() {
|
||||
return connStats.getSentBytes();
|
||||
}
|
||||
}
|
||||
|
||||
private final SitePaths site;
|
||||
private final Server httpd;
|
||||
private final Metrics metrics;
|
||||
private boolean reverseProxy;
|
||||
private ConnectionStatistics connStats;
|
||||
|
||||
@Inject
|
||||
JettyServer(
|
||||
@@ -172,7 +212,11 @@ public class JettyServer {
|
||||
QueuedThreadPool pool = threadPool(cfg, threadSettingsConfig);
|
||||
httpd = new Server(pool);
|
||||
httpd.setConnectors(listen(httpd, cfg));
|
||||
metrics = new Metrics(pool);
|
||||
connStats = new ConnectionStatistics();
|
||||
for (Connector connector : httpd.getConnectors()) {
|
||||
connector.addBean(connStats);
|
||||
}
|
||||
metrics = new Metrics(pool, connStats);
|
||||
|
||||
Handler app = makeContext(env, cfg);
|
||||
if (cfg.getBoolean("httpd", "requestLog", !reverseProxy)) {
|
||||
|
||||
Reference in New Issue
Block a user