mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
don't start a new reporter every time the registry is injected
This commit is contained in:
@@ -1,21 +1,30 @@
|
||||
package com.commafeed.backend.metrics;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.enterprise.context.ApplicationScoped;
|
||||
import javax.enterprise.inject.Produces;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import com.codahale.metrics.JmxReporter;
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
|
||||
@ApplicationScoped
|
||||
@Slf4j
|
||||
public class MetricRegistryProducer {
|
||||
|
||||
private final MetricRegistry registry = new MetricRegistry();
|
||||
private MetricRegistry registry;
|
||||
|
||||
@PostConstruct
|
||||
private void init() {
|
||||
log.info("initializing metrics registry");
|
||||
registry = new MetricRegistry();
|
||||
JmxReporter.forRegistry(registry).build().start();
|
||||
log.info("metrics registry initialized");
|
||||
}
|
||||
|
||||
@Produces
|
||||
public MetricRegistry produceMetricsRegistry() {
|
||||
final JmxReporter reporter = JmxReporter.forRegistry(registry).build();
|
||||
reporter.start();
|
||||
return registry;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user