use of com.codahale.metrics.json.MetricsModule in project camel by apache.
the class MetricsMessageHistoryService method doStart.
@Override
protected void doStart() throws Exception {
if (metricsRegistry == null) {
Registry camelRegistry = getCamelContext().getRegistry();
metricsRegistry = camelRegistry.lookupByNameAndType(MetricsComponent.METRIC_REGISTRY_NAME, MetricRegistry.class);
// create a new metricsRegistry by default
if (metricsRegistry == null) {
metricsRegistry = new MetricRegistry();
}
}
if (useJmx) {
ManagementAgent agent = getCamelContext().getManagementStrategy().getManagementAgent();
if (agent != null) {
MBeanServer server = agent.getMBeanServer();
if (server != null) {
reporter = JmxReporter.forRegistry(metricsRegistry).registerWith(server).inDomain(jmxDomain).build();
reporter.start();
}
} else {
throw new IllegalStateException("CamelContext has not enabled JMX");
}
}
// json mapper
this.mapper = new ObjectMapper().registerModule(new MetricsModule(getRateUnit(), getDurationUnit(), false));
if (getRateUnit() == TimeUnit.SECONDS && getDurationUnit() == TimeUnit.SECONDS) {
// they both use same units so reuse
this.secondsMapper = this.mapper;
} else {
this.secondsMapper = new ObjectMapper().registerModule(new MetricsModule(TimeUnit.SECONDS, TimeUnit.SECONDS, false));
}
}
use of com.codahale.metrics.json.MetricsModule in project metrics by dropwizard.
the class MetricsServlet method init.
@Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
final ServletContext context = config.getServletContext();
if (null == registry) {
final Object registryAttr = context.getAttribute(METRICS_REGISTRY);
if (registryAttr instanceof MetricRegistry) {
this.registry = (MetricRegistry) registryAttr;
} else {
throw new ServletException("Couldn't find a MetricRegistry instance.");
}
}
final TimeUnit rateUnit = parseTimeUnit(context.getInitParameter(RATE_UNIT), TimeUnit.SECONDS);
final TimeUnit durationUnit = parseTimeUnit(context.getInitParameter(DURATION_UNIT), TimeUnit.SECONDS);
final boolean showSamples = Boolean.parseBoolean(context.getInitParameter(SHOW_SAMPLES));
MetricFilter filter = (MetricFilter) context.getAttribute(METRIC_FILTER);
if (filter == null) {
filter = MetricFilter.ALL;
}
this.mapper = new ObjectMapper().registerModule(new MetricsModule(rateUnit, durationUnit, showSamples, filter));
this.allowedOrigin = context.getInitParameter(ALLOWED_ORIGIN);
this.jsonpParamName = context.getInitParameter(CALLBACK_PARAM);
}
use of com.codahale.metrics.json.MetricsModule in project camel by apache.
the class MetricsRegistryService method doStart.
@Override
protected void doStart() throws Exception {
if (metricsRegistry == null) {
Registry camelRegistry = getCamelContext().getRegistry();
metricsRegistry = camelRegistry.lookupByNameAndType(MetricsComponent.METRIC_REGISTRY_NAME, MetricRegistry.class);
// create a new metricsRegistry by default
if (metricsRegistry == null) {
metricsRegistry = new MetricRegistry();
}
}
if (useJmx) {
ManagementAgent agent = getCamelContext().getManagementStrategy().getManagementAgent();
if (agent != null) {
MBeanServer server = agent.getMBeanServer();
if (server != null) {
reporter = JmxReporter.forRegistry(metricsRegistry).registerWith(server).inDomain(jmxDomain).build();
reporter.start();
}
} else {
throw new IllegalStateException("CamelContext has not enabled JMX");
}
}
// json mapper
this.mapper = new ObjectMapper().registerModule(new MetricsModule(getRateUnit(), getDurationUnit(), false));
if (getRateUnit() == TimeUnit.SECONDS && getDurationUnit() == TimeUnit.SECONDS) {
// they both use same units so reuse
this.secondsMapper = this.mapper;
} else {
this.secondsMapper = new ObjectMapper().registerModule(new MetricsModule(TimeUnit.SECONDS, TimeUnit.SECONDS, false));
}
}
Aggregations