Search in sources :

Example 1 with AdminServlet

use of com.codahale.metrics.servlets.AdminServlet in project metrics by dropwizard.

the class ExampleServer method main.

public static void main(String[] args) throws Exception {
    COUNTER_1.inc();
    COUNTER_2.inc();
    final ThreadPool threadPool = new InstrumentedQueuedThreadPool(REGISTRY);
    final Server server = new Server(threadPool);
    final Connector connector = new ServerConnector(server, new InstrumentedConnectionFactory(new HttpConnectionFactory(), REGISTRY.timer("http.connection")));
    server.addConnector(connector);
    final ServletContextHandler context = new ServletContextHandler();
    context.setContextPath("/initial");
    context.setAttribute(MetricsServlet.METRICS_REGISTRY, REGISTRY);
    context.setAttribute(HealthCheckServlet.HEALTH_CHECK_REGISTRY, new HealthCheckRegistry());
    final ServletHolder holder = new ServletHolder(new AdminServlet());
    context.addServlet(holder, "/dingo/*");
    final InstrumentedHandler handler = new InstrumentedHandler(REGISTRY);
    handler.setHandler(context);
    server.setHandler(handler);
    server.start();
    server.join();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) InstrumentedHandler(com.codahale.metrics.jetty9.InstrumentedHandler) ServerConnector(org.eclipse.jetty.server.ServerConnector) Connector(org.eclipse.jetty.server.Connector) InstrumentedQueuedThreadPool(com.codahale.metrics.jetty9.InstrumentedQueuedThreadPool) AdminServlet(com.codahale.metrics.servlets.AdminServlet) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) HealthCheckRegistry(com.codahale.metrics.health.HealthCheckRegistry) ThreadPool(org.eclipse.jetty.util.thread.ThreadPool) InstrumentedQueuedThreadPool(com.codahale.metrics.jetty9.InstrumentedQueuedThreadPool) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) InstrumentedConnectionFactory(com.codahale.metrics.jetty9.InstrumentedConnectionFactory)

Example 2 with AdminServlet

use of com.codahale.metrics.servlets.AdminServlet in project dropwizard by dropwizard.

the class AbstractServerFactory method createAdminServlet.

protected Handler createAdminServlet(Server server, MutableServletContextHandler handler, MetricRegistry metrics, HealthCheckRegistry healthChecks) {
    configureSessionsAndSecurity(handler, server);
    handler.setServer(server);
    handler.getServletContext().setAttribute(MetricsServlet.METRICS_REGISTRY, metrics);
    handler.getServletContext().setAttribute(HealthCheckServlet.HEALTH_CHECK_REGISTRY, healthChecks);
    handler.addServlet(new NonblockingServletHolder(new AdminServlet()), "/*");
    handler.addFilter(AllowedMethodsFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST)).setInitParameter(AllowedMethodsFilter.ALLOWED_METHODS_PARAM, Joiner.on(',').join(allowedMethods));
    return handler;
}
Also used : NonblockingServletHolder(io.dropwizard.jetty.NonblockingServletHolder) AdminServlet(com.codahale.metrics.servlets.AdminServlet) AllowedMethodsFilter(io.dropwizard.jersey.filter.AllowedMethodsFilter)

Example 3 with AdminServlet

use of com.codahale.metrics.servlets.AdminServlet in project distributedlog by twitter.

the class ServletReporter method start.

public void start() throws Exception {
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath("/");
    jettyServer.setHandler(context);
    context.addEventListener(new HealthCheckServletContextListener(healthCheckRegistry));
    context.addEventListener(new MetricsServletContextListener(metricRegistry));
    context.addServlet(new ServletHolder(new AdminServlet()), "/*");
    jettyServer.start();
}
Also used : AdminServlet(com.codahale.metrics.servlets.AdminServlet) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 4 with AdminServlet

use of com.codahale.metrics.servlets.AdminServlet in project chassis by Kixeye.

the class AdminTransportConfiguration method adminServer.

