Skip to content

Instantly share code, notes, and snippets.

@ivanursul
Created August 13, 2016 17:56
Show Gist options
  • Save ivanursul/e8301df33eebd9a2d3631db7f5cb0e8b to your computer and use it in GitHub Desktop.
Save ivanursul/e8301df33eebd9a2d3631db7f5cb0e8b to your computer and use it in GitHub Desktop.
package org.startup.queue.metrics;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.health.HealthCheckRegistry;
import com.codahale.metrics.servlets.HealthCheckServlet;
import com.codahale.metrics.servlets.MetricsServlet;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
public class MetricsServletContextListener implements ServletContextListener {
private MetricRegistry metricRegistry;
private HealthCheckRegistry healthCheckRegistry;
public MetricsServletContextListener(MetricRegistry metricRegistry, HealthCheckRegistry healthCheckRegistry) {
this.metricRegistry = metricRegistry;
this.healthCheckRegistry = healthCheckRegistry;
}
@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
servletContextEvent.getServletContext().setAttribute(HealthCheckServlet.HEALTH_CHECK_REGISTRY,healthCheckRegistry);
servletContextEvent.getServletContext().setAttribute(MetricsServlet.METRICS_REGISTRY, metricRegistry);
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment