Skip to content

Commit

Permalink
Use simple HTTP Server (prometheus#162)
Browse files Browse the repository at this point in the history
  • Loading branch information
leogomes authored and brian-brazil committed Jul 17, 2017
1 parent e5192ce commit 5b180af
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 63 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@

# compilation objects
target/
/.project
.project
.settings/
.classpath
dependency-reduced-pom.xml
2 changes: 1 addition & 1 deletion collector/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient</artifactId>
<version>0.0.21</version>
<version>0.0.25</version>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand Down
10 changes: 2 additions & 8 deletions jmx_prometheus_httpserver/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<version>0.10-SNAPSHOT</version>
</parent>

<groupId>io.prometheus.jmx</groupId>
<artifactId>jmx_prometheus_httpserver</artifactId>
<description>
See https://github.com/prometheus/jmx_exporter/blob/master/README.md
Expand All @@ -22,13 +21,8 @@
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_servlet</artifactId>
<version>0.0.21</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>8.1.7.v20120910</version>
<artifactId>simpleclient_httpserver</artifactId>
<version>0.0.25</version>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package io.prometheus.jmx;

import io.prometheus.client.exporter.MetricsServlet;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;

import java.io.File;
import java.net.InetSocketAddress;

import io.prometheus.client.CollectorRegistry;
import io.prometheus.client.exporter.HTTPServer;

public class WebServer {

public static void main(String[] args) throws Exception {
Expand All @@ -19,7 +17,7 @@ public static void main(String[] args) throws Exception {
String[] hostnamePort = args[0].split(":");
int port;
InetSocketAddress socket;

if (hostnamePort.length == 2) {
port = Integer.parseInt(hostnamePort[1]);
socket = new InetSocketAddress(hostnamePort[0], port);
Expand All @@ -28,14 +26,7 @@ public static void main(String[] args) throws Exception {
socket = new InetSocketAddress(port);
}

JmxCollector jc = new JmxCollector(new File(args[1])).register();

Server server = new Server(socket);
ServletContextHandler context = new ServletContextHandler();
context.setContextPath("/");
server.setHandler(context);
context.addServlet(new ServletHolder(new MetricsServlet()), "/metrics");
server.start();
server.join();
new JmxCollector(new File(args[1])).register();
new HTTPServer(socket, CollectorRegistry.defaultRegistry);
}
}
15 changes: 5 additions & 10 deletions jmx_prometheus_javaagent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,12 @@
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_hotspot</artifactId>
<version>0.0.21</version>
<version>0.0.25</version>
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_servlet</artifactId>
<version>0.0.21</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>8.1.7.v20120910</version>
<artifactId>simpleclient_httpserver</artifactId>
<version>0.0.25</version>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand All @@ -52,8 +47,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package io.prometheus.jmx;

import io.prometheus.client.exporter.MetricsServlet;
import io.prometheus.client.hotspot.DefaultExports;
import java.lang.instrument.Instrumentation;
import java.io.File;
import java.lang.instrument.Instrumentation;
import java.net.InetSocketAddress;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.nio.SelectChannelConnector;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.util.thread.QueuedThreadPool;

import io.prometheus.client.CollectorRegistry;
import io.prometheus.client.exporter.HTTPServer;
import io.prometheus.client.hotspot.DefaultExports;

public class JavaAgent {
static Server server;

static HTTPServer server;

public static void premain(String agentArgument, Instrumentation instrumentation) throws Exception {
String[] args = agentArgument.split(":");
Expand All @@ -22,8 +20,8 @@ public static void premain(String agentArgument, Instrumentation instrumentation
}

int port;
InetSocketAddress socket;
String file;
InetSocketAddress socket;

if (args.length == 3) {
port = Integer.parseInt(args[1]);
Expand All @@ -37,23 +35,6 @@ public static void premain(String agentArgument, Instrumentation instrumentation

new JmxCollector(new File(file)).register();
DefaultExports.initialize();

server = new Server();
QueuedThreadPool pool = new QueuedThreadPool();
pool.setDaemon(true);
pool.setMaxThreads(10);
pool.setMaxQueued(10);
pool.setName("jmx_exporter");
server.setThreadPool(pool);
SelectChannelConnector connector = new SelectChannelConnector();
connector.setHost(socket.getHostName());
connector.setPort(socket.getPort());
connector.setAcceptors(1);
server.addConnector(connector);
ServletContextHandler context = new ServletContextHandler();
context.setContextPath("/");
server.setHandler(context);
context.addServlet(new ServletHolder(new MetricsServlet()), "/metrics");
server.start();
server = new HTTPServer(socket, CollectorRegistry.defaultRegistry);
}
}

0 comments on commit 5b180af

Please sign in to comment.