Class MetricsProvider
- java.lang.Object
-
- de.iip_ecosphere.platform.services.environment.metricsProvider.MetricsProvider
-
public class MetricsProvider extends java.lang.ObjectThis class represents an interface to manage the Micrometer-API meters.
The operations available in this class are:- Consulting the amount of custom meters of each type
- Modifying, consulting or deleting a custom gauge
- Modifying, consulting or deleting a custom counter
- Modifying, consulting or deleting a custom timer
- Consult the current capacity base unit for the Memory and Disk metrics
It is also mentioned that the Timer meter is the most resource consuming meter. It is recommended to use the already existing global timers instead of creating a new one.- Author:
- Miguel Gomez
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceMetricsProvider.TimeSupplierSupplies access to a time measurement.
-
Field Summary
Fields Modifier and Type Field Description private io.micrometer.core.instrument.Clockclockprivate java.util.Map<java.lang.String,io.micrometer.core.instrument.Counter>countersstatic io.micrometer.core.instrument.config.MeterFilter[]DEFAULT_METER_FILTERSstatic java.lang.StringDEVICE_CASE_TEMPERATUREstatic java.lang.StringDEVICE_CPU_CORESstatic java.lang.StringDEVICE_CPU_TEMPERATUREstatic java.lang.StringDEVICE_GPU_CORESstatic java.lang.StringDEVICE_TPU_CORESprivate floatdeviceCaseTemperatureprivate floatdeviceCpuTemperaturestatic CapacityBaseUnitDFLT_DISKstatic CapacityBaseUnitDFLT_MEMORYprivate CapacityBaseUnitdiskBaseUnitstatic java.util.List<io.micrometer.core.instrument.Tag>EMPTY_TAGSprivate java.util.Map<java.lang.String,com.google.common.util.concurrent.AtomicDouble>gaugesprotected static java.lang.StringID_NOT_FOUND_ERRMSGprivate booleaninitprivate CapacityBaseUnitmemoryBaseUnitprivate booleanmonitorNonNativeprotected static java.lang.StringNON_POSITIVE_ERRMSGprotected static java.lang.StringNULL_ARGprivate com.sun.management.OperatingSystemMXBeanosmxbprivate io.micrometer.core.instrument.MeterRegistryregistrystatic java.lang.StringSERVICE_TIME_PROCESSEDstatic java.lang.StringSERVICE_TUPLES_RECEIVEDstatic java.lang.StringSERVICE_TUPLES_SENTstatic java.lang.StringSYS_DISK_FREEstatic java.lang.StringSYS_DISK_TOTALstatic java.lang.StringSYS_DISK_USABLEstatic java.lang.StringSYS_DISK_USEDstatic java.lang.StringSYS_MEM_FREEstatic java.lang.StringSYS_MEM_TOTALstatic java.lang.StringSYS_MEM_USAGEstatic java.lang.StringSYS_MEM_USEDprivate doublesysDiskFreeprivate doublesysDiskTotalprivate doublesysDiskUsableprivate doublesysDiskUsedprivate doublesysMemFreeprivate doublesysMemTotalprivate doublesysMemUsageprivate doublesysMemUsedstatic java.lang.StringTAG_SERVICE_APPINSTIDstatic java.lang.StringTAG_SERVICE_APPLICATIONstatic java.lang.StringTAG_SERVICE_DEVICEstatic java.lang.StringTAG_SERVICE_SERVICEstatic java.lang.StringTAG_SERVICE_SERVICEIDprivate java.util.Map<java.lang.String,io.micrometer.core.instrument.Timer>timersprivate java.util.List<UpdatingMonitoringService>updaters
-
Constructor Summary
Constructors Constructor Description MetricsProvider(io.micrometer.core.instrument.MeterRegistry registry)Create a new Metrics Provider Instance.
The Metrics Provider will have a map of metrics that can be operated by the client via the appropriate methods, allowing the user to add new custom metrics when needed and manipulate them in a uniform manner.MetricsProvider(io.micrometer.core.instrument.MeterRegistry registry, boolean monitorNonNative)Create a new Metrics Provider Instance.
The Metrics Provider will have a map of metrics that can be operated by the client via the appropriate methods, allowing the user to add new custom metrics when needed and manipulate them in a uniform manner.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddCounter(java.lang.String counterId)Creates a new counter and registers it in the MeterRegistry.voidaddGaugeValue(java.lang.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(UpdatingMonitoringService service)Adds a service to be updated regularly regarding its monitoring data.protected voidaddTimer(java.lang.String timerId)Create a new custom timer to be added to the Meter registry.static io.micrometer.core.instrument.config.MeterFilter[]append(io.micrometer.core.instrument.config.MeterFilter[] base, io.micrometer.core.instrument.config.MeterFilter... addition)Appendsadditiontobase.static voidapply(io.micrometer.core.instrument.MeterRegistry registry, io.micrometer.core.instrument.config.MeterFilter... filters)Applies the given list of meter filters.voidcalculateMetrics()Call this method to update the metrics.voidcalculateNonNativeSystemMetrics()This operation calculates the values for the extra system metrics not exposed by Micrometer-API.
Even though this sacrifices the real time values of these metrics, we gain speed when requesting the metrics as we no longer have to calculate the values upon request.io.micrometer.core.instrument.TimercreateServiceProcessingTimer(java.lang.String serviceName, java.lang.String serviceId, java.lang.String appId, java.lang.String appInstanceId)Creates and registers a default service processing timer.io.micrometer.core.instrument.CountercreateServiceReceivedCounter(java.lang.String serviceName, java.lang.String serviceId, java.lang.String appId, java.lang.String appInstanceId)Creates and registers a default service received counter.io.micrometer.core.instrument.CountercreateServiceSentCounter(java.lang.String serviceName, java.lang.String serviceId, java.lang.String appId, java.lang.String appInstanceId)Creates and registers a default service sent counter.io.micrometer.core.instrument.CountercreateServiceSentReceivedCounter(boolean receive, java.lang.String serviceName, java.lang.String serviceId, java.lang.String appId, java.lang.String appInstanceId)Creates and registers a default service send/receive counter.static java.util.List<io.micrometer.core.instrument.Meter>filter(java.util.List<io.micrometer.core.instrument.Meter> meters, boolean copy, io.micrometer.core.instrument.config.MeterFilter... filters)Filters the given meters according to the specified filters.io.micrometer.core.instrument.ClockgetClock()Returns the clock used in the underlying meter registry.java.lang.StringgetCounter(java.lang.String name)Retrieves a custom counter as a JSON object.
The requested counter is located within the map and parsed as a JsonObject to be sent via HTTP.doublegetCounterValue(java.lang.String counterId)Retrieves the value of a custom Counter.
If no counter is found with that identifier, this method will return zero.java.lang.StringgetCustomCounterList()Returns a list of the names of the registered custom counters.
The list is returned as a JsonArray containing Strings.java.lang.StringgetCustomGaugeList()Returns a list of the names of the registered custom gauges.
The list is returned as a JsonArray containing Strings.java.lang.StringgetCustomTimerList()Returns a list of the names of the registered custom timers.
The list is returned as a JsonArray containing Strings.CapacityBaseUnitgetDiskBaseUnit()Consults the capacity base unit used for the disk capacity metrics.java.lang.StringgetGauge(java.lang.String name)Retrieves a custom gauge as a JSON object.
The requested gauge is located within the map and parsed as a JsonObject to be sent via HTTP.doublegetGaugeValue(java.lang.String gaugeId)Retrieves the value of a custom Gauge.
If no gauge is found with that identifier, this method will return zerodoublegetMaxTimeFromTimer(java.lang.String timerId)Retrieves the maximum time recorded by the timer in its base unit.
If no timer is found with that identifier, this method will return zero.CapacityBaseUnitgetMemoryBaseUnit()Consults the capacity base unit used for the physical memory metrics.java.lang.StringgetMeter(java.lang.String name, java.lang.Iterable<io.micrometer.core.instrument.Tag> tags)Retrieves a meter as a JSON object.
The requested meter is located and parsed as a JsonObject to be sent via HTTP.intgetNumberOfCustomCounters()Consult the number of custom counters that are registered by the MetricsProvider.intgetNumberOfCustomGauges()Consult the number of custom gauges that are registered by the MetricsProvider.intgetNumberOfCustomTimers()Consult the number of custom timers that are registered by the MetricsProvider.doublegetRegisteredCounterValue(java.lang.String counterId)Retrieves the value of a registered Counter, i.e., custom, non-native ones of this provider or micrometer/pre-registered ones
If no counter is found with that identifier, this method will return zero.doublegetRegisteredGaugeValue(java.lang.String gaugeId)Retrieves the value of a registered Gauge, i.e., custom, non-native ones of this provider or micrometer/pre-registered ones
If no gauge is found with that identifier, this method will return zero.longgetRegisteredTimerCount(java.lang.String timerId)Retrieves the value of a registered Timer, i.e., custom, non-native ones of this provider or micrometer/pre-registered ones
If no timer is found with that identifier, this method will return zero.io.micrometer.core.instrument.MeterRegistrygetRegistry()Returns the meter registry.java.lang.StringgetSimpleMeterList()Returns a list of names of the relevant Meters registered by micrometer that have no tags.java.lang.StringgetTaggedMeterList()Returns a list of names of the relevant Meters registered by micrometer that have tags.java.lang.StringgetTimer(java.lang.String name)Retrieves a custom timer as a JSON object.
The requested timer is located within the map and parsed as a JsonObject to be sent via HTTP.longgetTimerCount(java.lang.String timerId)Retrieves the number of times a timer has been used.
If no timer is found with that identifier, this method will return zero.doublegetTotalTimeFromTimer(java.lang.String timerId)Retrieves the total time from the timer in its base unit.
If no timer is found with that identifier, this method will return zero.static booleaninclude(io.micrometer.core.instrument.Meter.Id id, io.micrometer.core.instrument.config.MeterFilter... filters)Returns whether a meter id shall be included into a result set.static booleaninclude(java.lang.String id, io.micrometer.core.instrument.config.MeterFilter... filters)Returns whether a meter id shall be included into a result set.voidincreaseCounter(java.lang.String counterId)Increases the counter by one.static voidincreaseCounterBy(io.micrometer.core.instrument.Counter counter, double value)Helper method to increase/increment the givencounterby the specifiedvalue.voidincreaseCounterBy(java.lang.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.private java.lang.StringjsonParser(io.micrometer.core.instrument.Meter meter)Parses a meter into a JsonObject to be sent via HTTP.
Due to the current limitations with inserting the actualJsonlibraries inside this component, this method acts like a crude substitute that creates a String that can later be parsed into a valid JsonObject.
In order to maintain a certain uniformity, the resulting JSON object mimics the structure that Micrometer-API metrics have when exposed by the Spring Boot Actuator.
It is important to add that if the description contains any"characters, they will be exchanged for''due to the limitations we currently have regarding JSON parsing.private java.lang.StringmapJsonParser(java.util.Map<java.lang.String,?> map)Parses one of the custom meter maps into a JsonArray containing the names.
This method is to be used bygetCustomCounterList(),getCustomGaugeList()and @link MetricsProvider#getCustomTimerList()}.static voidrecordMsTime(io.micrometer.core.instrument.Timer timer, MetricsProvider.TimeSupplier timeSupplier, java.lang.Runnable function)Record milliseconds time.voidrecordWithTimer(java.lang.String timerId, long time, java.util.concurrent.TimeUnit unit)Adds time from a specific timer.voidrecordWithTimer(java.lang.String timerId, java.lang.Runnable runnable)Records the execution of a runnable using a timer.<T> TrecordWithTimer(java.lang.String timerId, java.util.function.Supplier<T> supplier)Records the execution of a supplier using a timer.voidregisterDeviceMetrics()Registers the default device metrics.
It can be called multiple times during execution in order to update the base units.voidregisterDiskMetrics()Registers the disk capacity metrics.
It can be called multiple times during execution in order to update the disk capacity base unit.voidregisterMemoryMetrics()Registers the physical memory metrics except for the usage percentage.
It can be called multiple times during execution in order to update the memory base unit.voidregisterNonNativeSystemMetrics()Registers the extra system metrics onto the registry.
The extra system metrics include the physical memory values and the disk values, which are metrics not automatically recorded by Micrometer-API.voidremoveCounter(java.lang.String counterId)Remove a custom counter from the Meter Registry.voidremoveDeviceMetrics()Removes the default device metrics from the registry.
This method is required as the previous memory metrics have to be removed and registered again after changing the base unit in order for the description to update correctly.voidremoveDiskMetrics()Removes the disk capacity metrics from the registry.
This method is required as the previous disk capacity metrics have to be removed and registered again after changing the base unit in order for the description to update correctly.voidremoveGauge(java.lang.String gaugeId)Remove a custom gauge from the Meter Registry.voidremoveMemoryMetrics()Removes the physical memory metrics from the registry.
This method is required as the previous memory metrics have to be removed and registered again after changing the base unit in order for the description to update correctly.voidremoveTimer(java.lang.String timerId)Remove a custom timer from the Registry.voidsetDiskBaseUnit(CapacityBaseUnit diskBaseUnit)Changes the disk capacity base unit.voidsetMemoryBaseUnit(CapacityBaseUnit memoryBaseUnit)Changes the memory base unit.java.lang.StringtoJson(java.lang.String identifier, boolean update, io.micrometer.core.instrument.config.MeterFilter... filter)Returns the full provider in Json.
-
-
-
Field Detail
-
EMPTY_TAGS
public static final java.util.List<io.micrometer.core.instrument.Tag> EMPTY_TAGS
-
DEFAULT_METER_FILTERS
public static final io.micrometer.core.instrument.config.MeterFilter[] DEFAULT_METER_FILTERS
-
TAG_SERVICE_SERVICE
public static final java.lang.String TAG_SERVICE_SERVICE
- See Also:
- Constant Field Values
-
TAG_SERVICE_APPLICATION
public static final java.lang.String TAG_SERVICE_APPLICATION
- See Also:
- Constant Field Values
-
TAG_SERVICE_DEVICE
public static final java.lang.String TAG_SERVICE_DEVICE
- See Also:
- Constant Field Values
-
TAG_SERVICE_SERVICEID
public static final java.lang.String TAG_SERVICE_SERVICEID
- See Also:
- Constant Field Values
-
TAG_SERVICE_APPINSTID
public static final java.lang.String TAG_SERVICE_APPINSTID
- See Also:
- Constant Field Values
-
SYS_MEM_TOTAL
public static final java.lang.String SYS_MEM_TOTAL
- See Also:
- Constant Field Values
-
SYS_MEM_FREE
public static final java.lang.String SYS_MEM_FREE
- See Also:
- Constant Field Values
-
SYS_MEM_USED
public static final java.lang.String SYS_MEM_USED
- See Also:
- Constant Field Values
-
SYS_MEM_USAGE
public static final java.lang.String SYS_MEM_USAGE
- See Also:
- Constant Field Values
-
SYS_DISK_TOTAL
public static final java.lang.String SYS_DISK_TOTAL
- See Also:
- Constant Field Values
-
SYS_DISK_FREE
public static final java.lang.String SYS_DISK_FREE
- See Also:
- Constant Field Values
-
SYS_DISK_USABLE
public static final java.lang.String SYS_DISK_USABLE
- See Also:
- Constant Field Values
-
SYS_DISK_USED
public static final java.lang.String SYS_DISK_USED
- See Also:
- Constant Field Values
-
DEVICE_CPU_TEMPERATURE
public static final java.lang.String DEVICE_CPU_TEMPERATURE
- See Also:
- Constant Field Values
-
DEVICE_CASE_TEMPERATURE
public static final java.lang.String DEVICE_CASE_TEMPERATURE
- See Also:
- Constant Field Values
-
DEVICE_TPU_CORES
public static final java.lang.String DEVICE_TPU_CORES
- See Also:
- Constant Field Values
-
DEVICE_GPU_CORES
public static final java.lang.String DEVICE_GPU_CORES
- See Also:
- Constant Field Values
-
DEVICE_CPU_CORES
public static final java.lang.String DEVICE_CPU_CORES
- See Also:
- Constant Field Values
-
SERVICE_TUPLES_SENT
public static final java.lang.String SERVICE_TUPLES_SENT
- See Also:
- Constant Field Values
-
SERVICE_TUPLES_RECEIVED
public static final java.lang.String SERVICE_TUPLES_RECEIVED
- See Also:
- Constant Field Values
-
SERVICE_TIME_PROCESSED
public static final java.lang.String SERVICE_TIME_PROCESSED
- See Also:
- Constant Field Values
-
DFLT_MEMORY
public static final CapacityBaseUnit DFLT_MEMORY
-
DFLT_DISK
public static final CapacityBaseUnit DFLT_DISK
-
ID_NOT_FOUND_ERRMSG
protected static final java.lang.String ID_NOT_FOUND_ERRMSG
- See Also:
- Constant Field Values
-
NON_POSITIVE_ERRMSG
protected static final java.lang.String NON_POSITIVE_ERRMSG
- See Also:
- Constant Field Values
-
NULL_ARG
protected static final java.lang.String NULL_ARG
- See Also:
- Constant Field Values
-
registry
private final io.micrometer.core.instrument.MeterRegistry registry
-
osmxb
private final com.sun.management.OperatingSystemMXBean osmxb
-
init
private boolean init
-
clock
private io.micrometer.core.instrument.Clock clock
-
updaters
private java.util.List<UpdatingMonitoringService> updaters
-
memoryBaseUnit
private CapacityBaseUnit memoryBaseUnit
-
diskBaseUnit
private CapacityBaseUnit diskBaseUnit
-
gauges
private final java.util.Map<java.lang.String,com.google.common.util.concurrent.AtomicDouble> gauges
-
counters
private final java.util.Map<java.lang.String,io.micrometer.core.instrument.Counter> counters
-
timers
private final java.util.Map<java.lang.String,io.micrometer.core.instrument.Timer> timers
-
monitorNonNative
private boolean monitorNonNative
-
sysMemTotal
private double sysMemTotal
-
sysMemFree
private double sysMemFree
-
sysMemUsed
private double sysMemUsed
-
sysMemUsage
private double sysMemUsage
-
sysDiskTotal
private double sysDiskTotal
-
sysDiskFree
private double sysDiskFree
-
sysDiskUsable
private double sysDiskUsable
-
sysDiskUsed
private double sysDiskUsed
-
deviceCpuTemperature
private float deviceCpuTemperature
-
deviceCaseTemperature
private float deviceCaseTemperature
-
-
Constructor Detail
-
MetricsProvider
public MetricsProvider(io.micrometer.core.instrument.MeterRegistry registry)
Create a new Metrics Provider Instance.
The Metrics Provider will have a map of metrics that can be operated by the client via the appropriate methods, allowing the user to add new custom metrics when needed and manipulate them in a uniform manner.
This constructor enables monitoring of (default IIP-Ecosphere) non-native system metrics; requirescalculateNonNativeSystemMetrics()to be called regularly.- Parameters:
registry- where new Meters are registered. Injected by the Spring Boot Application- Throws:
java.lang.IllegalArgumentException- if the registry is null- See Also:
MetricsProvider(MeterRegistry, boolean)
-
MetricsProvider
public MetricsProvider(io.micrometer.core.instrument.MeterRegistry registry, boolean monitorNonNative)Create a new Metrics Provider Instance.
The Metrics Provider will have a map of metrics that can be operated by the client via the appropriate methods, allowing the user to add new custom metrics when needed and manipulate them in a uniform manner.- Parameters:
registry- where new Meters are registered. Injected by the Spring Boot ApplicationmonitorNonNative- enable/disable monitoring of (default IIP-Ecosphere) non-native system metrics, requirescalculateNonNativeSystemMetrics()to be called regularly- Throws:
java.lang.IllegalArgumentException- if the registry is null
-
-
Method Detail
-
getRegistry
public io.micrometer.core.instrument.MeterRegistry getRegistry()
Returns the meter registry.- Returns:
- the meter registry
-
getClock
public io.micrometer.core.instrument.Clock getClock()
Returns the clock used in the underlying meter registry.- Returns:
- the clock
-
registerNonNativeSystemMetrics
public void registerNonNativeSystemMetrics()
Registers the extra system metrics onto the registry.
The extra system metrics include the physical memory values and the disk values, which are metrics not automatically recorded by Micrometer-API.
-
registerMemoryMetrics
public void registerMemoryMetrics()
Registers the physical memory metrics except for the usage percentage.
It can be called multiple times during execution in order to update the memory base unit.
-
registerDiskMetrics
public void registerDiskMetrics()
Registers the disk capacity metrics.
It can be called multiple times during execution in order to update the disk capacity base unit.
-
registerDeviceMetrics
public void registerDeviceMetrics()
Registers the default device metrics.
It can be called multiple times during execution in order to update the base units.
-
removeDeviceMetrics
public void removeDeviceMetrics()
Removes the default device metrics from the registry.
This method is required as the previous memory metrics have to be removed and registered again after changing the base unit in order for the description to update correctly.
-
removeMemoryMetrics
public void removeMemoryMetrics()
Removes the physical memory metrics from the registry.
This method is required as the previous memory metrics have to be removed and registered again after changing the base unit in order for the description to update correctly.
-
removeDiskMetrics
public void removeDiskMetrics()
Removes the disk capacity metrics from the registry.
This method is required as the previous disk capacity metrics have to be removed and registered again after changing the base unit in order for the description to update correctly.
-
getNumberOfCustomGauges
public int getNumberOfCustomGauges()
Consult the number of custom gauges that are registered by the MetricsProvider.- Returns:
- number of custom gauges currently registered
-
getNumberOfCustomCounters
public int getNumberOfCustomCounters()
Consult the number of custom counters that are registered by the MetricsProvider.- Returns:
- number of custom counters currently registered
-
getNumberOfCustomTimers
public int getNumberOfCustomTimers()
Consult the number of custom timers that are registered by the MetricsProvider.- Returns:
- number of custom timers currently registered
-
addGaugeValue
public void addGaugeValue(java.lang.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. 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:
java.lang.IllegalArgumentException- if the identifier is null
-
removeGauge
public void removeGauge(java.lang.String gaugeId)
Remove a custom gauge from the Meter Registry.- Parameters:
gaugeId- identifier of the custom gauge- Throws:
java.lang.IllegalArgumentException- if there is no gauge with that identifier
-
getGaugeValue
public double getGaugeValue(java.lang.String gaugeId)
Retrieves the value of a custom Gauge.
If no gauge is found with that identifier, this method will return zero- Parameters:
gaugeId- identifier of the custom gauge- Returns:
- current value of the custom gauge or
0.0if there is no gauge with the requested identifier
-
getRegisteredGaugeValue
public double getRegisteredGaugeValue(java.lang.String gaugeId)
Retrieves the value of a registered Gauge, i.e., custom, non-native ones of this provider or micrometer/pre-registered ones
If no gauge is found with that identifier, this method will return zero.- Parameters:
gaugeId- identifier of the gauge- Returns:
- current value of the gauge or
0.0if there is no gauge with the requested identifier
-
addCounter
private void addCounter(java.lang.String counterId)
Creates a new counter and registers it in the MeterRegistry.- Parameters:
counterId- identifier of the counter
-
increaseCounterBy
public void increaseCounterBy(java.lang.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. 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:
java.lang.IllegalArgumentException- ifvalueis negative or ifcounterIdis null
-
increaseCounterBy
public static void increaseCounterBy(io.micrometer.core.instrument.Counter counter, double value)Helper method to increase/increment the givencounterby the specifiedvalue. Does nothing ifcounteris null.- Parameters:
counter- the countervalue- the value
-
recordMsTime
public static void recordMsTime(io.micrometer.core.instrument.Timer timer, MetricsProvider.TimeSupplier timeSupplier, java.lang.Runnable function)Record milliseconds time.- Parameters:
timer- the timer to record the time ontimeSupplier- the time supplier returning the time after executingfunctionfunction- the function to execute
-
increaseCounter
public void increaseCounter(java.lang.String counterId)
Increases the counter by one.
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.- Parameters:
counterId- identifier of the custom counter- Throws:
java.lang.IllegalArgumentException- ifvalueis negative or ifcounterIdis null
-
removeCounter
public void removeCounter(java.lang.String counterId)
Remove a custom counter from the Meter Registry.- Parameters:
counterId- identifier of the custom counter- Throws:
java.lang.IllegalArgumentException- if there is no counter with that identifier
-
getCounterValue
public double getCounterValue(java.lang.String counterId)
Retrieves the value of a custom Counter.
If no counter is found with that identifier, this method will return zero.- Parameters:
counterId- identifier of the custom counter- Returns:
- current value of the custom counter or
0.0if there is no counter with the requested identifier
-
getRegisteredCounterValue
public double getRegisteredCounterValue(java.lang.String counterId)
Retrieves the value of a registered Counter, i.e., custom, non-native ones of this provider or micrometer/pre-registered ones
If no counter is found with that identifier, this method will return zero.- Parameters:
counterId- identifier of the counter- Returns:
- current value of the counter or
0.0if there is no counter with the requested identifier
-
addTimer
protected void addTimer(java.lang.String timerId)
Create a new custom timer to be added to the Meter registry.- Parameters:
timerId- identifier of the custom timer- Throws:
java.lang.IllegalArgumentException- if the identifier is null
-
removeTimer
public void removeTimer(java.lang.String timerId)
Remove a custom timer from the Registry.- Parameters:
timerId- identifier of the custom timer- Throws:
java.lang.IllegalArgumentException- if there is no timer with that identifier
-
recordWithTimer
public void recordWithTimer(java.lang.String timerId, java.lang.Runnable runnable)Records the execution of a runnable using a timer.- Parameters:
timerId- identifier of the custom timerrunnable- runnable function that we want to record- Throws:
java.lang.IllegalArgumentException- if the runnable or the identifier are null
-
recordWithTimer
public <T> T recordWithTimer(java.lang.String timerId, java.util.function.Supplier<T> supplier)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:
java.lang.IllegalArgumentException- if the identifier or the supplier are null
-
recordWithTimer
public void recordWithTimer(java.lang.String timerId, long time, java.util.concurrent.TimeUnit unit)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:
java.lang.IllegalArgumentException- if the identifier or the supplier are nulljava.lang.IllegalArgumentException- if thetimeis negative
-
getTotalTimeFromTimer
public double getTotalTimeFromTimer(java.lang.String timerId)
Retrieves the total time from the timer in its base unit.
If no timer is found with that identifier, this method will return zero. The base unit for a timer is, by default, seconds.- Parameters:
timerId- identifier of the custom timer- Returns:
- total time recorded by the timer or
0.0if no timer is found with that identifier
-
getMaxTimeFromTimer
public double getMaxTimeFromTimer(java.lang.String timerId)
Retrieves the maximum time recorded by the timer in its base unit.
If no timer is found with that identifier, this method will return zero. The base unit for a timer is, by default, seconds.- Parameters:
timerId- identifier of the custom timer- Returns:
- maximum time recorded by the timer or
0.0if no timer is found with that identifier
-
getTimerCount
public long getTimerCount(java.lang.String timerId)
Retrieves the number of times a timer has been used.
If no timer is found with that identifier, this method will return zero.- Parameters:
timerId- identifier of the custom timer- Returns:
- number of times this timer was called or
0if no timer is found with that identifier
-
getRegisteredTimerCount
public long getRegisteredTimerCount(java.lang.String timerId)
Retrieves the value of a registered Timer, i.e., custom, non-native ones of this provider or micrometer/pre-registered ones
If no timer is found with that identifier, this method will return zero.- Parameters:
timerId- identifier of the timer- Returns:
- current value of the timer or
0if there is no timer with the requested identifier
-
addService
public void addService(UpdatingMonitoringService service)
Adds a service to be updated regularly regarding its monitoring data. Services are not added multiple times.- Parameters:
service- the service, ignored if null
-
calculateMetrics
public void calculateMetrics()
Call this method to update the metrics. May be called regularly.
-
calculateNonNativeSystemMetrics
public void calculateNonNativeSystemMetrics()
This operation calculates the values for the extra system metrics not exposed by Micrometer-API.
Even though this sacrifices the real time values of these metrics, we gain speed when requesting the metrics as we no longer have to calculate the values upon request. TheSCHEDULE_RATEindicates the time in between calculations.
-
setMemoryBaseUnit
public void setMemoryBaseUnit(CapacityBaseUnit memoryBaseUnit)
Changes the memory base unit.- Parameters:
memoryBaseUnit- new capacity base unit for the memory- Throws:
java.lang.IllegalArgumentException- if thememoryBaseUnitis null
-
getMemoryBaseUnit
public CapacityBaseUnit getMemoryBaseUnit()
Consults the capacity base unit used for the physical memory metrics.- Returns:
- capacity base unit for the memory metrics
-
setDiskBaseUnit
public void setDiskBaseUnit(CapacityBaseUnit diskBaseUnit)
Changes the disk capacity base unit.- Parameters:
diskBaseUnit- new capacity base unit for the disk capacity- Throws:
java.lang.IllegalArgumentException- if thememoryBaseUnitis null
-
getDiskBaseUnit
public CapacityBaseUnit getDiskBaseUnit()
Consults the capacity base unit used for the disk capacity metrics.- Returns:
- capacity base unit for the disk capacity metrics
-
getMeter
public java.lang.String getMeter(java.lang.String name, java.lang.Iterable<io.micrometer.core.instrument.Tag> tags)Retrieves a meter as a JSON object.
The requested meter is located and parsed as a JsonObject to be sent via HTTP.- Parameters:
name- name of the meter we want to retrievetags- tags the meter has- Returns:
- the JSON object representing the meter
- Throws:
java.lang.IllegalArgumentException- if no meter is found with that name
-
toJson
public java.lang.String toJson(java.lang.String identifier, boolean update, io.micrometer.core.instrument.config.MeterFilter... filter)Returns the full provider in Json.- Parameters:
identifier- optional identifier to be added to the structure, no identifier is added if nullupdate- is this an update or an initial serialization to Jsonfilter- optional filters on the meters to be exported- Returns:
- all meters and their values/structures, all lists
-
filter
public static java.util.List<io.micrometer.core.instrument.Meter> filter(java.util.List<io.micrometer.core.instrument.Meter> meters, boolean copy, io.micrometer.core.instrument.config.MeterFilter... filters)Filters the given meters according to the specified filters.- Parameters:
meters- the meters to be filteredcopy- copy themetersif filters are to be applied or iffalsemodify meters directlyfilters- the filters to be applied. The first matching filter returningMeterFilterReply.DENYwill remove a metric from the result list, anMeterFilterReply.NEUTRALwill keep it as long as there is noMeterFilterReply.DENYfilter until the end of the filter list andMeterFilterReply.ACCEPTwill immediately accept the actual meter.- Returns:
- the filtered metrics list
-
include
public static boolean include(io.micrometer.core.instrument.Meter.Id id, io.micrometer.core.instrument.config.MeterFilter... filters)Returns whether a meter id shall be included into a result set.- Parameters:
id- the meter idfilters- the filters to be applied. The first matching filter returningMeterFilterReply.DENYwill remove a metric from the result list, anMeterFilterReply.NEUTRALwill keep it as long as there is noMeterFilterReply.DENYfilter until the end of the filter list andMeterFilterReply.ACCEPTwill immediately accept the actual meter.- Returns:
truefor apply,falseelse
-
include
public static boolean include(java.lang.String id, io.micrometer.core.instrument.config.MeterFilter... filters)Returns whether a meter id shall be included into a result set.- Parameters:
id- the meter idfilters- the filters to be applied. The first matching filter returningMeterFilterReply.DENYwill remove a metric from the result list, anMeterFilterReply.NEUTRALwill keep it as long as there is noMeterFilterReply.DENYfilter until the end of the filter list andMeterFilterReply.ACCEPTwill immediately accept the actual meter.- Returns:
truefor apply,falseelse
-
append
public static io.micrometer.core.instrument.config.MeterFilter[] append(io.micrometer.core.instrument.config.MeterFilter[] base, io.micrometer.core.instrument.config.MeterFilter... addition)Appendsadditiontobase.- Parameters:
base- the base filtersaddition- the addition filters- Returns:
- the combined filter array
-
apply
public static void apply(io.micrometer.core.instrument.MeterRegistry registry, io.micrometer.core.instrument.config.MeterFilter... filters)Applies the given list of meter filters.- Parameters:
registry- the registry to apply the filters tofilters- the filters to apply
-
getGauge
public java.lang.String getGauge(java.lang.String name)
Retrieves a custom gauge as a JSON object.
The requested gauge is located within the map and parsed as a JsonObject to be sent via HTTP.- Parameters:
name- name of the custom gauge we want to retrieve- Returns:
- the JSON object representing the gauge
- Throws:
java.lang.IllegalArgumentException- if no custom gauge is found with that name
-
getCounter
public java.lang.String getCounter(java.lang.String name)
Retrieves a custom counter as a JSON object.
The requested counter is located within the map and parsed as a JsonObject to be sent via HTTP.- Parameters:
name- name of the custom counter we want to retrieve- Returns:
- the JSON object representing the counter
- Throws:
java.lang.IllegalArgumentException- if no custom counter is found with that name
-
getTimer
public java.lang.String getTimer(java.lang.String name)
Retrieves a custom timer as a JSON object.
The requested timer is located within the map and parsed as a JsonObject to be sent via HTTP.- Parameters:
name- name of the custom timer we want to retrieve- Returns:
- the JSON object representing the timer
- Throws:
java.lang.IllegalArgumentException- if no custom timer is found with that name
-
jsonParser
private java.lang.String jsonParser(io.micrometer.core.instrument.Meter meter)
Parses a meter into a JsonObject to be sent via HTTP.
Due to the current limitations with inserting the actualJsonlibraries inside this component, this method acts like a crude substitute that creates a String that can later be parsed into a valid JsonObject.
In order to maintain a certain uniformity, the resulting JSON object mimics the structure that Micrometer-API metrics have when exposed by the Spring Boot Actuator.
It is important to add that if the description contains any"characters, they will be exchanged for''due to the limitations we currently have regarding JSON parsing.- Parameters:
meter- meter we want to parse- Returns:
- meter parsed as a String compatible with a JsonObject
-
getCustomGaugeList
public java.lang.String getCustomGaugeList()
Returns a list of the names of the registered custom gauges.
The list is returned as a JsonArray containing Strings.- Returns:
- JsonArray with the list of names of all the registered custom gauges
-
getCustomCounterList
public java.lang.String getCustomCounterList()
Returns a list of the names of the registered custom counters.
The list is returned as a JsonArray containing Strings.- Returns:
- JsonArray with the list of names of all the registered custom counters
-
getCustomTimerList
public java.lang.String getCustomTimerList()
Returns a list of the names of the registered custom timers.
The list is returned as a JsonArray containing Strings.- Returns:
- JsonArray with the list of names of all the registered custom timers
-
getTaggedMeterList
public java.lang.String getTaggedMeterList()
Returns a list of names of the relevant Meters registered by micrometer that have tags.- Returns:
- JsonArray with the list of names of the relevant micrometer-registered meters with tags
-
getSimpleMeterList
public java.lang.String getSimpleMeterList()
Returns a list of names of the relevant Meters registered by micrometer that have no tags.- Returns:
- JsonArray with the list of names of the relevant micrometer-registered meters with no tags
-
mapJsonParser
private java.lang.String mapJsonParser(java.util.Map<java.lang.String,?> map)
Parses one of the custom meter maps into a JsonArray containing the names.
This method is to be used bygetCustomCounterList(),getCustomGaugeList()and @link MetricsProvider#getCustomTimerList()}.- Parameters:
map- custom meter map- Returns:
- JsonArray of the names of the custom meters from that map
-
createServiceReceivedCounter
public io.micrometer.core.instrument.Counter createServiceReceivedCounter(java.lang.String serviceName, java.lang.String serviceId, java.lang.String appId, java.lang.String appInstanceId)Creates and registers a default service received counter. The device id tag will be set fromId.getDeviceId().- 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, as validated byServiceBase.validateApplicationInstanceId(String)- Returns:
- the registered counter instance
- See Also:
createServiceSentReceivedCounter(boolean, String, String, String, String)
-
createServiceSentCounter
public io.micrometer.core.instrument.Counter createServiceSentCounter(java.lang.String serviceName, java.lang.String serviceId, java.lang.String appId, java.lang.String appInstanceId)Creates and registers a default service sent counter. The device id tag will be set fromId.getDeviceId().- 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, as validated byServiceBase.validateApplicationInstanceId(String)- Returns:
- the registered counter instance
- See Also:
createServiceSentReceivedCounter(boolean, String, String, String, String)
-
createServiceSentReceivedCounter
public io.micrometer.core.instrument.Counter createServiceSentReceivedCounter(boolean receive, java.lang.String serviceName, java.lang.String serviceId, java.lang.String appId, java.lang.String appInstanceId)Creates and registers a default service send/receive counter. The device id tag will be set fromId.getDeviceId().- 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, as validated byServiceBase.validateApplicationInstanceId(String)- Returns:
- the registered counter instance
-
createServiceProcessingTimer
public io.micrometer.core.instrument.Timer createServiceProcessingTimer(java.lang.String serviceName, java.lang.String serviceId, java.lang.String appId, java.lang.String appInstanceId)Creates and registers a default service processing timer. The device id tag will be set fromId.getDeviceId().- 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, as validated byServiceBase.validateApplicationInstanceId(String)- Returns:
- the registered counter instance
-
-