Class ThreadExports


  • public class ThreadExports
    extends Collector
    Exports metrics about JVM thread areas.

    Example usage:

     
       new ThreadExports().register();
     
     
    Example metrics being exported:
       jvm_threads_current{} 300
       jvm_threads_daemon{} 200
       jvm_threads_peak{} 410
       jvm_threads_started_total{} 1200
     
    • Field Detail

      • JVM_THREADS_STATE

        public static final java.lang.String JVM_THREADS_STATE
        See Also:
        Constant Field Values
      • JVM_THREADS_CURRENT

        private static final java.lang.String JVM_THREADS_CURRENT
        See Also:
        Constant Field Values
      • JVM_THREADS_DAEMON

        private static final java.lang.String JVM_THREADS_DAEMON
        See Also:
        Constant Field Values
      • JVM_THREADS_PEAK

        private static final java.lang.String JVM_THREADS_PEAK
        See Also:
        Constant Field Values
      • JVM_THREADS_STARTED_TOTAL

        private static final java.lang.String JVM_THREADS_STARTED_TOTAL
        See Also:
        Constant Field Values
      • JVM_THREADS_DEADLOCKED

        private static final java.lang.String JVM_THREADS_DEADLOCKED
        See Also:
        Constant Field Values
      • JVM_THREADS_DEADLOCKED_MONITOR

        private static final java.lang.String JVM_THREADS_DEADLOCKED_MONITOR
        See Also:
        Constant Field Values
      • threadBean

        private final java.lang.management.ThreadMXBean threadBean
    • Constructor Detail

      • ThreadExports

        public ThreadExports()
      • ThreadExports

        public ThreadExports​(java.lang.management.ThreadMXBean threadBean)
    • Method Detail

      • getThreadStateCountMap

        private java.util.Map<java.lang.String,​java.lang.Integer> getThreadStateCountMap()
      • nullSafeArrayLength

        private static double nullSafeArrayLength​(long[] array)
      • collect

        public java.util.List<Collector.MetricFamilySamples> collect​(Predicate<java.lang.String> nameFilter)
        Description copied from class: Collector
        Like Collector.collect(), but the result should only contain MetricFamilySamples where sampleNameFilter.test(name) is true for at least one Sample name.

        The default implementation first collects all MetricFamilySamples and then discards the ones where sampleNameFilter.test(name) returns false for all names in Collector.MetricFamilySamples.getNames(). To improve performance, collector implementations should override this method to prevent MetricFamilySamples from being collected if they will be discarded anyways. See ThreadExports for an example.

        Note that the resulting List may contain MetricFamilySamples where some Sample names return true for sampleNameFilter.test(name) but some Sample names return false. This is ok, because before we produce the output format we will call Collector.MetricFamilySamples.filter(Predicate) to strip all Samples where sampleNameFilter.test(name) returns false.

        Overrides:
        collect in class Collector
        Parameters:
        nameFilter - may be null, indicating that all metrics should be collected.