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

@Component @ConfigurationProperties(prefix="metricsprovider") public class MetricsProvider extends de.iip_ecosphere.platform.services.environment.metricsProvider.MetricsProvider
This class represents an interface to manage the Micrometer-API meters.
An instance of this class is auto-wired into the Stream Application and will act as a metrics provider for the service application.
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.
All meters will be accessible via HTTP requests through the endpoint provided by the Spring Boot Application by adding the resource names as final part of the URI. If the requested metric has tags, they are passed as query parameters: http://192.168.1.111:8080/actuator/metrics/my.metric?tag=tagKey:tagValue&tag=anotherTagKey:anotherTagValue
There are a few properties that can be modified using the application.yml file. These properties are:
  • schedulerrate: the rate at which the system metrics are gathered to reduce gauge calculation overload
  • memorybaseunit: the base unit we want to use for the physical memory metrics
  • diskbaseunit: the base unit we want to use for the disk capacity metrics
It is important to note that all previously configurable properties have a default value, so there is no need obligation to set them in the file and that the names given to the base units must correspond a valid value from CapacityBaseUnit.values(). In order to comply with flexibility and YAML, the names are not case sensitive and will correctly parse to their equivalent values independently of upper or lower case letters.
Author:
Miguel Gomez
  • Nested Class Summary

    Nested classes/interfaces inherited from class de.iip_ecosphere.platform.services.environment.metricsProvider.MetricsProvider

    de.iip_ecosphere.platform.services.environment.metricsProvider.MetricsProvider.TimeSupplier
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private de.iip_ecosphere.platform.transport.connectors.TransportConnector
     
    private boolean
     
    private String
     
    private String
     
    private static final String
     
    private de.iip_ecosphere.platform.transport.connectors.TransportSetup
     
    private boolean
     

    Fields inherited from class de.iip_ecosphere.platform.services.environment.metricsProvider.MetricsProvider

    DEFAULT_METER_FILTERS, DEVICE_CASE_TEMPERATURE, DEVICE_CPU_CORES, DEVICE_CPU_TEMPERATURE, DEVICE_GPU_CORES, DEVICE_TPU_CORES, DFLT_DISK, DFLT_MEMORY, EMPTY_TAGS, ID_NOT_FOUND_ERRMSG, NON_POSITIVE_ERRMSG, NULL_ARG, SERVICE_TIME_PROCESSED, SERVICE_TUPLES_RECEIVED, SERVICE_TUPLES_SENT, SYS_DISK_FREE, SYS_DISK_TOTAL, SYS_DISK_USABLE, SYS_DISK_USED, SYS_MEM_FREE, SYS_MEM_TOTAL, SYS_MEM_USAGE, SYS_MEM_USED, TAG_PREDICATE, TAG_SERVICE_APPINSTID, TAG_SERVICE_APPLICATION, TAG_SERVICE_DEVICE, TAG_SERVICE_SERVICE, TAG_SERVICE_SERVICEID
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
     
    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.
    protected
    MetricsProvider(de.iip_ecosphere.platform.support.metrics.MeterRegistry registry)
    Create a new Metrics Provider Instance.
     
    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.
  • Method Summary

    Modifier and Type
    Method
    Description
    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.
    void
    Clean up at shutdown.
    of(de.iip_ecosphere.platform.support.metrics.MeterRegistry registry)
    Create a new Metrics Provider Instance.
    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
    setInjectedValues(de.iip_ecosphere.platform.transport.connectors.TransportSetup transport)
    Sets the basic values that are usually injected.

    Methods inherited from class de.iip_ecosphere.platform.services.environment.metricsProvider.MetricsProvider

    addGaugeValue, addService, addTimer, append, apply, calculateNonNativeSystemMetrics, createServiceProcessingTimer, createServiceReceivedCounter, createServiceSentCounter, createServiceSentReceivedCounter, filter, getClock, getCounter, getCounterValue, getCustomCounterList, getCustomGaugeList, getCustomTimerList, getDiskBaseUnit, getGauge, getGaugeValue, getMaxTimeFromTimer, getMemoryBaseUnit, getMeter, getNumberOfCustomCounters, getNumberOfCustomGauges, getNumberOfCustomTimers, getRegisteredCounterValue, getRegisteredGaugeValue, getRegisteredTimerCount, getRegistry, getSimpleMeterList, getTaggedMeterList, getTimer, getTimerCount, getTotalTimeFromTimer, include, include, increaseCounter, increaseCounterBy, increaseCounterBy, recordMsTime, recordNsTime, recordWithTimer, recordWithTimer, recordWithTimer, registerDeviceMetrics, registerDiskMetrics, registerMemoryMetrics, removeCounter, removeDeviceMetrics, removeDiskMetrics, removeGauge, removeMemoryMetrics, removeTimer, setDiskBaseUnit, setMemoryBaseUnit, toJson

    Methods inherited from class java.lang.Object

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

    • SCHEDULE_RATE

      private static final String SCHEDULE_RATE
      See Also:
    • memoryBaseUnitString

      @Value("${metricsprovider.memorybaseunit:bytes}") private String memoryBaseUnitString
    • diskBaseUnitString

      @Value("${metricsprovider.diskbaseunit:kilobytes}") private String diskBaseUnitString
    • update

      private boolean update
    • connector

      private de.iip_ecosphere.platform.transport.connectors.TransportConnector connector
    • connectorFailed

      private boolean connectorFailed
    • transport

      @Autowired private de.iip_ecosphere.platform.transport.connectors.TransportSetup transport
  • Constructor Details

    • MetricsProvider

      public MetricsProvider()
      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 should be called automatically by the Spring boot framework as fallback if no MeterRegistry is available.
      Throws:
      IllegalArgumentException - if the registry is null
    • MetricsProvider

      @Autowired 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 should be called automatically by the Spring boot framework and accessed by an autowired attribute as a result.
      Parameters:
      registry - where new Meters are registered. Injected by the Spring Boot Application
      Throws:
      IllegalArgumentException - if the registry is null
    • MetricsProvider

      protected MetricsProvider(de.iip_ecosphere.platform.support.metrics.MeterRegistry registry)
      Create a new Metrics Provider Instance. Avoid interference with autowiring.
      Parameters:
      registry - where new Meters are registered. Injected by the Spring Boot Application
      Throws:
      IllegalArgumentException - if the registry is null
  • Method Details

    • of

      public static MetricsProvider of(de.iip_ecosphere.platform.support.metrics.MeterRegistry registry)
      Create a new Metrics Provider Instance.
      Parameters:
      registry - where new Meters are registered. Injected by the Spring Boot Application
      Throws:
      IllegalArgumentException - if the registry is null
    • setInjectedValues

      public void setInjectedValues(de.iip_ecosphere.platform.transport.connectors.TransportSetup transport)
      Sets the basic values that are usually injected. [testing outside Spring]
      Parameters:
      transport - the transport instance
    • 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.
      Overrides:
      registerNonNativeSystemMetrics in class de.iip_ecosphere.platform.services.environment.metricsProvider.MetricsProvider
    • calculateMetrics

      @Scheduled(fixedRateString="${metricsprovider.schedulerrate:5000}") public void calculateMetrics()
      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. [public for testing outside spring]
      Overrides:
      calculateMetrics in class de.iip_ecosphere.platform.services.environment.metricsProvider.MetricsProvider
    • destroy

      @PreDestroy public void destroy()
      Clean up at shutdown.