Class MetricsProvider
java.lang.Object
de.iip_ecosphere.platform.services.environment.metricsProvider.MetricsProvider
This class represents an interface to manage the Micrometer-API meters.
The operations available in this class are:
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.
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 ClassesModifier and TypeClassDescriptionstatic interfaceSupplies access to a time measurement. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate de.iip_ecosphere.platform.support.metrics.Clockstatic final de.iip_ecosphere.platform.support.metrics.MeterFilter[]static final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringprivate floatprivate floatstatic final CapacityBaseUnitstatic final CapacityBaseUnitprivate CapacityBaseUnitstatic final List<de.iip_ecosphere.platform.support.metrics.Tag> protected static final Stringprivate booleanprivate CapacityBaseUnitprivate booleanprotected static final Stringprotected static final Stringprivate final OperatingSystemMXBeanprivate de.iip_ecosphere.platform.support.metrics.MeterRegistrystatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringprivate doubleprivate doubleprivate doubleprivate doubleprivate doubleprivate doubleprivate doubleprivate doublestatic final MetricsAasConstructor.PushMeterPredicateTag matching predicate.static final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringprivate List<UpdatingMonitoringService> -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new Metrics Provider Instance with default registry.MetricsProvider(de.iip_ecosphere.platform.support.metrics.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(de.iip_ecosphere.platform.support.metrics.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
Modifier and TypeMethodDescriptionprivate voidaddCounter(String counterId) Creates a new counter and registers it in the MeterRegistry.voidaddGaugeValue(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 voidCreate a new custom timer to be added to the Meter registry.static de.iip_ecosphere.platform.support.metrics.MeterFilter[]append(de.iip_ecosphere.platform.support.metrics.MeterFilter[] base, de.iip_ecosphere.platform.support.metrics.MeterFilter... addition) Appendsadditiontobase.static voidapply(de.iip_ecosphere.platform.support.metrics.MeterRegistry registry, de.iip_ecosphere.platform.support.metrics.MeterFilter... filters) Applies the given list of meter filters.voidCall this method to update the metrics.voidThis 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.de.iip_ecosphere.platform.support.metrics.TimercreateServiceProcessingTimer(String serviceName, String serviceId, String appId, String appInstanceId) Creates and registers a default service processing timer.de.iip_ecosphere.platform.support.metrics.CountercreateServiceReceivedCounter(String serviceName, String serviceId, String appId, String appInstanceId) Creates and registers a default service received counter.de.iip_ecosphere.platform.support.metrics.CountercreateServiceSentCounter(String serviceName, String serviceId, String appId, String appInstanceId) Creates and registers a default service sent counter.de.iip_ecosphere.platform.support.metrics.CountercreateServiceSentReceivedCounter(boolean receive, String serviceName, String serviceId, String appId, String appInstanceId) Creates and registers a default service send/receive counter.static List<de.iip_ecosphere.platform.support.metrics.Meter> filter(List<de.iip_ecosphere.platform.support.metrics.Meter> meters, boolean copy, de.iip_ecosphere.platform.support.metrics.MeterFilter... filters) Filters the given meters according to the specified filters.de.iip_ecosphere.platform.support.metrics.ClockgetClock()Returns the clock used in the underlying meter registry.getCounter(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(String counterId) Retrieves the value of a custom Counter.
If no counter is found with that identifier, this method will return zero.Returns a list of the names of the registered custom counters.
The list is returned as a JsonArray containing Strings.Returns a list of the names of the registered custom gauges.
The list is returned as a JsonArray containing Strings.Returns a list of the names of the registered custom timers.
The list is returned as a JsonArray containing Strings.Consults the capacity base unit used for the disk capacity metrics.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(String gaugeId) Retrieves the value of a custom Gauge.
If no gauge is found with that identifier, this method will return zerodoublegetMaxTimeFromTimer(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.Consults the capacity base unit used for the physical memory metrics.Retrieves a meter as a JSON object.
The requested meter is located and parsed as a JsonObject to be sent via HTTP.intConsult the number of custom counters that are registered by the MetricsProvider.intConsult the number of custom gauges that are registered by the MetricsProvider.intConsult the number of custom timers that are registered by the MetricsProvider.doublegetRegisteredCounterValue(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(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(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.de.iip_ecosphere.platform.support.metrics.MeterRegistryReturns the meter registry.Returns a list of names of the relevant Meters registered by micrometer that have no tags.Returns a list of names of the relevant Meters registered by micrometer that have tags.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(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(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(de.iip_ecosphere.platform.support.metrics.Meter.Id id, de.iip_ecosphere.platform.support.metrics.MeterFilter... filters) Returns whether a meter id shall be included into a result set.static booleanReturns whether a meter id shall be included into a result set.voidincreaseCounter(String counterId) Increases the counter by one.static voidincreaseCounterBy(de.iip_ecosphere.platform.support.metrics.Counter counter, double value) Helper method to increase/increment the givencounterby the specifiedvalue.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.private StringjsonParser(de.iip_ecosphere.platform.support.metrics.Meter meter) Parses a meter into a JsonObject to be sent via HTTP.
Due to the current limitations with the Json libraries 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 StringmapJsonParser(Map<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(de.iip_ecosphere.platform.support.metrics.Timer timer, MetricsProvider.TimeSupplier timeSupplier, Runnable function) Record milliseconds time.static voidrecordNsTime(de.iip_ecosphere.platform.support.metrics.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.voidRegisters the default device metrics.
It can be called multiple times during execution in order to update the base units.voidRegisters the disk capacity metrics.
It can be called multiple times during execution in order to update the disk capacity base unit.voidRegisters 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.voidRegisters 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(String counterId) Remove a custom counter from the Meter Registry.voidRemoves 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.voidRemoves 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(String gaugeId) Remove a custom gauge from the Meter Registry.voidRemoves 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(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.toJson(String identifier, boolean update, de.iip_ecosphere.platform.support.metrics.MeterFilter... filter) Returns the full provider in Json.
-
Field Details
-
TAG_PREDICATE
Tag matching predicate. Pre-matched deviceIds assumed. -
EMPTY_TAGS
-
DEFAULT_METER_FILTERS
public static final de.iip_ecosphere.platform.support.metrics.MeterFilter[] DEFAULT_METER_FILTERS -
TAG_SERVICE_SERVICE
- See Also:
-
TAG_SERVICE_APPLICATION
- See Also:
-
TAG_SERVICE_DEVICE
- See Also:
-
TAG_SERVICE_SERVICEID
- See Also:
-
TAG_SERVICE_APPINSTID
- See Also:
-
SYS_MEM_TOTAL
- See Also:
-
SYS_MEM_FREE
- See Also:
-
SYS_MEM_USED
- See Also:
-
SYS_MEM_USAGE
- See Also:
-
SYS_DISK_TOTAL
- See Also:
-
SYS_DISK_FREE
- See Also:
-
SYS_DISK_USABLE
- See Also:
-
SYS_DISK_USED
- See Also:
-
DEVICE_CPU_TEMPERATURE
- See Also:
-
DEVICE_CASE_TEMPERATURE
- See Also:
-
DEVICE_TPU_CORES
- See Also:
-
DEVICE_GPU_CORES
- See Also:
-
DEVICE_CPU_CORES
- See Also:
-
SERVICE_TUPLES_SENT
- See Also:
-
SERVICE_TUPLES_RECEIVED
- See Also:
-
SERVICE_TIME_PROCESSED
- See Also:
-
DFLT_MEMORY
-
DFLT_DISK
-
ID_NOT_FOUND_ERRMSG
- See Also:
-
NON_POSITIVE_ERRMSG
- See Also:
-
NULL_ARG
- See Also:
-
registry
private de.iip_ecosphere.platform.support.metrics.MeterRegistry registry -
osmxb
-
init
private boolean init -
clock
private de.iip_ecosphere.platform.support.metrics.Clock clock -
updaters
-
memoryBaseUnit
-
diskBaseUnit
-
gauges
-
counters
-
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 Details
-
MetricsProvider
public MetricsProvider()Create a new Metrics Provider Instance with default registry.- Throws:
IllegalArgumentException- if the registry is null- See Also:
-
MetricsProvider
public MetricsProvider(de.iip_ecosphere.platform.support.metrics.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:
IllegalArgumentException- if the registry is null- See Also:
-
MetricsProvider
public MetricsProvider(de.iip_ecosphere.platform.support.metrics.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:
IllegalArgumentException- if the registry is null
-
-
Method Details
-
getRegistry
public de.iip_ecosphere.platform.support.metrics.MeterRegistry getRegistry()Returns the meter registry.- Returns:
- the meter registry
-
getClock
public de.iip_ecosphere.platform.support.metrics.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
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
-
getGaugeValue
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
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
Creates a new counter and registers it in the MeterRegistry.- Parameters:
counterId- identifier of the counter
-
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
-
increaseCounterBy
public static void increaseCounterBy(de.iip_ecosphere.platform.support.metrics.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(de.iip_ecosphere.platform.support.metrics.Timer timer, MetricsProvider.TimeSupplier timeSupplier, 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
-
recordNsTime
public static void recordNsTime(de.iip_ecosphere.platform.support.metrics.Timer timer, MetricsProvider.TimeSupplier timeSupplier, Runnable function) Record nanoseconds time.- Parameters:
timer- the timer to record the time ontimeSupplier- the time supplier returning the time after executingfunctionfunction- the function to execute
-
increaseCounter
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:
IllegalArgumentException- ifvalueis negative or ifcounterIdis null
-
removeCounter
Remove a custom counter from the Meter Registry.- Parameters:
counterId- identifier of the custom counter- Throws:
IllegalArgumentException- if there is no counter with that identifier
-
getCounterValue
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
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
Create a new custom timer to be added to the Meter registry.- Parameters:
timerId- identifier of the custom timer- Throws:
IllegalArgumentException- if the identifier is null
-
removeTimer
Remove a custom timer from the Registry.- Parameters:
timerId- identifier of the custom timer- Throws:
IllegalArgumentException- if there is no timer with that identifier
-
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
-
getTotalTimeFromTimer
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
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
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
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
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
Changes the memory base unit.- Parameters:
memoryBaseUnit- new capacity base unit for the memory- Throws:
IllegalArgumentException- if thememoryBaseUnitis null
-
getMemoryBaseUnit
Consults the capacity base unit used for the physical memory metrics.- Returns:
- capacity base unit for the memory metrics
-
setDiskBaseUnit
Changes the disk capacity base unit.- Parameters:
diskBaseUnit- new capacity base unit for the disk capacity- Throws:
IllegalArgumentException- if thememoryBaseUnitis null
-
getDiskBaseUnit
Consults the capacity base unit used for the disk capacity metrics.- Returns:
- capacity base unit for the disk capacity metrics
-
getMeter
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:
IllegalArgumentException- if no meter is found with that name
-
toJson
public String toJson(String identifier, boolean update, de.iip_ecosphere.platform.support.metrics.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 List<de.iip_ecosphere.platform.support.metrics.Meter> filter(List<de.iip_ecosphere.platform.support.metrics.Meter> meters, boolean copy, de.iip_ecosphere.platform.support.metrics.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 returningMeterFilter.MeterFilterReply.DENYwill remove a metric from the result list, anMeterFilter.MeterFilterReply.NEUTRALwill keep it as long as there is noMeterFilter.MeterFilterReply.DENYfilter until the end of the filter list andMeterFilter.MeterFilterReply.ACCEPTwill immediately accept the actual meter.- Returns:
- the filtered metrics list
-
include
public static boolean include(de.iip_ecosphere.platform.support.metrics.Meter.Id id, de.iip_ecosphere.platform.support.metrics.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 returningMeterFilter.MeterFilterReply.DENYwill remove a metric from the result list, anMeterFilter.MeterFilterReply.NEUTRALwill keep it as long as there is noMeterFilter.MeterFilterReply.DENYfilter until the end of the filter list andMeterFilter.MeterFilterReply.ACCEPTwill immediately accept the actual meter.- Returns:
truefor apply,falseelse
-
include
public static boolean include(String id, de.iip_ecosphere.platform.support.metrics.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 returningMeterFilter.MeterFilterReply.DENYwill remove a metric from the result list, anMeterFilter.MeterFilterReply.NEUTRALwill keep it as long as there is noMeterFilter.MeterFilterReply.DENYfilter until the end of the filter list andMeterFilter.MeterFilterReply.ACCEPTwill immediately accept the actual meter.- Returns:
truefor apply,falseelse
-
append
public static de.iip_ecosphere.platform.support.metrics.MeterFilter[] append(de.iip_ecosphere.platform.support.metrics.MeterFilter[] base, de.iip_ecosphere.platform.support.metrics.MeterFilter... addition) Appendsadditiontobase.- Parameters:
base- the base filtersaddition- the addition filters- Returns:
- the combined filter array
-
apply
public static void apply(de.iip_ecosphere.platform.support.metrics.MeterRegistry registry, de.iip_ecosphere.platform.support.metrics.MeterFilter... filters) Applies the given list of meter filters.- Parameters:
registry- the registry to apply the filters tofilters- the filters to apply
-
getGauge
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:
IllegalArgumentException- if no custom gauge is found with that name
-
getCounter
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:
IllegalArgumentException- if no custom counter is found with that name
-
getTimer
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:
IllegalArgumentException- if no custom timer is found with that name
-
jsonParser
Parses a meter into a JsonObject to be sent via HTTP.
Due to the current limitations with the Json libraries 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
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
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
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
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
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
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 de.iip_ecosphere.platform.support.metrics.Counter createServiceReceivedCounter(String serviceName, String serviceId, String appId, 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:
-
createServiceSentCounter
public de.iip_ecosphere.platform.support.metrics.Counter createServiceSentCounter(String serviceName, String serviceId, String appId, 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
public de.iip_ecosphere.platform.support.metrics.Counter createServiceSentReceivedCounter(boolean receive, String serviceName, String serviceId, String appId, 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 de.iip_ecosphere.platform.support.metrics.Timer createServiceProcessingTimer(String serviceName, String serviceId, String appId, 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
-