java.lang.Object
de.iip_ecosphere.platform.services.environment.metricsProvider.MetricsProvider

public class MetricsProvider extends Object
This 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 recommended to use the dot notation to name the meters, i.e. my.custom.meter, as it is the one used by default by the already existing metrics exposed by Micrometer
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 interface 
    Supplies access to a time measurement.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private de.iip_ecosphere.platform.support.metrics.Clock
     
    private final Map<String,de.iip_ecosphere.platform.support.metrics.Counter>
     
    static final de.iip_ecosphere.platform.support.metrics.MeterFilter[]
     
    static final String
     
    static final String
     
    static final String
     
    static final String
     
    static final String
     
    private float
     
    private float
     
    static final CapacityBaseUnit
     
    static final CapacityBaseUnit
     
     
    static final List<de.iip_ecosphere.platform.support.metrics.Tag>
     
    private final Map<String,de.iip_ecosphere.platform.support.AtomicDouble>
     
    protected static final String
     
    private boolean
     
     
    private boolean
     
    protected static final String
     
    protected static final String
     
    private final OperatingSystemMXBean
     
    private de.iip_ecosphere.platform.support.metrics.MeterRegistry
     
    static final String
     
    static final String
     
    static final String
     
    static final String
     
    static final String
     
    static final String
     
    static final String
     
    static final String
     
    static final String
     
    static final String
     
    static final String
     
    private double
     
    private double
     
    private double
     
    private double
     
    private double
     
    private double
     
    private double
     
    private double
     
    Tag matching predicate.
    static final String
     
    static final String
     
    static final String
     
    static final String
     
    static final String
     
    private final Map<String,de.iip_ecosphere.platform.support.metrics.Timer>
     
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create 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 Type
    Method
    Description
    private void
    addCounter(String counterId)
    Creates a new counter and registers it in the MeterRegistry.
    void
    addGaugeValue(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.
    void
    Adds a service to be updated regularly regarding its monitoring data.
    protected void
    addTimer(String timerId)
    Create 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)
    Appends addition to base.
    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.
    void
    Call this method to update the metrics.
    void
    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.
    de.iip_ecosphere.platform.support.metrics.Timer
    createServiceProcessingTimer(String serviceName, String serviceId, String appId, String appInstanceId)
    Creates and registers a default service processing timer.
    de.iip_ecosphere.platform.support.metrics.Counter
    createServiceReceivedCounter(String serviceName, String serviceId, String appId, String appInstanceId)
    Creates and registers a default service received counter.
    de.iip_ecosphere.platform.support.metrics.Counter
    createServiceSentCounter(String serviceName, String serviceId, String appId, String appInstanceId)
    Creates and registers a default service sent counter.
    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.
    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.Clock
    Returns the clock used in the underlying meter registry.
    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.
    double
    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.
    double
    Retrieves the value of a custom Gauge.
    If no gauge is found with that identifier, this method will return zero
    double
    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.
    getMeter(String name, Iterable<de.iip_ecosphere.platform.support.metrics.Tag> tags)
    Retrieves a meter as a JSON object.
    The requested meter is located and parsed as a JsonObject to be sent via HTTP.
    int
    Consult the number of custom counters that are registered by the MetricsProvider.
    int
    Consult the number of custom gauges that are registered by the MetricsProvider.
    int
    Consult the number of custom timers that are registered by the MetricsProvider.
    double
    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.
    double
    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.
    long
    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.MeterRegistry
    Returns 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.
    long
    Retrieves the number of times a timer has been used.
    If no timer is found with that identifier, this method will return zero.
    double
    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 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.
    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.
    void
    Increases the counter by one.
    static void
    increaseCounterBy(de.iip_ecosphere.platform.support.metrics.Counter counter, double value)
    Helper method to increase/increment the given counter by the specified value.
    void
    increaseCounterBy(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 String
    jsonParser(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 String
    Parses one of the custom meter maps into a JsonArray containing the names.
    This method is to be used by getCustomCounterList(), getCustomGaugeList() and @link MetricsProvider#getCustomTimerList()}.
    static void
    recordMsTime(de.iip_ecosphere.platform.support.metrics.Timer timer, MetricsProvider.TimeSupplier timeSupplier, Runnable function)
    Record milliseconds time.
    static void
    recordNsTime(de.iip_ecosphere.platform.support.metrics.Timer timer, MetricsProvider.TimeSupplier timeSupplier, Runnable function)
    Record nanoseconds time.
    void
    recordWithTimer(String timerId, long time, TimeUnit unit)
    Adds time from a specific timer.
    void
    recordWithTimer(String timerId, Runnable runnable)
    Records the execution of a runnable using a timer.
    <T> T
    recordWithTimer(String timerId, Supplier<T> supplier)
    Records the execution of a supplier using a timer.
    void
    Registers the default device metrics.
    It can be called multiple times during execution in order to update the base units.
    void
    Registers the disk capacity metrics.
    It can be called multiple times during execution in order to update the disk capacity base unit.
    void
    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.
    void
    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.
    void
    removeCounter(String counterId)
    Remove a custom counter from the Meter Registry.
    void
    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.
    void
    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.
    void
    Remove a custom gauge from the Meter Registry.
    void
    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.
    void
    Remove a custom timer from the Registry.
    void
    Changes the disk capacity base unit.
    void
    Changes the memory base unit.
    toJson(String identifier, boolean update, de.iip_ecosphere.platform.support.metrics.MeterFilter... filter)
    Returns the full provider in Json.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • 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; requires calculateNonNativeSystemMetrics() 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 Application
      monitorNonNative - enable/disable monitoring of (default IIP-Ecosphere) non-native system metrics, requires calculateNonNativeSystemMetrics() 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

      public void addGaugeValue(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 gauge
      value - value we want to set the gauge to
      Throws:
      IllegalArgumentException - if the identifier is null
    • removeGauge

      public void removeGauge(String gaugeId)
      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

      public double getGaugeValue(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.0 if there is no gauge with the requested identifier
    • getRegisteredGaugeValue

      public double getRegisteredGaugeValue(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.0 if there is no gauge with the requested identifier
    • addCounter

      private void addCounter(String counterId)
      Creates a new counter and registers it in the MeterRegistry.
      Parameters:
      counterId - identifier of the counter
    • increaseCounterBy

      public void increaseCounterBy(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 counter
      value - the amount we want to increases the counter
      Throws:
      IllegalArgumentException - if value is negative or if counterId is null
    • increaseCounterBy

      public static void increaseCounterBy(de.iip_ecosphere.platform.support.metrics.Counter counter, double value)
      Helper method to increase/increment the given counter by the specified value. Does nothing if counter is null.
      Parameters:
      counter - the counter
      value - 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 on
      timeSupplier - the time supplier returning the time after executing function
      function - 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 on
      timeSupplier - the time supplier returning the time after executing function
      function - the function to execute
    • increaseCounter

      public void increaseCounter(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:
      IllegalArgumentException - if value is negative or if counterId is null
    • removeCounter

      public void removeCounter(String counterId)
      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

      public double getCounterValue(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.0 if there is no counter with the requested identifier
    • getRegisteredCounterValue

      public double getRegisteredCounterValue(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.0 if there is no counter with the requested identifier
    • addTimer

      protected void addTimer(String timerId)
      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

      public void removeTimer(String timerId)
      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

      public void recordWithTimer(String timerId, Runnable runnable)
      Records the execution of a runnable using a timer.
      Parameters:
      timerId - identifier of the custom timer
      runnable - runnable function that we want to record
      Throws:
      IllegalArgumentException - if the runnable or the identifier are null
    • recordWithTimer

      public <T> T recordWithTimer(String timerId, 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 timer
      supplier - 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

      public void recordWithTimer(String timerId, long time, TimeUnit unit)
      Adds time from a specific timer.
      Parameters:
      timerId - identifier of the custom timer
      time - amount of time we want to record
      unit - base unit of the time we want to record
      Throws:
      IllegalArgumentException - if the identifier or the supplier are null
      IllegalArgumentException - if the time is negative
    • getTotalTimeFromTimer

      public double getTotalTimeFromTimer(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.0 if no timer is found with that identifier
    • getMaxTimeFromTimer

      public double getMaxTimeFromTimer(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.0 if no timer is found with that identifier
    • getTimerCount

      public long getTimerCount(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 0 if no timer is found with that identifier
    • getRegisteredTimerCount

      public long getRegisteredTimerCount(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 0 if 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. The SCHEDULE_RATE indicates 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:
      IllegalArgumentException - if the memoryBaseUnit is 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:
      IllegalArgumentException - if the memoryBaseUnit is 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 String getMeter(String name, Iterable<de.iip_ecosphere.platform.support.metrics.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 retrieve
      tags - 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 null
      update - is this an update or an initial serialization to Json
      filter - 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 filtered
      copy - copy the meters if filters are to be applied or if false modify meters directly
      filters - the filters to be applied. The first matching filter returning MeterFilter.MeterFilterReply.DENY will remove a metric from the result list, an MeterFilter.MeterFilterReply.NEUTRAL will keep it as long as there is no MeterFilter.MeterFilterReply.DENY filter until the end of the filter list and MeterFilter.MeterFilterReply.ACCEPT will 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 id
      filters - the filters to be applied. The first matching filter returning MeterFilter.MeterFilterReply.DENY will remove a metric from the result list, an MeterFilter.MeterFilterReply.NEUTRAL will keep it as long as there is no MeterFilter.MeterFilterReply.DENY filter until the end of the filter list and MeterFilter.MeterFilterReply.ACCEPT will immediately accept the actual meter.
      Returns:
      true for apply, false else
    • 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 id
      filters - the filters to be applied. The first matching filter returning MeterFilter.MeterFilterReply.DENY will remove a metric from the result list, an MeterFilter.MeterFilterReply.NEUTRAL will keep it as long as there is no MeterFilter.MeterFilterReply.DENY filter until the end of the filter list and MeterFilter.MeterFilterReply.ACCEPT will immediately accept the actual meter.
      Returns:
      true for apply, false else
    • 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)
      Appends addition to base.
      Parameters:
      base - the base filters
      addition - 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 to
      filters - the filters to apply
    • getGauge

      public String getGauge(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:
      IllegalArgumentException - if no custom gauge is found with that name
    • getCounter

      public String 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.
      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

      public String getTimer(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:
      IllegalArgumentException - if no custom timer is found with that name
    • jsonParser

      private String jsonParser(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.
      Parameters:
      meter - meter we want to parse
      Returns:
      meter parsed as a String compatible with a JsonObject
    • getCustomGaugeList

      public 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 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 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 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 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 String mapJsonParser(Map<String,?> map)
      Parses one of the custom meter maps into a JsonArray containing the names.
      This method is to be used by getCustomCounterList(), 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 from Id.getDeviceId().
      Parameters:
      serviceName - the static name/id of the service
      serviceId - the (complete) id of the service
      appId - the id of the application
      appInstanceId - the id of the application instance, as validated by ServiceBase.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 from Id.getDeviceId().
      Parameters:
      serviceName - the static name/id of the service
      serviceId - the (complete) id of the service
      appId - the id of the application
      appInstanceId - the id of the application instance, as validated by ServiceBase.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 from Id.getDeviceId().
      Parameters:
      receive - is it for receiving (true) or sending
      serviceName - the static name/id of the service
      serviceId - the (complete) id of the service
      appId - the id of the application
      appInstanceId - the id of the application instance, as validated by ServiceBase.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 from Id.getDeviceId().
      Parameters:
      serviceName - the static name/id of the service
      serviceId - the (complete) id of the service
      appId - the id of the application
      appInstanceId - the id of the application instance, as validated by ServiceBase.validateApplicationInstanceId(String)
      Returns:
      the registered counter instance