Class MicrometerRegistrator
java.lang.Object
com.gigaspaces.metrics.MetricRegistrator
com.gigaspaces.metrics.micrometer.MicrometerRegistrator
- All Implemented Interfaces:
BeanMetricManager
Adapter that bridges GigaSpaces MetricRegistrator API to Micrometer's MeterRegistry.
This class serves two purposes:
- Modern API: Provides access to native Micrometer MeterRegistry and utilities for registering metrics using pure Micrometer APIs (preferred)
- 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 Summary
ConstructorsConstructorDescriptionMicrometerRegistrator(io.micrometer.core.instrument.MeterRegistry meterRegistry) MicrometerRegistrator(io.micrometer.core.instrument.MeterRegistry meterRegistry, String prefix, io.micrometer.core.instrument.Tags staticTags, String separator) MicrometerRegistrator(io.micrometer.core.instrument.MeterRegistry meterRegistry, String prefix, io.micrometer.core.instrument.Tags staticTags, Map<String, DynamicMetricTag> dynamicTags, String separator) -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Unregisters all the metrics registered via this BeanMetricManager instance.io.micrometer.core.instrument.TagsEvaluate dynamic tags and combine with static tags.Extend this registrator with additional prefix, tags, and dynamic tags.getFullMetricName(String name) Returns the full metric name including the prefix.io.micrometer.core.instrument.MeterRegistryvoidKeep a strong reference to a gauge state object, preventing it from being garbage-collected.voidDeprecated.Since 17.1.5 - All legacy metrics have been migrated.voidunregister(String name) Unregisters the specified metric.voidunregisterByPrefix(String prefix)
-
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
-
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
- Specified by:
extendin classMetricRegistrator
-
extend
public MetricRegistrator extend(String prefix, Map<String, String> newTags, Map<String, DynamicMetricTag> newDynamicTags) Description copied from class:MetricRegistratorExtend 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:
extendin classMetricRegistrator
-
toPath
- Specified by:
toPathin classMetricRegistrator
-
getFullMetricName
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.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 namemetric- the legacy metric instance- Throws:
UnsupportedOperationException- always - this method is no longer supported- See Also:
-
unregister
Description copied from interface:BeanMetricManagerUnregisters the specified metric.- Parameters:
name- Name of metric to unregister
-
unregisterByPrefix
- Specified by:
unregisterByPrefixin classMetricRegistrator
-
keepAlive
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 whenclear()is called. -
clear
public void clear()Description copied from interface:BeanMetricManagerUnregisters all the metrics registered via this BeanMetricManager instance. -
getMeterRegistry
public io.micrometer.core.instrument.MeterRegistry getMeterRegistry()
-