com.codahale.metrics.servlets.AdminServlet Java Examples

The following examples show how to use com.codahale.metrics.servlets.AdminServlet. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Poseidon.java    From Poseidon with Apache License 2.0 6 votes vote down vote up
private ServletContextHandler getMetricsHandler() {
    MetricRegistry registry = Metrics.getRegistry();
    HealthCheckRegistry healthCheckRegistry = Metrics.getHealthCheckRegistry();
    healthCheckRegistry.register("rotation", new Rotation(configuration.getRotationStatusFilePath()));

    registry.registerAll(new GarbageCollectorMetricSet());
    registry.registerAll(new MemoryUsageGaugeSet());
    registry.registerAll(new ThreadStatesGaugeSet());
    registry.registerAll(new JvmAttributeGaugeSet());

    ServletContextHandler servletContextHandler = new ServletContextHandler();
    servletContextHandler.setContextPath("/__metrics");
    servletContextHandler.setAttribute(MetricsServlet.class.getCanonicalName() + ".registry", registry);
    servletContextHandler.setAttribute(HealthCheckServlet.class.getCanonicalName() + ".registry", healthCheckRegistry);
    servletContextHandler.addServlet(new ServletHolder(new AdminServlet()), "/*");

    return servletContextHandler;
}
 
Example #2
Source File: ServletReporter.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example #3
Source File: ServletReporter.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example #4
Source File: AdminTransportConfiguration.java    From chassis with Apache License 2.0 4 votes vote down vote up
@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;
}
 
Example #5
Source File: MetricsServletProvider.java    From hammock with Apache License 2.0 4 votes vote down vote up
@Produces
public ServletDescriptor metricsServlet() {
    String[] uris = new String[]{metricsConfig.getBaseUri()};
    WebInitParam[] params = null;
    return new ServletDescriptor("Metrics", uris, uris, 1, params, false, AdminServlet.class);
}
 
Example #6
Source File: Main.java    From billow with Apache License 2.0 4 votes vote down vote up
private Main(Config config) throws Exception {
    log.info("Startup...");

    try {
        System.out.println(Resources.toString(getResource("banner.txt"), Charsets.UTF_8));
    } catch (IllegalArgumentException | IOException e) {
        log.debug("No banner.txt", e);
    }

    final MetricRegistry metricRegistry = new MetricRegistry();
    final HealthCheckRegistry healthCheckRegistry = new HealthCheckRegistry();

    log.info("Creating database");

    final Config awsConfig = config.getConfig("aws");
    final Long refreshRate = awsConfig.getDuration("refreshRate", TimeUnit.MILLISECONDS);

    final AWSDatabaseHolder dbHolder = new AWSDatabaseHolder(awsConfig);

    final Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
    scheduler.getContext().put(AWSDatabaseHolderRefreshJob.DB_KEY, dbHolder);
    scheduler.start();

    final SimpleTrigger trigger = newTrigger().
            withIdentity(AWSDatabaseHolderRefreshJob.NAME).
            startNow().
            withSchedule(simpleSchedule().withIntervalInMilliseconds(refreshRate).repeatForever()).
            build();

    final JobDetail jobDetail = newJob(AWSDatabaseHolderRefreshJob.class).
            withIdentity(AWSDatabaseHolderRefreshJob.NAME).
            build();

    scheduler.scheduleJob(jobDetail, trigger);

    log.info("Creating age health check");
    healthCheckRegistry.register("DB", new HealthCheck() {
        @Override
        protected Result check() throws Exception {
            return dbHolder.healthy();
        }
    });

    log.info("Creating HTTP servers");
    final Server mainServer = new Server(config.getInt("mainPort"));
    final Server adminServer = new Server(config.getInt("adminPort"));

    configureConnectors(mainServer);
    configureConnectors(adminServer);

    log.info("Creating HTTP handlers");
    final Handler mainHandler = new Handler(metricRegistry, dbHolder, refreshRate);
    final InstrumentedHandler instrumentedHandler =
            new InstrumentedHandler(metricRegistry);
    instrumentedHandler.setHandler(mainHandler);

    mainServer.setHandler(instrumentedHandler);

    final ServletContextHandler adminHandler = new ServletContextHandler();
    adminHandler.addServlet(new ServletHolder(new AdminServlet()), "/*");

    final ServletContext adminContext = adminHandler.getServletContext();
    adminContext.setAttribute(MetricsServlet.METRICS_REGISTRY, metricRegistry);
    adminContext.setAttribute(HealthCheckServlet.HEALTH_CHECK_REGISTRY, healthCheckRegistry);
    adminServer.setHandler(adminHandler);

    log.info("Starting HTTP servers");

    adminServer.start();
    mainServer.start();

    log.info("Joining...");

    mainServer.join();
    adminServer.join();

    log.info("Shutting down scheduler...");

    scheduler.shutdown();

    log.info("We're done!");
}
 
Example #7
Source File: SentryWebServer.java    From incubator-sentry with Apache License 2.0 4 votes vote down vote up
public SentryWebServer(List<EventListener> listeners, int port, Configuration conf) {
  this.port = port;
  server = new Server(port);
  ServletContextHandler servletContextHandler = new ServletContextHandler();
  ServletHolder servletHolder = new ServletHolder(AdminServlet.class);
  servletContextHandler.addServlet(servletHolder, "/*");

  for(EventListener listener:listeners) {
    servletContextHandler.addEventListener(listener);
  }

  ServletHolder confServletHolder = new ServletHolder(ConfServlet.class);
  servletContextHandler.addServlet(confServletHolder, "/conf");
  servletContextHandler.getServletContext()
      .setAttribute(ConfServlet.CONF_CONTEXT_ATTRIBUTE, conf);

  ResourceHandler resourceHandler = new ResourceHandler();
  resourceHandler.setDirectoriesListed(true);
  URL url = this.getClass().getResource(RESOURCE_DIR);
  try {
    resourceHandler.setBaseResource(Resource.newResource(url.toString()));
  } catch (IOException e) {
    LOGGER.error("Got exception while setBaseResource for Sentry Service web UI", e);
  }
  resourceHandler.setWelcomeFiles(new String[]{WELCOME_PAGE});
  ContextHandler contextHandler= new ContextHandler();
  contextHandler.setHandler(resourceHandler);

  ContextHandlerCollection contextHandlerCollection = new ContextHandlerCollection();
  contextHandlerCollection.setHandlers(new Handler[]{contextHandler, servletContextHandler});

  String authMethod = conf.get(ServerConfig.SENTRY_WEB_SECURITY_TYPE);
  if (!ServerConfig.SENTRY_WEB_SECURITY_TYPE_NONE.equals(authMethod)) {
    /**
     * SentryAuthFilter is a subclass of AuthenticationFilter and
     * AuthenticationFilter tagged as private and unstable interface:
     * While there are not guarantees that this interface will not change,
     * it is fairly stable and used by other projects (ie - Oozie)
     */
    FilterHolder filterHolder = servletContextHandler.addFilter(SentryAuthFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
    filterHolder.setInitParameters(loadWebAuthenticationConf(conf));
  }

  server.setHandler(contextHandlerCollection);
}