Class Metrics
This class provides convenient static access to the MeterRegistry for components that don't extend QBeanSupport or otherwise have direct access to the Q2 container.
Usage Examples
For QBeans (components extending QBeanSupport)
MeterRegistry registry = getServer().getMeterRegistry();
For Non-QBean components (e.g., providers, participants)
import org.jpos.metrics.Metrics;
MeterRegistry registry = Metrics.getMeterRegistry();
Counter counter = Counter.builder("my.metric")
.description("My metric description")
.register(registry);
Using MeterFactory for consistent metrics
MeterRegistry registry = Metrics.getMeterRegistry();
Counter counter = MeterFactory.counter(registry, myMeterInfo, Tags.of("key", "value"));
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic io.micrometer.core.instrument.MeterRegistryGet the MeterRegistry from the default Q2 instance.static io.micrometer.core.instrument.MeterRegistrygetMeterRegistry(long timeout) Get the MeterRegistry from the default Q2 instance, waiting up to timeout milliseconds.static io.micrometer.core.instrument.MeterRegistrygetMeterRegistry(String q2Name) Get the MeterRegistry from a named Q2 instance.static io.micrometer.core.instrument.MeterRegistrygetMeterRegistry(String q2Name, long timeout) Get the MeterRegistry from a named Q2 instance, waiting up to timeout milliseconds.
-
Constructor Details
-
Metrics
public Metrics()Default constructor; no instance state to initialise.
-
-
Method Details
-
getMeterRegistry
Get the MeterRegistry from the default Q2 instance.For use by components that don't have direct access to Q2 (non-QBeans). This method looks up the Q2 instance registered as "Q2" in NameRegistrar and returns its MeterRegistry, or null if Q2 is not available.
Note: Q2.getQ2() returns null if Q2 is not found (uses getIfExists internally).
- Returns:
- MeterRegistry from the default Q2 instance, or null if Q2 not available
-
getMeterRegistry
Get the MeterRegistry from the default Q2 instance, waiting up to timeout milliseconds.This variant blocks until Q2 is available or the timeout expires. Useful during initialization when Q2 might not be fully started yet.
Throws
NameRegistrar.NotFoundException(unchecked) if Q2 is not registered before the timeout elapses.- Parameters:
timeout- maximum time to wait in milliseconds- Returns:
- MeterRegistry from Q2
-
getMeterRegistry
Get the MeterRegistry from a named Q2 instance.Use this when multiple Q2 instances are running and you need to access a specific instance's MeterRegistry.
- Parameters:
q2Name- Q2 instance name (e.g., "Q2", "Q2-1", etc.)- Returns:
- MeterRegistry from the named Q2 instance, or null if not found
-
getMeterRegistry
public static io.micrometer.core.instrument.MeterRegistry getMeterRegistry(String q2Name, long timeout) Get the MeterRegistry from a named Q2 instance, waiting up to timeout milliseconds.Throws
NameRegistrar.NotFoundException(unchecked) if the named Q2 is not registered before the timeout elapses.- Parameters:
q2Name- Q2 instance nametimeout- maximum time to wait in milliseconds- Returns:
- MeterRegistry from named Q2 instance
-