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

com.alibaba.metrics.jvm.ClassLoadingGaugeSet Maven / Gradle / Ivy

There is a newer version: 2.0.1
Show newest version
package com.alibaba.metrics.jvm;

import com.alibaba.metrics.Metric;
import com.alibaba.metrics.MetricName;
import com.alibaba.metrics.MetricSet;
import com.alibaba.metrics.PersistentGauge;

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(MetricName.build("loaded"), new PersistentGauge() {
            @Override
            public Long getValue() {
                return mxBean.getTotalLoadedClassCount();
            }
        });

        gauges.put(MetricName.build("loaded_current"), new PersistentGauge() {
            @Override
            public Integer getValue() {
                return mxBean.getLoadedClassCount();
            }
        });

        gauges.put(MetricName.build("unloaded"), new PersistentGauge() {
            @Override
            public Long getValue() {
                return mxBean.getUnloadedClassCount();
            }
        });

        return gauges;
    }

    @Override
    public long lastUpdateTime() {
        return System.currentTimeMillis();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy