Class MicrometerRegistrator

java.lang.Object
com.gigaspaces.metrics.MetricRegistrator
com.gigaspaces.metrics.micrometer.MicrometerRegistrator
All Implemented Interfaces:
BeanMetricManager

public class MicrometerRegistrator extends MetricRegistrator
Adapter that bridges GigaSpaces MetricRegistrator API to Micrometer's MeterRegistry.

This class serves two purposes:

  1. Modern API: Provides access to native Micrometer MeterRegistry and utilities for registering metrics using pure Micrometer APIs (preferred)
  2. Legacy Bridge: Adapts legacy metric types (LongCounter, ThroughputMetric, LatencyGauge) to Micrometer for backward compatibility (deprecated)

Recommended Usage: Use getMeterRegistry() and evaluateTags() to register metrics directly with Micrometer APIs (Gauge.builder(), Counter.builder(), Timer.builder()) or use MicrometerMetricFactory utility methods.

Legacy Usage: The register(String, Metric) method is maintained for backward compatibility but is deprecated. It converts legacy metric types to Micrometer equivalents.

Since:
17.1.4
See Also:
  • Constructor Details

    • MicrometerRegistrator

      public MicrometerRegistrator(io.micrometer.core.instrument.MeterRegistry meterRegistry, String prefix, io.micrometer.core.instrument.Tags staticTags, Map<String,DynamicMetricTag> dynamicTags, String separator)
    • MicrometerRegistrator

      public MicrometerRegistrator(io.micrometer.core.instrument.MeterRegistry meterRegistry, String prefix, io.micrometer.core.instrument.Tags staticTags, String separator)
    • MicrometerRegistrator

      public MicrometerRegistrator(io.micrometer.core.instrument.MeterRegistry meterRegistry)
  • Method Details

    • evaluateTags

      public io.micrometer.core.instrument.Tags evaluateTags()
      Evaluate dynamic tags and combine with static tags. This is called each time we register a metric to get the current tag values.
    • extend

      public MetricRegistrator extend(String prefix)
      Specified by:
      extend in class MetricRegistrator
    • extend

      public MetricRegistrator extend(String prefix, Map<String,String> newTags, Map<String,DynamicMetricTag> newDynamicTags)
      Description copied from class: MetricRegistrator
      Extend this registrator with additional prefix, tags, and dynamic tags. Default implementation ignores the extra parameters and calls extend(prefix). Subclasses should override to handle tags and dynamic tags.
      Overrides:
      extend in class MetricRegistrator
    • toPath

      public String toPath(String... names)
      Specified by:
      toPath in class MetricRegistrator
    • getFullMetricName

      public String getFullMetricName(String name)
      Returns the full metric name including the prefix. Used when registering Micrometer gauges to ensure consistent naming.
      Parameters:
      name - the metric name
      Returns:
      the full metric name with prefix
    • register

      @Deprecated public void register(String name, Metric metric)
      Deprecated.
      Since 17.1.5 - All legacy metrics have been migrated. This method will be removed in v18.0.
      Legacy metric registration method - NO LONGER SUPPORTED.

      REMOVED: All production code has been migrated to use Micrometer APIs directly. This method now throws UnsupportedOperationException.

      Migration Guide:

      
       // OLD (no longer supported):
       registrator.register("my-counter", new LongCounter());
      
       // NEW (use Micrometer directly):
       MicrometerRegistrator mr = (MicrometerRegistrator) registrator;
       MeterRegistry registry = mr.getMeterRegistry();
       Tags tags = mr.evaluateTags();
      
       // For counters:
       AtomicLong counter = new AtomicLong();
       FunctionCounter.builder(mr.getFullMetricName("my-counter"), counter, AtomicLong::get)
           .tags(tags)
           .register(registry);
      
       // For gauges:
       Gauge.builder(mr.getFullMetricName("my-gauge"), myObject, MyObject::getValue)
           .tags(tags)
           .register(registry);
      
       // For timers:
       Timer timer = Timer.builder(mr.getFullMetricName("my-timer"))
           .tags(tags)
           .register(registry);
       
      Parameters:
      name - the metric name
      metric - the legacy metric instance
      Throws:
      UnsupportedOperationException - always - this method is no longer supported
      See Also:
    • unregister

      public void unregister(String name)
      Description copied from interface: BeanMetricManager
      Unregisters the specified metric.
      Parameters:
      name - Name of metric to unregister
    • unregisterByPrefix

      public void unregisterByPrefix(String prefix)
      Specified by:
      unregisterByPrefix in class MetricRegistrator
    • keepAlive

      public void keepAlive(Object stateObject)
      Keep a strong reference to a gauge state object, preventing it from being garbage-collected. Micrometer's Gauge holds only a WeakReference to its state object — any locally-created object passed to Gauge.builder() must be kept alive here, or the gauge will silently stop reporting once GC collects the object. The reference is released when clear() is called.
    • clear

      public void clear()
      Description copied from interface: BeanMetricManager
      Unregisters all the metrics registered via this BeanMetricManager instance.
    • getMeterRegistry

      public io.micrometer.core.instrument.MeterRegistry getMeterRegistry()