Class MetricsProvider


  • public class MetricsProvider
    extends java.lang.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  MetricsProvider.TimeSupplier
      Supplies access to a time measurement.
    • 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 void addCounter​(java.lang.String counterId)
      Creates a new counter and registers it in the MeterRegistry.
      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.
      void addService​(UpdatingMonitoringService service)
      Adds a service to be updated regularly regarding its monitoring data.
      protected void addTimer​(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)
      Appends addition to base.
      static void apply​(io.micrometer.core.instrument.MeterRegistry registry, io.micrometer.core.instrument.config.MeterFilter... filters)
      Applies the given list of meter filters.
      void calculateMetrics()
      Call this method to update the metrics.
      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.
      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.
      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.
      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.
      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.
      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.Clock getClock()
      Returns the clock used in the underlying meter registry.
      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.
      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.
      java.lang.String getCustomCounterList()
      Returns a list of the names of the registered custom counters.
      The list is returned as a JsonArray containing Strings.
      java.lang.String getCustomGaugeList()
      Returns a list of the names of the registered custom gauges.
      The list is returned as a JsonArray containing Strings.
      java.lang.String getCustomTimerList()
      Returns a list of the names of the registered custom timers.
      The list is returned as a JsonArray containing Strings.
      CapacityBaseUnit getDiskBaseUnit()
      Consults the capacity base unit used for the disk capacity metrics.
      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.
      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
      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.
      CapacityBaseUnit getMemoryBaseUnit()
      Consults the capacity base unit used for the physical memory metrics.
      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.
      int getNumberOfCustomCounters()
      Consult the number of custom counters that are registered by the MetricsProvider.
      int getNumberOfCustomGauges()
      Consult the number of custom gauges that are registered by the MetricsProvider.
      int getNumberOfCustomTimers()
      Consult the number of custom timers that are registered by the MetricsProvider.
      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.
      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.
      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.
      io.micrometer.core.instrument.MeterRegistry getRegistry()
      Returns the meter registry.
      java.lang.String getSimpleMeterList()
      Returns a list of names of the relevant Meters registered by micrometer that have no tags.
      java.lang.String getTaggedMeterList()
      Returns a list of names of the relevant Meters registered by micrometer that have tags.
      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.
      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.
      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.
      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.
      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.
      void increaseCounter​(java.lang.String counterId)
      Increases the counter by one.
      static void increaseCounterBy​(io.micrometer.core.instrument.Counter counter, double value)
      Helper method to increase/increment the given counter by the specified value.
      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.
      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 actual 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 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 by getCustomCounterList(), getCustomGaugeList() and @link MetricsProvider#getCustomTimerList()}.
      static void recordMsTime​(io.micrometer.core.instrument.Timer timer, MetricsProvider.TimeSupplier timeSupplier, java.lang.Runnable function)
      Record milliseconds time.
      void recordWithTimer​(java.lang.String timerId, long time, java.util.concurrent.TimeUnit unit)
      Adds time from a specific timer.
      void recordWithTimer​(java.lang.String timerId, java.lang.Runnable runnable)
      Records the execution of a runnable using a timer.
      <T> T recordWithTimer​(java.lang.String timerId, java.util.function.Supplier<T> supplier)
      Records the execution of a supplier using a timer.
      void registerDeviceMetrics()
      Registers the default device metrics.
      It can be called multiple times during execution in order to update the base units.
      void registerDiskMetrics()
      Registers the disk capacity metrics.
      It can be called multiple times during execution in order to update the disk capacity base unit.
      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.
      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.
      void removeCounter​(java.lang.String counterId)
      Remove a custom counter from the Meter Registry.
      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.
      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.
      void removeGauge​(java.lang.String gaugeId)
      Remove a custom gauge from the Meter Registry.
      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.
      void removeTimer​(java.lang.String timerId)
      Remove a custom timer from the Registry.
      void setDiskBaseUnit​(CapacityBaseUnit diskBaseUnit)
      Changes the disk capacity base unit.
      void setMemoryBaseUnit​(CapacityBaseUnit memoryBaseUnit)
      Changes the memory base unit.
      java.lang.String toJson​(java.lang.String identifier, boolean update, io.micrometer.core.instrument.config.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 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
      • 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
      • 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
      • 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
      • 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; requires calculateNonNativeSystemMetrics() 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 Application
        monitorNonNative - enable/disable monitoring of (default IIP-Ecosphere) non-native system metrics, requires calculateNonNativeSystemMetrics() 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 gauge
        value - 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.0 if 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.0 if 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 counter
        value - the amount we want to increases the counter
        Throws:
        java.lang.IllegalArgumentException - if value is negative or if counterId is null
      • increaseCounterBy

        public static void increaseCounterBy​(io.micrometer.core.instrument.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​(io.micrometer.core.instrument.Timer timer,
                                        MetricsProvider.TimeSupplier timeSupplier,
                                        java.lang.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
      • 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 - if value is negative or if counterId is 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.0 if 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.0 if 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 timer
        runnable - 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 timer
        supplier - 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 timer
        time - amount of time we want to record
        unit - base unit of the time we want to record
        Throws:
        java.lang.IllegalArgumentException - if the identifier or the supplier are null
        java.lang.IllegalArgumentException - if the time is 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.0 if 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.0 if 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 0 if 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 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:
        java.lang.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:
        java.lang.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 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 retrieve
        tags - 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 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 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 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 MeterFilterReply.DENY will remove a metric from the result list, an MeterFilterReply.NEUTRAL will keep it as long as there is no MeterFilterReply.DENY filter until the end of the filter list and MeterFilterReply.ACCEPT will 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 id
        filters - the filters to be applied. The first matching filter returning MeterFilterReply.DENY will remove a metric from the result list, an MeterFilterReply.NEUTRAL will keep it as long as there is no MeterFilterReply.DENY filter until the end of the filter list and MeterFilterReply.ACCEPT will immediately accept the actual meter.
        Returns:
        true for apply, false else
      • 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 id
        filters - the filters to be applied. The first matching filter returning MeterFilterReply.DENY will remove a metric from the result list, an MeterFilterReply.NEUTRAL will keep it as long as there is no MeterFilterReply.DENY filter until the end of the filter list and MeterFilterReply.ACCEPT will immediately accept the actual meter.
        Returns:
        true for apply, false else
      • append

        public static io.micrometer.core.instrument.config.MeterFilter[] append​(io.micrometer.core.instrument.config.MeterFilter[] base,
                                                                                io.micrometer.core.instrument.config.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​(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 to
        filters - 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 actual 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 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 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 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 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(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 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(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 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 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 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