Search in sources :

Example 1 with ClassLoadingGaugeSet

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

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

use of com.codahale.metrics.jvm.ClassLoadingGaugeSet in project lucene-solr by apache.

the class SolrDispatchFilter method setupJvmMetrics.

private void setupJvmMetrics(CoreContainer coresInit) {
    SolrMetricManager metricManager = coresInit.getMetricManager();
    final Set<String> hiddenSysProps = coresInit.getConfig().getMetricsConfig().getHiddenSysProps();
    try {
        String registry = SolrMetricManager.getRegistryName(SolrInfoBean.Group.jvm);
        metricManager.registerAll(registry, new AltBufferPoolMetricSet(), true, "buffers");
        metricManager.registerAll(registry, new ClassLoadingGaugeSet(), true, "classes");
        metricManager.registerAll(registry, new OperatingSystemMetricSet(), true, "os");
        metricManager.registerAll(registry, new GarbageCollectorMetricSet(), true, "gc");
        metricManager.registerAll(registry, new MemoryUsageGaugeSet(), true, "memory");
        // todo should we use CachedThreadStatesGaugeSet instead?
        metricManager.registerAll(registry, new ThreadStatesGaugeSet(), true, "threads");
        MetricsMap sysprops = new MetricsMap((detailed, map) -> {
            System.getProperties().forEach((k, v) -> {
                if (!hiddenSysProps.contains(k)) {
                    map.put(String.valueOf(k), v);
                }
            });
        });
        metricManager.registerGauge(null, registry, sysprops, true, "properties", "system");
    } catch (Exception e) {
        log.warn("Error registering JVM metrics", e);
    }
}
Also used : MetricsMap(org.apache.solr.metrics.MetricsMap) MemoryUsageGaugeSet(com.codahale.metrics.jvm.MemoryUsageGaugeSet) OperatingSystemMetricSet(org.apache.solr.metrics.OperatingSystemMetricSet) SolrMetricManager(org.apache.solr.metrics.SolrMetricManager) AltBufferPoolMetricSet(org.apache.solr.metrics.AltBufferPoolMetricSet) ClassLoadingGaugeSet(com.codahale.metrics.jvm.ClassLoadingGaugeSet) ThreadStatesGaugeSet(com.codahale.metrics.jvm.ThreadStatesGaugeSet) ServletException(javax.servlet.ServletException) SolrException(org.apache.solr.common.SolrException) IOException(java.io.IOException) UnavailableException(javax.servlet.UnavailableException) GarbageCollectorMetricSet(com.codahale.metrics.jvm.GarbageCollectorMetricSet)

Aggregations

ClassLoadingGaugeSet (com.codahale.metrics.jvm.ClassLoadingGaugeSet)3 GarbageCollectorMetricSet (com.codahale.metrics.jvm.GarbageCollectorMetricSet)3 MemoryUsageGaugeSet (com.codahale.metrics.jvm.MemoryUsageGaugeSet)3 ThreadStatesGaugeSet (com.codahale.metrics.jvm.ThreadStatesGaugeSet)3 LoggerContext (ch.qos.logback.classic.LoggerContext)1 JmxReporter (com.codahale.metrics.JmxReporter)1 JvmAttributeGaugeSet (com.codahale.metrics.JvmAttributeGaugeSet)1 BufferPoolMetricSet (com.codahale.metrics.jvm.BufferPoolMetricSet)1 FileDescriptorRatioGauge (com.codahale.metrics.jvm.FileDescriptorRatioGauge)1 InstrumentedAppender (com.codahale.metrics.logback.InstrumentedAppender)1 IOException (java.io.IOException)1 ServletException (javax.servlet.ServletException)1 UnavailableException (javax.servlet.UnavailableException)1 Start (ninja.lifecycle.Start)1 SolrException (org.apache.solr.common.SolrException)1 AltBufferPoolMetricSet (org.apache.solr.metrics.AltBufferPoolMetricSet)1 MetricsMap (org.apache.solr.metrics.MetricsMap)1 OperatingSystemMetricSet (org.apache.solr.metrics.OperatingSystemMetricSet)1 SolrMetricManager (org.apache.solr.metrics.SolrMetricManager)1