Interface MetricsProvider
public interface MetricsProvider
Simplified metrics provider interface.
- Author:
- Holger Eichelberger, SSE
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceSupplies access to a time measurement. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddGaugeValue(String gaugeId, double value) Adds a gauge value to the MeterRegistry.
If the identifier does not correspond to an existing gauge, a new gauge will be created and registered.voidaddService(MonitoringService service) Adds a service to be updated regularly regarding its monitoring data.createServiceProcessingTimer(String serviceName, String serviceId, String appId, String appInstanceId) Creates and registers a default service processing timer.default CountercreateServiceReceivedCounter(String serviceName, String serviceId, String appId, String appInstanceId) Creates and registers a default service received counter.default CountercreateServiceSentCounter(String serviceName, String serviceId, String appId, String appInstanceId) Creates and registers a default service sent counter.createServiceSentReceivedCounter(boolean receive, String serviceName, String serviceId, String appId, String appInstanceId) Creates and registers a default service send/receive counter.getClock()Returns the clock used in the underlying meter registry.Returns the meter registry.static voidincreaseCounterBy(Counter counter, double value) Helper method to increase/increment the givencounterby the specifiedvalue.static <T> TincreaseCounterBy(Counter counter, double value, T data) Helper method to increase/increment the givencounterby the specifiedvalueifdatais not null.voidincreaseCounterBy(String counterId, double value) Increases the counter by a certain value.
If the identifier does not correspond to an existing counter, a new counter will be created and registered.static voidrecordMsTime(Timer timer, MetricsProvider.TimeSupplier timeSupplier, Runnable function) Record milliseconds time.static voidrecordNsTime(Timer timer, MetricsProvider.TimeSupplier timeSupplier, Runnable function) Record nanoseconds time.voidrecordWithTimer(String timerId, long time, TimeUnit unit) Adds time from a specific timer.voidrecordWithTimer(String timerId, Runnable runnable) Records the execution of a runnable using a timer.<T> TrecordWithTimer(String timerId, Supplier<T> supplier) Records the execution of a supplier using a timer.voidremoveGauge(String gaugeId) Remove a custom gauge from the Meter Registry.
-
Method Details
-
getClock
Clock getClock()Returns the clock used in the underlying meter registry.- Returns:
- the clock
-
getRegistry
MeterRegistry getRegistry()Returns the meter registry.- Returns:
- the meter registry
-
recordWithTimer
Records the execution of a runnable using a timer.- Parameters:
timerId- identifier of the custom timerrunnable- runnable function that we want to record- Throws:
IllegalArgumentException- if the runnable or the identifier are null
-
recordWithTimer
Records the execution of a supplier using a timer.- Type Parameters:
T- the datatype that the supplier returns- Parameters:
timerId- identifier of the custom timersupplier- supplier function that we want to record- Returns:
- the value returned by the supplier
- Throws:
IllegalArgumentException- if the identifier or the supplier are null
-
recordWithTimer
Adds time from a specific timer.- Parameters:
timerId- identifier of the custom timertime- amount of time we want to recordunit- base unit of the time we want to record- Throws:
IllegalArgumentException- if the identifier or the supplier are nullIllegalArgumentException- if thetimeis negative
-
addGaugeValue
Adds a gauge value to the MeterRegistry.
If the identifier does not correspond to an existing gauge, a new gauge will be created and registered. If it is an existing gauge, the value will simply be modified.- Parameters:
gaugeId- identifier for the gaugevalue- value we want to set the gauge to- Throws:
IllegalArgumentException- if the identifier is null
-
removeGauge
Remove a custom gauge from the Meter Registry.- Parameters:
gaugeId- identifier of the custom gauge- Throws:
IllegalArgumentException- if there is no gauge with that identifier
-
increaseCounterBy
Increases the counter by a certain value.
If the identifier does not correspond to an existing counter, a new counter will be created and registered. If it is an existing counter, the value will simply be incremented by the amount requested.- Parameters:
counterId- identifier of the custom countervalue- the amount we want to increases the counter- Throws:
IllegalArgumentException- ifvalueis negative or ifcounterIdis null
-
createServiceReceivedCounter
default Counter createServiceReceivedCounter(String serviceName, String serviceId, String appId, String appInstanceId) Creates and registers a default service received counter.- Parameters:
serviceName- the static name/id of the serviceserviceId- the (complete) id of the serviceappId- the id of the applicationappInstanceId- the id of the application instance- Returns:
- the registered counter instance
- See Also:
-
createServiceSentCounter
default Counter createServiceSentCounter(String serviceName, String serviceId, String appId, String appInstanceId) Creates and registers a default service sent counter.- Parameters:
serviceName- the static name/id of the serviceserviceId- the (complete) id of the serviceappId- the id of the applicationappInstanceId- the id of the application instance- Returns:
- the registered counter instance
- See Also:
-
createServiceSentReceivedCounter
Counter createServiceSentReceivedCounter(boolean receive, String serviceName, String serviceId, String appId, String appInstanceId) Creates and registers a default service send/receive counter.- Parameters:
receive- is it for receiving (true) or sendingserviceName- the static name/id of the serviceserviceId- the (complete) id of the serviceappId- the id of the applicationappInstanceId- the id of the application instance- Returns:
- the registered counter instance
-
createServiceProcessingTimer
Timer createServiceProcessingTimer(String serviceName, String serviceId, String appId, String appInstanceId) Creates and registers a default service processing timer.- Parameters:
serviceName- the static name/id of the serviceserviceId- the (complete) id of the serviceappId- the id of the applicationappInstanceId- the id of the application instance- Returns:
- the registered counter instance
-
increaseCounterBy
Helper method to increase/increment the givencounterby the specifiedvalueifdatais not null. Does nothing ifcounteris null.- Parameters:
counter- the countervalue- the valuedata- the data to consider- Returns:
data
-
increaseCounterBy
Helper method to increase/increment the givencounterby the specifiedvalue. Does nothing ifcounteris null.- Parameters:
counter- the countervalue- the value
-
recordMsTime
Record milliseconds time.- Parameters:
timer- the timer to record the time ontimeSupplier- the time supplier returning the time after executingfunctionfunction- the function to execute
-
recordNsTime
Record nanoseconds time.- Parameters:
timer- the timer to record the time ontimeSupplier- the time supplier returning the time after executingfunctionfunction- the function to execute
-
addService
Adds a service to be updated regularly regarding its monitoring data. Services are not added multiple times.- Parameters:
service- the service, ignored if null
-