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

io.prometheus.client.hotspot.ClassLoadingExports Maven / Gradle / Ivy

package io.prometheus.client.hotspot;

import io.prometheus.client.Collector;
import io.prometheus.client.CounterMetricFamily;
import io.prometheus.client.GaugeMetricFamily;

import java.lang.management.ManagementFactory;
import java.lang.management.ClassLoadingMXBean;
import java.util.ArrayList;
import java.util.List;

/**
 * Exports metrics about JVM classloading.
 * 

* Example usage: *

 * {@code
 *   new ClassLoadingExports().register();
 * }
 * 
* Example metrics being exported: *
 *   jvm_classes_loaded{} 1000
 *   jvm_classes_loaded_total{} 2000
 *   jvm_classes_unloaded_total{} 500
 * 
*/ public class ClassLoadingExports extends Collector { private final ClassLoadingMXBean clBean; public ClassLoadingExports() { this(ManagementFactory.getClassLoadingMXBean()); } public ClassLoadingExports(ClassLoadingMXBean clBean) { this.clBean = clBean; } void addClassLoadingMetrics(List sampleFamilies) { sampleFamilies.add(new GaugeMetricFamily( "jvm_classes_loaded", "The number of classes that are currently loaded in the JVM", clBean.getLoadedClassCount())); sampleFamilies.add(new CounterMetricFamily( "jvm_classes_loaded_total", "The total number of classes that have been loaded since the JVM has started execution", clBean.getTotalLoadedClassCount())); sampleFamilies.add(new CounterMetricFamily( "jvm_classes_unloaded_total", "The total number of classes that have been unloaded since the JVM has started execution", clBean.getUnloadedClassCount())); } public List collect() { List mfs = new ArrayList(); addClassLoadingMetrics(mfs); return mfs; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy