Search in sources :

Example 1 with MetricsModule

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));
    }
}
Also used : ManagementAgent(org.apache.camel.spi.ManagementAgent) MetricRegistry(com.codahale.metrics.MetricRegistry) MetricsModule(com.codahale.metrics.json.MetricsModule) MetricRegistry(com.codahale.metrics.MetricRegistry) Registry(org.apache.camel.spi.Registry) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MBeanServer(javax.management.MBeanServer)

Example 2 with MetricsModule

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);
}
Also used : ServletException(javax.servlet.ServletException) MetricFilter(com.codahale.metrics.MetricFilter) MetricRegistry(com.codahale.metrics.MetricRegistry) MetricsModule(com.codahale.metrics.json.MetricsModule) ServletContext(javax.servlet.ServletContext) TimeUnit(java.util.concurrent.TimeUnit) JSONPObject(com.fasterxml.jackson.databind.util.JSONPObject) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 3 with MetricsModule

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));
    }
}
Also used : ManagementAgent(org.apache.camel.spi.ManagementAgent) MetricRegistry(com.codahale.metrics.MetricRegistry) MetricsModule(com.codahale.metrics.json.MetricsModule) MetricRegistry(com.codahale.metrics.MetricRegistry) Registry(org.apache.camel.spi.Registry) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MBeanServer(javax.management.MBeanServer)

Aggregations

MetricRegistry (com.codahale.metrics.MetricRegistry)3 MetricsModule (com.codahale.metrics.json.MetricsModule)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 MBeanServer (javax.management.MBeanServer)2 ManagementAgent (org.apache.camel.spi.ManagementAgent)2 Registry (org.apache.camel.spi.Registry)2 MetricFilter (com.codahale.metrics.MetricFilter)1 JSONPObject (com.fasterxml.jackson.databind.util.JSONPObject)1 TimeUnit (java.util.concurrent.TimeUnit)1 ServletContext (javax.servlet.ServletContext)1 ServletException (javax.servlet.ServletException)1