Search in sources :

Example 1 with ThreadStatesGaugeSet

use of com.codahale.metrics.jvm.ThreadStatesGaugeSet in project dropwizard by dropwizard.

the class Bootstrap method registerMetrics.

/**
     * Registers the JVM metrics to the metric registry and start to report
     * the registry metrics via JMX.
     */
public void registerMetrics() {
    if (metricsAreRegistered) {
        return;
    }
    getMetricRegistry().register("jvm.attribute", new JvmAttributeGaugeSet());
    getMetricRegistry().register("jvm.buffers", new BufferPoolMetricSet(ManagementFactory.getPlatformMBeanServer()));
    getMetricRegistry().register("jvm.classloader", new ClassLoadingGaugeSet());
    getMetricRegistry().register("jvm.filedescriptor", new FileDescriptorRatioGauge());
    getMetricRegistry().register("jvm.gc", new GarbageCollectorMetricSet());
    getMetricRegistry().register("jvm.memory", new MemoryUsageGaugeSet());
    getMetricRegistry().register("jvm.threads", new ThreadStatesGaugeSet());
    JmxReporter.forRegistry(metricRegistry).build().start();
    metricsAreRegistered = true;
}
Also used : BufferPoolMetricSet(com.codahale.metrics.jvm.BufferPoolMetricSet) JvmAttributeGaugeSet(com.codahale.metrics.JvmAttributeGaugeSet) FileDescriptorRatioGauge(com.codahale.metrics.jvm.FileDescriptorRatioGauge) MemoryUsageGaugeSet(com.codahale.metrics.jvm.MemoryUsageGaugeSet) ClassLoadingGaugeSet(com.codahale.metrics.jvm.ClassLoadingGaugeSet) ThreadStatesGaugeSet(com.codahale.metrics.jvm.ThreadStatesGaugeSet) GarbageCollectorMetricSet(com.codahale.metrics.jvm.GarbageCollectorMetricSet)

Example 2 with ThreadStatesGaugeSet

use of com.codahale.metrics.jvm.ThreadStatesGaugeSet 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 3 with ThreadStatesGaugeSet

use of com.codahale.metrics.jvm.ThreadStatesGaugeSet in project cas by apereo.

the class CasMetricsConfiguration method metrics.

/**
     * Metric registry metric registry.
     *
     * @return the metric registry
     */
@RefreshScope
@Bean
public MetricRegistry metrics() {
    final MetricRegistry metrics = new MetricRegistry();
    metrics.register("jvm.gc", new GarbageCollectorMetricSet());
    metrics.register("jvm.memory", new MemoryUsageGaugeSet());
    metrics.register("thread-states", new ThreadStatesGaugeSet());
    metrics.register("jvm.fd.usage", new FileDescriptorRatioGauge());
    return metrics;
}
Also used : FileDescriptorRatioGauge(com.codahale.metrics.jvm.FileDescriptorRatioGauge) MemoryUsageGaugeSet(com.codahale.metrics.jvm.MemoryUsageGaugeSet) MetricRegistry(com.codahale.metrics.MetricRegistry) ThreadStatesGaugeSet(com.codahale.metrics.jvm.ThreadStatesGaugeSet) GarbageCollectorMetricSet(com.codahale.metrics.jvm.GarbageCollectorMetricSet) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) Bean(org.springframework.context.annotation.Bean)

Example 4 with ThreadStatesGaugeSet

use of com.codahale.metrics.jvm.ThreadStatesGaugeSet 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)

Example 5 with ThreadStatesGaugeSet

use of com.codahale.metrics.jvm.ThreadStatesGaugeSet in project pinpoint by naver.

the class CollectorMetric method initRegistry.

private void initRegistry() {
    // add JVM statistics
    metricRegistry.register("jvm.memory", new MemoryUsageGaugeSet());
    metricRegistry.register("jvm.vm", new JvmAttributeGaugeSet());
    metricRegistry.register("jvm.garbage-collectors", new GarbageCollectorMetricSet());
    metricRegistry.register("jvm.thread-states", new ThreadStatesGaugeSet());
    if (hBaseAsyncOperationMetrics != null) {
        Map<String, Metric> metrics = hBaseAsyncOperationMetrics.getMetrics();
        for (Map.Entry<String, Metric> metric : metrics.entrySet()) {
            metricRegistry.register(metric.getKey(), metric.getValue());
        }
    }
}
Also used : JvmAttributeGaugeSet(com.codahale.metrics.JvmAttributeGaugeSet) MemoryUsageGaugeSet(com.codahale.metrics.jvm.MemoryUsageGaugeSet) Metric(com.codahale.metrics.Metric) ThreadStatesGaugeSet(com.codahale.metrics.jvm.ThreadStatesGaugeSet) Map(java.util.Map) GarbageCollectorMetricSet(com.codahale.metrics.jvm.GarbageCollectorMetricSet)

Aggregations

GarbageCollectorMetricSet (com.codahale.metrics.jvm.GarbageCollectorMetricSet)8 MemoryUsageGaugeSet (com.codahale.metrics.jvm.MemoryUsageGaugeSet)8 ThreadStatesGaugeSet (com.codahale.metrics.jvm.ThreadStatesGaugeSet)8 FileDescriptorRatioGauge (com.codahale.metrics.jvm.FileDescriptorRatioGauge)4 MetricRegistry (com.codahale.metrics.MetricRegistry)3 ClassLoadingGaugeSet (com.codahale.metrics.jvm.ClassLoadingGaugeSet)3 Bean (org.springframework.context.annotation.Bean)3 LoggerContext (ch.qos.logback.classic.LoggerContext)2 JvmAttributeGaugeSet (com.codahale.metrics.JvmAttributeGaugeSet)2 BufferPoolMetricSet (com.codahale.metrics.jvm.BufferPoolMetricSet)2 InstrumentedAppender (com.codahale.metrics.logback.InstrumentedAppender)2 Logger (ch.qos.logback.classic.Logger)1 JmxReporter (com.codahale.metrics.JmxReporter)1 Metric (com.codahale.metrics.Metric)1 IOException (java.io.IOException)1 OperatingSystemMXBean (java.lang.management.OperatingSystemMXBean)1 Map (java.util.Map)1 ServletException (javax.servlet.ServletException)1 UnavailableException (javax.servlet.UnavailableException)1 Start (ninja.lifecycle.Start)1