Class MetricsProvider
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:
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:
There are a few properties that can be modified using the application.yml file. These properties are:
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 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:anotherTagValueThere 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
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
FieldsModifier and TypeFieldDescriptionprivate de.iip_ecosphere.platform.transport.connectors.TransportConnectorprivate booleanprivate Stringprivate Stringprivate static final Stringprivate de.iip_ecosphere.platform.transport.connectors.TransportSetupprivate booleanFields 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
ConstructorsModifierConstructorDescriptionCreate 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.protectedMetricsProvider(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 TypeMethodDescriptionvoidThis 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.voiddestroy()Clean up at shutdown.static MetricsProviderof(de.iip_ecosphere.platform.support.metrics.MeterRegistry registry) Create a new Metrics Provider Instance.voidRegisters the extra system metrics onto the registry.
The extra system metrics include the physical memory values and the disk values, which are metrics not automatically recorded by Micrometer-API.voidsetInjectedValues(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
-
Field Details
-
SCHEDULE_RATE
- See Also:
-
memoryBaseUnitString
-
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 noMeterRegistryis 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
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:
registerNonNativeSystemMetricsin classde.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. TheSCHEDULE_RATEindicates the time in between calculations. [public for testing outside spring]- Overrides:
calculateMetricsin classde.iip_ecosphere.platform.services.environment.metricsProvider.MetricsProvider
-
destroy
@PreDestroy public void destroy()Clean up at shutdown.
-