@Bean(initMethod = "start", destroyMethod = "stop")
@Order(0)
public Server adminServer(@Value("${admin.hostname}") String hostname, @Value("${admin.port}") int port) {
    // set up servlets
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS | ServletContextHandler.NO_SECURITY);
    context.setErrorHandler(null);
    context.setWelcomeFiles(new String[] { "/" });
    // enable gzip
    context.addFilter(GzipFilter.class, "/*", null);
    // add common admin servlets
    context.addServlet(new ServletHolder(new HealthServlet(healthCheckRegistry)), "/healthcheck");
    context.addServlet(new ServletHolder(new ClasspathResourceServlet("com/kixeye/chassis/transport/admin", "/admin/", "index.html")), "/admin/*");
    context.addServlet(new ServletHolder(new PropertiesServlet()), "/admin/properties");
    context.addServlet(new ServletHolder(new ClasspathDumpServlet()), "/admin/classpath");
    // add websocket servlets if WebSockets have been initialized
    if (mappingRegistry != null && messageRegistry != null) {
        context.addServlet(new ServletHolder(new ProtobufMessagesDocumentationServlet(appName, mappingRegistry, messageRegistry)), "/schema/messages/protobuf");
        context.addServlet(new ServletHolder(new ProtobufEnvelopeDocumentationServlet()), "/schema/envelope/protobuf");
    }
    // add metric servlets if Metric has been initialized
    if (metricRegistry != null && healthCheckRegistry != null) {
        context.getServletContext().setAttribute(MetricsServlet.METRICS_REGISTRY, metricRegistry);
        context.getServletContext().setAttribute(HealthCheckServlet.HEALTH_CHECK_REGISTRY, healthCheckRegistry);
        ServletHolder holder = new ServletHolder(new AdminServlet());
        holder.setInitParameter("service-name", System.getProperty("app.name"));
        context.addServlet(holder, "/metrics/*");
    }
    // create the server
    InetSocketAddress address = StringUtils.isBlank(hostname) ? new InetSocketAddress(port) : new InetSocketAddress(hostname, port);
    Server server = new Server();
    JettyConnectorRegistry.registerHttpConnector(server, address);
    server.setHandler(context);
    return server;
}
Also used : AdminServlet(com.codahale.metrics.servlets.AdminServlet) PropertiesServlet(com.kixeye.chassis.transport.shared.PropertiesServlet) Server(org.eclipse.jetty.server.Server) HealthServlet(com.kixeye.chassis.transport.shared.HealthServlet) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ProtobufMessagesDocumentationServlet(com.kixeye.chassis.transport.websocket.docs.ProtobufMessagesDocumentationServlet) InetSocketAddress(java.net.InetSocketAddress) ClasspathDumpServlet(com.kixeye.chassis.transport.shared.ClasspathDumpServlet) ProtobufEnvelopeDocumentationServlet(com.kixeye.chassis.transport.websocket.docs.ProtobufEnvelopeDocumentationServlet) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) ClasspathResourceServlet(com.kixeye.chassis.transport.shared.ClasspathResourceServlet) Order(org.springframework.core.annotation.Order) Bean(org.springframework.context.annotation.Bean)

Aggregations

AdminServlet (com.codahale.metrics.servlets.AdminServlet)4 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)3 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)3 Server (org.eclipse.jetty.server.Server)2 HealthCheckRegistry (com.codahale.metrics.health.HealthCheckRegistry)1 InstrumentedConnectionFactory (com.codahale.metrics.jetty9.InstrumentedConnectionFactory)1 InstrumentedHandler (com.codahale.metrics.jetty9.InstrumentedHandler)1 InstrumentedQueuedThreadPool (com.codahale.metrics.jetty9.InstrumentedQueuedThreadPool)1 ClasspathDumpServlet (com.kixeye.chassis.transport.shared.ClasspathDumpServlet)1 ClasspathResourceServlet (com.kixeye.chassis.transport.shared.ClasspathResourceServlet)1 HealthServlet (com.kixeye.chassis.transport.shared.HealthServlet)1 PropertiesServlet (com.kixeye.chassis.transport.shared.PropertiesServlet)1 ProtobufEnvelopeDocumentationServlet (com.kixeye.chassis.transport.websocket.docs.ProtobufEnvelopeDocumentationServlet)1 ProtobufMessagesDocumentationServlet (com.kixeye.chassis.transport.websocket.docs.ProtobufMessagesDocumentationServlet)1 AllowedMethodsFilter (io.dropwizard.jersey.filter.AllowedMethodsFilter)1 NonblockingServletHolder (io.dropwizard.jetty.NonblockingServletHolder)1 InetSocketAddress (java.net.InetSocketAddress)1 Connector (org.eclipse.jetty.server.Connector)1 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)1 ServerConnector (org.eclipse.jetty.server.ServerConnector)1