Class GaugeWithCallback

All Implemented Interfaces:
io.prometheus.metrics.model.registry.Collector

public class GaugeWithCallback extends MetricWithFixedMetadata
Example:

 MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean();

 GaugeWithCallback.builder()
     .name("jvm_memory_bytes_used")
     .help("Used bytes of a given JVM memory area.")
     .unit(Unit.BYTES)
     .labelNames("area")
     .callback(callback -> {
         callback.call(memoryBean.getHeapMemoryUsage().getUsed(), "heap");
         callback.call(memoryBean.getNonHeapMemoryUsage().getUsed(), "nonheap");
     })
     .register();
 
  • Method Details

    • collect

      public io.prometheus.metrics.model.snapshots.GaugeSnapshot collect()
      Specified by:
      collect in interface io.prometheus.metrics.model.registry.Collector
      Specified by:
      collect in class Metric
    • builder

      public static GaugeWithCallback.Builder builder()
    • builder

      public static GaugeWithCallback.Builder builder(io.prometheus.metrics.config.PrometheusProperties properties)
    • makeLabels

      protected io.prometheus.metrics.model.snapshots.Labels makeLabels(String... labelValues)