forked from Archives/Athou_commafeed
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;
|
package com.commafeed.backend.metrics;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
import javax.enterprise.context.ApplicationScoped;
|
import javax.enterprise.context.ApplicationScoped;
|
||||||
import javax.enterprise.inject.Produces;
|
import javax.enterprise.inject.Produces;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import com.codahale.metrics.JmxReporter;
|
import com.codahale.metrics.JmxReporter;
|
||||||
import com.codahale.metrics.MetricRegistry;
|
import com.codahale.metrics.MetricRegistry;
|
||||||
|
|
||||||
@ApplicationScoped
|
@ApplicationScoped
|
||||||
|
@Slf4j
|
||||||
public class MetricRegistryProducer {
|
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
|
@Produces
|
||||||
public MetricRegistry produceMetricsRegistry() {
|
public MetricRegistry produceMetricsRegistry() {
|
||||||
final JmxReporter reporter = JmxReporter.forRegistry(registry).build();
|
|
||||||
reporter.start();
|
|
||||||
return registry;
|
return registry;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user