Skip to content

Commit

Permalink
Export Jetty stats to Prometheus (#2804)
Browse files Browse the repository at this point in the history
* Export Jetty stats to Prometheus

* Fixed exception in tests
  • Loading branch information
merlimat committed Oct 18, 2018
1 parent 1fe6395 commit 4d16522
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 13 deletions.
11 changes: 6 additions & 5 deletions distribution/server/src/assemble/LICENSE.bin.txt
Expand Up @@ -353,11 +353,12 @@ The Apache Software License, Version 2.0
- io.netty-netty-all-4.1.22.Final.jar
- io.netty-netty-tcnative-boringssl-static-2.0.7.Final.jar
* Prometheus client
- io.prometheus-simpleclient-0.0.23.jar
- io.prometheus-simpleclient_common-0.0.23.jar
- io.prometheus-simpleclient_hotspot-0.0.23.jar
- io.prometheus-simpleclient_servlet-0.0.23.jar
- io.prometheus-simpleclient_log4j2-0.0.23.jar
- io.prometheus-simpleclient-0.5.0.jar
- io.prometheus-simpleclient_common-0.5.0.jar
- io.prometheus-simpleclient_hotspot-0.5.0.jar
- io.prometheus-simpleclient_servlet-0.5.0.jar
- io.prometheus-simpleclient_log4j2-0.5.0.jar
- io.prometheus-simpleclient_jetty-0.5.0.jar
* Bean Validation API -- javax.validation-validation-api-1.1.0.Final.jar
* Log4J
- log4j-log4j-1.2.17.jar
Expand Down
8 changes: 7 additions & 1 deletion pom.xml
Expand Up @@ -147,7 +147,7 @@ flexible messaging model and an intuitive client API.</description>
<jetty.version>9.3.11.v20160721</jetty.version>
<jersey.version>2.25</jersey.version>
<athenz.version>1.7.17</athenz.version>
<prometheus.version>0.0.23</prometheus.version>
<prometheus.version>0.5.0</prometheus.version>
<aspectj.version>1.9.1</aspectj.version>
<rocksdb.version>5.13.3</rocksdb.version>
<slf4j.version>1.7.25</slf4j.version>
Expand Down Expand Up @@ -686,6 +686,12 @@ flexible messaging model and an intuitive client API.</description>
<version>${prometheus.version}</version>
</dependency>

<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_jetty</artifactId>
<version>${prometheus.version}</version>
</dependency>

<dependency>
<groupId>com.carrotsearch</groupId>
<artifactId>hppc</artifactId>
Expand Down
6 changes: 6 additions & 0 deletions pulsar-broker/pom.xml
Expand Up @@ -210,6 +210,12 @@
<artifactId>simpleclient</artifactId>
</dependency>

<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_jetty</artifactId>
</dependency>


<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_hotspot</artifactId>
Expand Down
Expand Up @@ -43,6 +43,7 @@
import org.eclipse.jetty.server.handler.HandlerCollection;
import org.eclipse.jetty.server.handler.RequestLogHandler;
import org.eclipse.jetty.server.handler.ResourceHandler;
import org.eclipse.jetty.server.handler.StatisticsHandler;
import org.eclipse.jetty.servlet.FilterHolder;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
Expand All @@ -59,6 +60,7 @@
import com.google.common.collect.Lists;

import io.netty.util.concurrent.DefaultThreadFactory;
import io.prometheus.client.jetty.JettyStatisticsCollector;

/**
* Web Service embedded into Pulsar
Expand Down Expand Up @@ -167,11 +169,21 @@ public void start() throws PulsarServerException {
handlers.add(0, new ContextHandlerCollection());
handlers.add(requestLogHandler);

// Metrics handler
StatisticsHandler stats = new StatisticsHandler();
stats.setHandler(server.getHandler());
try {
new JettyStatisticsCollector(stats).register();
} catch (IllegalArgumentException e) {
// Already registered. Eg: in unit tests
}
handlers.add(stats);

ContextHandlerCollection contexts = new ContextHandlerCollection();
contexts.setHandlers(handlers.toArray(new Handler[handlers.size()]));

HandlerCollection handlerCollection = new HandlerCollection();
handlerCollection.setHandlers(new Handler[] { contexts, new DefaultHandler(), requestLogHandler });
handlerCollection.setHandlers(new Handler[] { contexts, new DefaultHandler(), requestLogHandler, stats });
server.setHandler(handlerCollection);

server.start();
Expand Down
5 changes: 5 additions & 0 deletions pulsar-proxy/pom.xml
Expand Up @@ -109,6 +109,11 @@
<artifactId>simpleclient_servlet</artifactId>
</dependency>

<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_jetty</artifactId>
</dependency>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>pulsar-broker</artifactId>
Expand Down
Expand Up @@ -22,6 +22,7 @@
import com.google.common.collect.Lists;

import io.netty.util.concurrent.DefaultThreadFactory;
import io.prometheus.client.jetty.JettyStatisticsCollector;

import java.io.IOException;
import java.net.URI;
Expand Down Expand Up @@ -52,6 +53,7 @@
import org.eclipse.jetty.server.handler.DefaultHandler;
import org.eclipse.jetty.server.handler.HandlerCollection;
import org.eclipse.jetty.server.handler.RequestLogHandler;
import org.eclipse.jetty.server.handler.StatisticsHandler;
import org.eclipse.jetty.servlet.FilterHolder;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
Expand Down Expand Up @@ -174,8 +176,17 @@ public void start() throws Exception {
ContextHandlerCollection contexts = new ContextHandlerCollection();
contexts.setHandlers(handlers.toArray(new Handler[handlers.size()]));

// Metrics handler
StatisticsHandler stats = new StatisticsHandler();
stats.setHandler(server.getHandler());
try {
new JettyStatisticsCollector(stats).register();
} catch (IllegalArgumentException e) {
// Already registered. Eg: in unit tests
}

HandlerCollection handlerCollection = new HandlerCollection();
handlerCollection.setHandlers(new Handler[] { contexts, new DefaultHandler(), requestLogHandler });
handlerCollection.setHandlers(new Handler[] { contexts, new DefaultHandler(), requestLogHandler, stats });
server.setHandler(handlerCollection);

try {
Expand Down
9 changes: 4 additions & 5 deletions pulsar-sql/presto-distribution/LICENSE
Expand Up @@ -415,10 +415,10 @@ The Apache Software License, Version 2.0
- metrics-graphite-3.1.0.jar
- metrics-jvm-3.1.0.jar
* Prometheus
- simpleclient-0.0.23.jar
- simpleclient_common-0.0.23.jar
- simpleclient_hotspot-0.0.23.jar
- simpleclient_servlet-0.0.23.jar
- simpleclient-0.5.0.jar
- simpleclient_common-0.5.0.jar
- simpleclient_hotspot-0.5.0.jar
- simpleclient_servlet-0.5.0.jar
* LZ4
- lz4-java-1.5.0.jar
* Bookkeeper
Expand Down Expand Up @@ -530,4 +530,3 @@ Bouncy Castle License
* Bouncy Castle -- licenses/LICENSE-bouncycastle.txt
- bcpkix-jdk15on-1.55.jar
- bcprov-jdk15on-1.55.jar

0 comments on commit 4d16522

Please sign in to comment.