com.codahale.metrics.jvm.ClassLoadingGaugeSet Maven / Gradle / Ivy
package com.codahale.metrics.jvm;
import com.codahale.metrics.Gauge;
import com.codahale.metrics.Metric;
import com.codahale.metrics.MetricSet;
import java.lang.management.ClassLoadingMXBean;
import java.lang.management.ManagementFactory;
import java.util.HashMap;
import java.util.Map;
/**
* A set of gauges for JVM classloader usage.
*/
public class ClassLoadingGaugeSet implements MetricSet {
private final ClassLoadingMXBean mxBean;
public ClassLoadingGaugeSet() {
this(ManagementFactory.getClassLoadingMXBean());
}
public ClassLoadingGaugeSet(ClassLoadingMXBean mxBean) {
this.mxBean = mxBean;
}
@Override
public Map getMetrics() {
final Map gauges = new HashMap();
gauges.put("loaded", new Gauge() {
@Override
public Long getValue() {
return mxBean.getTotalLoadedClassCount();
}
});
gauges.put("unloaded", new Gauge() {
@Override
public Long getValue() {
return mxBean.getUnloadedClassCount();
}
});
return gauges;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy