All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.mapfish.print.metrics.JvmMetricsConfigurator Maven / Gradle / Ivy

There is a newer version: 3.22.0
Show newest version
package org.mapfish.print.metrics;

import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.jvm.FileDescriptorRatioGauge;
import com.codahale.metrics.jvm.GarbageCollectorMetricSet;
import com.codahale.metrics.jvm.MemoryUsageGaugeSet;
import com.codahale.metrics.jvm.ThreadStatesGaugeSet;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.PostConstruct;

/**
 * A bean that will add several gauges and metric sets for tracking the JVM stats.
 */
public final class JvmMetricsConfigurator {

    @Autowired
    private MetricRegistry metricRegistry;

    /**
     * Add several jvm metrics.
     */
    @PostConstruct
    public void init() {
        this.metricRegistry.register(name("gc"), new GarbageCollectorMetricSet());
        this.metricRegistry.register(name("memory"), new MemoryUsageGaugeSet());
        this.metricRegistry.register(name("thread-states"), new ThreadStatesGaugeSet());
        this.metricRegistry.register(name("fd-usage"), new FileDescriptorRatioGauge());
    }

    private String name(final String metricName) {
        return "jvm-" + metricName;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy