Created
June 23, 2017 21:17
-
-
Save mwiede/3fae2b064b9814d6d408dc60a6e6ed2a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io.prometheus.client.CollectorRegistry; | |
import io.prometheus.client.dropwizard.DropwizardExports; | |
import io.prometheus.client.hotspot.ClassLoadingExports; | |
import io.prometheus.client.hotspot.GarbageCollectorExports; | |
import io.prometheus.client.hotspot.MemoryPoolsExports; | |
import io.prometheus.client.hotspot.ThreadExports; | |
import io.prometheus.client.hotspot.VersionInfoExports; | |
import javax.enterprise.context.ApplicationScoped; | |
import javax.enterprise.context.Destroyed; | |
import javax.enterprise.context.Initialized; | |
import javax.enterprise.event.Observes; | |
import javax.inject.Inject; | |
import com.codahale.metrics.MetricRegistry; | |
/** | |
* A bean, which is starting the metrics reporter during startup and its is shutting down the | |
* reporter when application is destroyed. | |
* | |
* | |
*/ | |
@ApplicationScoped | |
public class MetricsBean { | |
@Inject | |
private MetricRegistry registry; | |
public void init(@Observes @Initialized(ApplicationScoped.class) final Object init) { | |
// DefaultExports.initialize(); | |
new MemoryPoolsExports().register(); | |
new GarbageCollectorExports().register(); | |
new ThreadExports().register(); | |
new ClassLoadingExports().register(); | |
new VersionInfoExports().register(); | |
CollectorRegistry.defaultRegistry.register(new DropwizardExports(registry)); | |
} | |
public void destroy(@Observes @Destroyed(ApplicationScoped.class) final Object init) { | |
CollectorRegistry.defaultRegistry.clear(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment