Class GaugeWithCallback

All Implemented Interfaces:
Collector

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

      Description copied from interface: Collector
      Called when the Prometheus server scrapes metrics.
      Specified by:
      collect in interface Collector
      Specified by:
      collect in class Metric
    • getMetricType

      Description copied from interface: Collector
      Returns the metric type for registration-time validation.

      This is used to prevent different metric types (e.g., Counter and Gauge) from sharing the same name. Returning null means type validation is skipped for this collector.

      Validation is performed only at registration time. If this method returns null, no type validation is performed for this collector, and duplicate or conflicting metrics may result in invalid exposition output.

      Returns:
      the metric type, or null to skip validation
    • builder

    • builder