Search in sources :

Example 1 with InstrumentedHandler

use of io.dropwizard.metrics.jetty11.InstrumentedHandler 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(io.dropwizard.metrics.jetty11.InstrumentedHandler) ServerConnector(org.eclipse.jetty.server.ServerConnector) Connector(org.eclipse.jetty.server.Connector) InstrumentedQueuedThreadPool(io.dropwizard.metrics.jetty11.InstrumentedQueuedThreadPool) AdminServlet(io.dropwizard.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) InstrumentedQueuedThreadPool(io.dropwizard.metrics.jetty11.InstrumentedQueuedThreadPool) ThreadPool(org.eclipse.jetty.util.thread.ThreadPool) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) InstrumentedConnectionFactory(io.dropwizard.metrics.jetty11.InstrumentedConnectionFactory)

Example 2 with InstrumentedHandler

use of io.dropwizard.metrics.jetty11.InstrumentedHandler 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 3 with InstrumentedHandler

use of io.dropwizard.metrics.jetty11.InstrumentedHandler in project dropwizard by dropwizard.

the class AbstractServerFactory method createAppServlet.

protected Handler createAppServlet(Server server, JerseyEnvironment jersey, ObjectMapper objectMapper, Validator validator, MutableServletContextHandler handler, @Nullable Servlet jerseyContainer, MetricRegistry metricRegistry) {
    configureSessionsAndSecurity(handler, server);
    final String allowedMethodsParam = String.join(",", allowedMethods);
    handler.addFilter(AllowedMethodsFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST)).setInitParameter(AllowedMethodsFilter.ALLOWED_METHODS_PARAM, allowedMethodsParam);
    if (enableThreadNameFilter) {
        handler.addFilter(ThreadNameFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
    }
    serverPush.addFilter(handler);
    if (jerseyContainer != null) {
        jerseyRootPath.ifPresent(jersey::setUrlPattern);
        jersey.register(new JacksonFeature(objectMapper));
        jersey.register(new HibernateValidationBinder(validator));
        if (registerDefaultExceptionMappers == null || registerDefaultExceptionMappers) {
            jersey.register(new ExceptionMapperBinder(detailedJsonProcessingExceptionMapper));
        }
        handler.addServlet(new ServletHolder("jersey", jerseyContainer), jersey.getUrlPattern());
    }
    final InstrumentedHandler instrumented = new InstrumentedHandler(metricRegistry);
    instrumented.setServer(server);
    instrumented.setHandler(handler);
    return instrumented;
}
Also used : InstrumentedHandler(com.codahale.metrics.jetty9.InstrumentedHandler) JacksonFeature(io.dropwizard.jersey.jackson.JacksonFeature) ExceptionMapperBinder(io.dropwizard.setup.ExceptionMapperBinder) HibernateValidationBinder(io.dropwizard.jersey.validation.HibernateValidationBinder) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) AllowedMethodsFilter(io.dropwizard.jersey.filter.AllowedMethodsFilter)

Aggregations

ServletHolder (org.eclipse.jetty.servlet.ServletHolder)3 HealthCheckRegistry (com.codahale.metrics.health.HealthCheckRegistry)2 InstrumentedHandler (com.codahale.metrics.jetty9.InstrumentedHandler)2 Connector (org.eclipse.jetty.server.Connector)2 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)2 Server (org.eclipse.jetty.server.Server)2 ServerConnector (org.eclipse.jetty.server.ServerConnector)2 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)2 ThreadPool (org.eclipse.jetty.util.thread.ThreadPool)2 InstrumentedConnectionFactory (com.codahale.metrics.jetty9.InstrumentedConnectionFactory)1 InstrumentedQueuedThreadPool (com.codahale.metrics.jetty9.InstrumentedQueuedThreadPool)1 AdminServlet (com.codahale.metrics.servlets.AdminServlet)1 AllowedMethodsFilter (io.dropwizard.jersey.filter.AllowedMethodsFilter)1 JacksonFeature (io.dropwizard.jersey.jackson.JacksonFeature)1 HibernateValidationBinder (io.dropwizard.jersey.validation.HibernateValidationBinder)1 InstrumentedConnectionFactory (io.dropwizard.metrics.jetty11.InstrumentedConnectionFactory)1 InstrumentedHandler (io.dropwizard.metrics.jetty11.InstrumentedHandler)1 InstrumentedQueuedThreadPool (io.dropwizard.metrics.jetty11.InstrumentedQueuedThreadPool)1 AdminServlet (io.dropwizard.metrics.servlets.AdminServlet)1 ExceptionMapperBinder (io.dropwizard.setup.ExceptionMapperBinder)1