Search in sources :

Example 1 with InstrumentedAppender

use of com.codahale.metrics.logback.InstrumentedAppender in project chassis by Kixeye.

the class ChassisConfiguration method metricRegistry.

/**
     * Initializes the metrics registry
     *
     * @return metric registry bean
     */
@Bean
public MetricRegistry metricRegistry() {
    final MetricRegistry bean = new MetricRegistry();
    // add JVM metrics
    bean.register("jvm.gc", new GarbageCollectorMetricSet());
    bean.register("jvm.memory", new MemoryUsageGaugeSet());
    bean.register("jvm.thread-states", new ThreadStatesGaugeSet());
    bean.register("jvm.fd", new FileDescriptorRatioGauge());
    bean.register("jvm.load-average", new Gauge<Double>() {

        private OperatingSystemMXBean mxBean = ManagementFactory.getOperatingSystemMXBean();

        public Double getValue() {
            try {
                return mxBean.getSystemLoadAverage();
            } catch (Exception e) {
                // not supported
                return -1d;
            }
        }
    });
    // add Logback metrics
    final LoggerContext factory = (LoggerContext) LoggerFactory.getILoggerFactory();
    final Logger root = factory.getLogger(Logger.ROOT_LOGGER_NAME);
    final InstrumentedAppender appender = new InstrumentedAppender(bean);
    appender.setContext(root.getLoggerContext());
    appender.start();
    root.addAppender(appender);
    return bean;
}
Also used : InstrumentedAppender(com.codahale.metrics.logback.InstrumentedAppender) FileDescriptorRatioGauge(com.codahale.metrics.jvm.FileDescriptorRatioGauge) MemoryUsageGaugeSet(com.codahale.metrics.jvm.MemoryUsageGaugeSet) MetricRegistry(com.codahale.metrics.MetricRegistry) Logger(ch.qos.logback.classic.Logger) ThreadStatesGaugeSet(com.codahale.metrics.jvm.ThreadStatesGaugeSet) LoggerContext(ch.qos.logback.classic.LoggerContext) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean) GarbageCollectorMetricSet(com.codahale.metrics.jvm.GarbageCollectorMetricSet) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with InstrumentedAppender

use of com.codahale.metrics.logback.InstrumentedAppender in project dropwizard by dropwizard.

the class DefaultLoggingFactory method configureInstrumentation.

private void configureInstrumentation(Logger root, MetricRegistry metricRegistry) {
    final InstrumentedAppender appender = new InstrumentedAppender(metricRegistry);
    appender.setContext(loggerContext);
    appender.start();
    root.addAppender(appender);
}
Also used : InstrumentedAppender(com.codahale.metrics.logback.InstrumentedAppender)

Example 3 with InstrumentedAppender

use of com.codahale.metrics.logback.InstrumentedAppender in project ninja by ninjaframework.

the class MetricsServiceImpl method start.

@Start(order = 10)
@Override
public void start() {
    String applicationName = ninjaProps.getWithDefault(NinjaConstant.applicationName, "Ninja");
    /*
         * Register optional metrics
         */
    if (ninjaProps.getBooleanWithDefault("metrics.jvm.enabled", false)) {
        registerAll("jvm.gc", new GarbageCollectorMetricSet());
        registerAll("jvm.memory", new MemoryUsageGaugeSet());
        registerAll("jvm.threads", new ThreadStatesGaugeSet());
        registerAll("jvm.classes", new ClassLoadingGaugeSet());
        log.debug("Registered JVM-Metrics integration");
    }
    if (ninjaProps.getBooleanWithDefault("metrics.logback.enabled", false)) {
        final LoggerContext factory = (LoggerContext) LoggerFactory.getILoggerFactory();
        final ch.qos.logback.classic.Logger root = factory.getLogger(Logger.ROOT_LOGGER_NAME);
        final InstrumentedAppender appender = new InstrumentedAppender(metricRegistry);
        appender.setContext(root.getLoggerContext());
        appender.start();
        root.addAppender(appender);
        log.debug("Registered Logback-Metrics integration");
    }
    /*
         * MBeans for VisualVM, JConsole, or JMX
         */
    if (ninjaProps.getBooleanWithDefault("metrics.mbeans.enabled", true)) {
        JmxReporter reporter = JmxReporter.forRegistry(metricRegistry).inDomain(applicationName).build();
        reporter.start();
        reporters.add(reporter);
        log.debug("Started Ninja Metrics MBeans reporter");
    }
    log.info("Ninja Metrics is ready for collection.");
}
Also used : InstrumentedAppender(com.codahale.metrics.logback.InstrumentedAppender) MemoryUsageGaugeSet(com.codahale.metrics.jvm.MemoryUsageGaugeSet) ClassLoadingGaugeSet(com.codahale.metrics.jvm.ClassLoadingGaugeSet) ThreadStatesGaugeSet(com.codahale.metrics.jvm.ThreadStatesGaugeSet) LoggerContext(ch.qos.logback.classic.LoggerContext) JmxReporter(com.codahale.metrics.JmxReporter) GarbageCollectorMetricSet(com.codahale.metrics.jvm.GarbageCollectorMetricSet) Start(ninja.lifecycle.Start)

Aggregations

InstrumentedAppender (com.codahale.metrics.logback.InstrumentedAppender)3 LoggerContext (ch.qos.logback.classic.LoggerContext)2 GarbageCollectorMetricSet (com.codahale.metrics.jvm.GarbageCollectorMetricSet)2 MemoryUsageGaugeSet (com.codahale.metrics.jvm.MemoryUsageGaugeSet)2 ThreadStatesGaugeSet (com.codahale.metrics.jvm.ThreadStatesGaugeSet)2 Logger (ch.qos.logback.classic.Logger)1 JmxReporter (com.codahale.metrics.JmxReporter)1 MetricRegistry (com.codahale.metrics.MetricRegistry)1 ClassLoadingGaugeSet (com.codahale.metrics.jvm.ClassLoadingGaugeSet)1 FileDescriptorRatioGauge (com.codahale.metrics.jvm.FileDescriptorRatioGauge)1 OperatingSystemMXBean (java.lang.management.OperatingSystemMXBean)1 Start (ninja.lifecycle.Start)1 Bean (org.springframework.context.annotation.Bean)1