Class MetricsExtractorRestClient
java.lang.Object
de.iip_ecosphere.platform.services.environment.metricsProvider.metricsAas.MetricsExtractorRestClient
Class that implements a REST client to retrieve the Meters from the Metrics
Provider.
This class contains the method implementations to send different requests to the Metrics Provider. Apart from having a method that sends a GET request to retrieve all the metrics exposed by the Metrics Provider, it also has a series of methods that allows as to update or create a custom meter from the Metrics provider as well as methods to delete it. This methods should always be used to retrieve the values instead of using another REST client.
The methods that follow the IIP-Ecosphere AAS signature do not check the validity of their arguments. Part of this is checked by the IIP-Ecosphere framework and the other part by the Metrics Provider REST Service.
This class contains the method implementations to send different requests to the Metrics Provider. Apart from having a method that sends a GET request to retrieve all the metrics exposed by the Metrics Provider, it also has a series of methods that allows as to update or create a custom meter from the Metrics provider as well as methods to delete it. This methods should always be used to retrieve the values instead of using another REST client.
The methods that follow the IIP-Ecosphere AAS signature do not check the validity of their arguments. Part of this is checked by the IIP-Ecosphere framework and the other part by the Metrics Provider REST Service.
- Author:
- Miguel Gomez
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate de.iip_ecosphere.platform.support.rest.RestTarget -
Constructor Summary
ConstructorsConstructorDescriptionMetricsExtractorRestClient(String hostAddr, int portNo) Initializes a new Metrics Extractor REST Client.
Once the instance is created, the Client will have a Web Resource that will be the connection point to the server hosting the Metrics Provider REST Service. -
Method Summary
Modifier and TypeMethodDescriptiondeleteCustomCounter(Object[] args) Deletes a Custom Counter using the REST service.
This method is "forced" to follow the AAS signature, so there are some constraints.deleteCustomGauge(Object[] args) Deletes a Custom Gauge using the REST service.
This method is "forced" to follow the AAS signature, so there are some constraints.deleteCustomTimer(Object[] args) Deletes a Custom Timer using the REST service.
This method is "forced" to follow the AAS signature, so there are some constraints.private StringgetBufferMetric(String name) Retrieves a buffer metric from the REST service.
The buffer metrics exposed by Micrometer use the same tags, so this method is created to avoid code repetition.Retrieves the list of custom counters registered in the Metrics Provider.getCustomCounter(String name) Retrieves a custom counter.
All the metrics received are of typeMeterType#COUNTER.getCustomGauge(String name) Retrieves a custom gauge.
All the metrics received are of typeMeterType#GAUGE.getCustomTimer(String name) Retrieves a custom timer.
All the metrics received are of typeMeterType#TIMER.Retrieves the list of custom gauges registered in the Metrics Provider.Retrieves the number of buffers from the JVM.
The metric received is of typeMeterType#GAUGE.Retrieves the amount of buffer memory used by the JVM.
The metric received is of typeMeterType#GAUGE.Retrieves the total capacity of the buffers from the JVM.
The metric received is of typeMeterType#GAUGE.Retrieves the number of classes loaded in the resource being monitored.
The metric received is of typeMeterType#GAUGE.Retrieves the number of classes that has been unloaded from the JVM since execution started.
The metric received is of typeMeterType#COUNTER.Retrieves the live data size of the garbage collector from the process being monitored.
The metric received is of typeMeterType#GAUGE.Retrieves the max data size of the garbage collector from the process being monitored.
The metric received is of typeMeterType#GAUGE.Retrieves the allocated memory of the garbage collector from the process being monitored.
The metric received is of typeMeterType#COUNTER.Retrieves the amount the memory of the garbage collector from the process being monitored has been promoted.
The metric received is of typeMeterType#COUNTER.Retrieves the timers for the Garbage Collector pause sorted by cause and action.
The metric received is of typeMeterType#TIMER.Retrieves the amount of committed memory from the JVM.
The metric received is of typeMeterType#GAUGE.Retrieves the max memory from the JVM.
The metric received is of typeMeterType#GAUGE.Retrieves the amount of used memory from the JVM.
The metric received is of typeMeterType#GAUGE.Retrieves the number of Daemon threads running in the resource.
The metric received is of typeMeterType#GAUGE.Retrieves the number of live threads running in the resource.
The metric received is of typeMeterType#GAUGE.Retrieves the peak number of threads running in the resource.
The metric received is of typeMeterType#GAUGE.Retrieves the number of threads running in the resource sorted by state.
The metric received is of typeMeterType#GAUGE.Retrieves the count of logback events from the resource sorted by level.
The metric received is of typeMeterType#COUNTER.private StringgetMemoryMetric(String name) Retrieves a memory metric from the REST service.
The memory metrics exposed by Micrometer use the same tags, so this method is created to avoid code repetition.Retrieves percentage of the CPU that the process is using.
The metric received is of typeMeterType#GAUGE.Retrieves the start time of the process being monitored.
The metric received is of typeMeterType#GAUGE.Retrieves the total time the process being monitored has been running.
The metric received is of typeMeterType#GAUGE.Retrieves the list of non-tagged meters registered in the Metrics Provider.Retrieves the number of CPUs running in the resource.
The metric received is of typeMeterType#GAUGE.Retrieves percentage of usage of the CPU running in the resource.
The metric received is of typeMeterType#GAUGE.Retrieves the free disk capacity in the resource.
The metric received is of typeMeterType#GAUGE.Retrieves the total disk capacity in the resource.
The metric received is of typeMeterType#GAUGE.Retrieves the usable disk capacity in the resource.
The metric received is of typeMeterType#GAUGE.Retrieves the amount of free physical memory in the resource.
The metric received is of typeMeterType#GAUGE.Retrieves the total amount of physical memory in the resource.
The metric received is of typeMeterType#GAUGE.Retrieves the percentage of usage of physical memory in the resource.
The metric received is of typeMeterType#GAUGE.Retrieves the amount of used physical memory in the resource.
The metric received is of typeMeterType#GAUGE.Retrieves the used disk capacity in the resource.
The metric received is of typeMeterType#GAUGE.Retrieves the list of tagged meters registered in the Metrics Provider.Retrieves the list of custom timers registered in the Metrics Provider.private voidsendDeleteRequest(String endpoint, String resource) Sends HTTP DELETE request to the REST service.
If the response is OK, the value will have been deleted from the corresponding custom metric map and deregistered from the Meter Registry.private StringsendGetRequest(String endpoint, String resource, String... tags) Sends an HTTP GET request to the REST Service.
The response body will be a String that can be parsed into a JsonObject if the response is OK.private voidsendPutRequest(String endpoint, String body) Sends an HTTP PUT request to the REST service.
If the response is OK, the value will have been added to the corresponding custom metric map.setDiskBaseUnit(Object[] args) Updates the capacity base unit used for the system disk capacity metrics.
This method is "forced" to follow the AAS signature, so there are some constraints.setMemoryBaseUnit(Object[] args) Updates the memory base unit used for the system physical memory metrics.
This method is "forced" to follow the AAS signature, so there are some constraints.updateCustomCounter(Object[] args) Updates a Custom Counter using the REST service.
This method is "forced" to follow the AAS signature, so there are some constraints.updateCustomGauge(Object[] args) Updates a Custom Gauge using the REST service.
This method is "forced" to follow the AAS signature, so there are some constraints.updateCustomTimer(Object[] args) Updates a Custom Timer using the REST service.
This method is "forced" to follow the AAS signature, so there are some constraints.
-
Field Details
-
PROTOCOL
- See Also:
-
SIMPLE_ENDPOINT
- See Also:
-
TAGGED_ENDPOINT
- See Also:
-
COUNTERS_ENDPOINT
- See Also:
-
GAUGES_ENDPOINT
- See Also:
-
TIMERS_ENDPOINT
- See Also:
-
CONFIG_MEMORY_BASE_UNIT
- See Also:
-
CONFIG_DISK_BASE_UNIT
- See Also:
-
AREA_HEAP
- See Also:
-
ID_SURVIVOR_SPACE
- See Also:
-
ID_OLD_GEN
- See Also:
-
ID_EDEN_SPACE
- See Also:
-
AREA_NONHEAP
- See Also:
-
ID_METASPACE
- See Also:
-
ID_CODE_CACHE
- See Also:
-
ID_COMPRESSED_CLASS_SPACE
- See Also:
-
STATE_RUNNABLE
- See Also:
-
STATE_BLOCKED
- See Also:
-
STATE_WAITING
- See Also:
-
STATE_TIMED_WAITING
- See Also:
-
STATE_NEW
- See Also:
-
STATE_TERMINATED
- See Also:
-
ID_DIRECT
- See Also:
-
ID_MAPPED
- See Also:
-
LEVEL_WARN
- See Also:
-
LEVEL_DEBUG
- See Also:
-
LEVEL_ERROR
- See Also:
-
LEVEL_TRACE
- See Also:
-
LEVEL_INFO
- See Also:
-
CAUSE
- See Also:
-
CAUSE_FAILURE
- See Also:
-
ACTION_MAJOR
- See Also:
-
ACTION_MINOR
- See Also:
-
webTarget
private de.iip_ecosphere.platform.support.rest.RestTarget webTarget
-
-
Constructor Details
-
MetricsExtractorRestClient
Initializes a new Metrics Extractor REST Client.
Once the instance is created, the Client will have a Web Resource that will be the connection point to the server hosting the Metrics Provider REST Service.- Parameters:
hostAddr- inet address of the host that has the REST serviceportNo- port number were the REST service is hosted on the server- Throws:
IllegalArgumentException- if the host address is empty or if the port number is negative
-
-
Method Details
-
sendGetRequest
Sends an HTTP GET request to the REST Service.
The response body will be a String that can be parsed into a JsonObject if the response is OK.- Parameters:
endpoint- endpoint where the resource isresource- resource we want to retrievetags- tags that the resource has (if any)- Returns:
- response body of the GET request
-
sendPutRequest
Sends an HTTP PUT request to the REST service.
If the response is OK, the value will have been added to the corresponding custom metric map.- Parameters:
endpoint- endpoint where the request is sentbody- request body- Throws:
IllegalArgumentException- if the request body causes an error in the server
-
sendDeleteRequest
Sends HTTP DELETE request to the REST service.
If the response is OK, the value will have been deleted from the corresponding custom metric map and deregistered from the Meter Registry.- Parameters:
endpoint- endpoint where the request is sentresource- resource we want to delete- Throws:
IllegalStateException- if the deletion is not possible at the requested moment, returning an error code from the server
-
getJvmBufferCount
Retrieves the number of buffers from the JVM.
The metric received is of typeMeterType#GAUGE. The Gauges will be arranged in a JsonArray of JsonObjects. Said objects have a first attribute indicating the used tags and the second attribute will have the JsonObject that was retrieved from the REST service.- Returns:
- a JsonArray representing the set of Gauges of the number of buffers from the JVM sorted by id
-
getJvmBufferMemoryUsed
Retrieves the amount of buffer memory used by the JVM.
The metric received is of typeMeterType#GAUGE. The Gauges will be arranged in a JsonArray of JsonObjects. Said objects have a first attribute indicating the used tags and the second attribute will have the JsonObject that was retrieved from the REST service.- Returns:
- a JsonArray representing the set of Gauges of the buffer memory used by the JVM sorted by id
-
getJvmBufferTotalCapacity
Retrieves the total capacity of the buffers from the JVM.
The metric received is of typeMeterType#GAUGE. The Gauges will be arranged in a JsonArray of JsonObjects. Said objects have a first attribute indicating the used tags and the second attribute will have the JsonObject that was retrieved from the REST service.- Returns:
- a JsonArray representing the set of Gauges of the total buffer capacity of the JVM sorted by id
-
getJvmClassesLoaded
Retrieves the number of classes loaded in the resource being monitored.
The metric received is of typeMeterType#GAUGE.- Returns:
- a JsonObject representing the Gauge of loaded classes
-
getJvmClassesUnloaded
Retrieves the number of classes that has been unloaded from the JVM since execution started.
The metric received is of typeMeterType#COUNTER.- Returns:
- a JsonObject representing the Counter of unloaded classes
-
getJvmGcLiveDataSize
Retrieves the live data size of the garbage collector from the process being monitored.
The metric received is of typeMeterType#GAUGE.- Returns:
- a JsonObject representing the Gauge of GC live data size
-
getJvmGcMaxDataSize
Retrieves the max data size of the garbage collector from the process being monitored.
The metric received is of typeMeterType#GAUGE.- Returns:
- a JsonObject representing the Gauge of GC max data size
-
getJvmGcMemoryAllocated
Retrieves the allocated memory of the garbage collector from the process being monitored.
The metric received is of typeMeterType#COUNTER.- Returns:
- a JsonObject representing the Counter of GC allocated memory
-
getJvmGcMemoryPromoted
Retrieves the amount the memory of the garbage collector from the process being monitored has been promoted.
The metric received is of typeMeterType#COUNTER.- Returns:
- a JsonObject representing the Counter of GC promoted memory
-
getJvmGcPause
Retrieves the timers for the Garbage Collector pause sorted by cause and action.
The metric received is of typeMeterType#TIMER. The Timers will be arranged in a JsonArray of JsonObjects. Said objects have a first attribute indicating the used tags and the second attribute will have the JsonObject that was retrieved from the REST service.- Returns:
- a JsonArray representing the set of Timers of the GC pause
-
getJvmMemoryCommited
Retrieves the amount of committed memory from the JVM.
The metric received is of typeMeterType#GAUGE. The Gauges will be arranged in a JsonArray of JsonObjects. Said objects have a first attribute indicating the used tags and the second attribute will have the JsonObject that was retrieved from the REST service.- Returns:
- a JsonArray representing the set of Gauges of the amount of commited JVM memory sorted by area and id
-
getJvmMemoryMax
Retrieves the max memory from the JVM.
The metric received is of typeMeterType#GAUGE. The Gauges will be arranged in a JsonArray of JsonObjects. Said objects have a first attribute indicating the used tags and the second attribute will have the JsonObject that was retrieved from the REST service.- Returns:
- a JsonArray representing the set of Gauges of the max JVM memory sorted by area and id
-
getJvmMemoryUsed
Retrieves the amount of used memory from the JVM.
The metric received is of typeMeterType#GAUGE. The Gauges will be arranged in a JsonArray of JsonObjects. Said objects have a first attribute indicating the used tags and the second attribute will have the JsonObject that was retrieved from the REST service.- Returns:
- a JsonArray representing the set of Gauges of the amount of used JVM memory sorted by area and id
-
getJvmThreadsDaemon
Retrieves the number of Daemon threads running in the resource.
The metric received is of typeMeterType#GAUGE.- Returns:
- a JsonObject representing the Gauge of Daemon threads
-
getJvmThreadsLive
Retrieves the number of live threads running in the resource.
The metric received is of typeMeterType#GAUGE.- Returns:
- a JsonObject representing the Gauge of live threads
-
getJvmThreadsPeak
Retrieves the peak number of threads running in the resource.
The metric received is of typeMeterType#GAUGE.- Returns:
- a JsonObject representing the Gauge of peak threads
-
getJvmThreadsStates
Retrieves the number of threads running in the resource sorted by state.
The metric received is of typeMeterType#GAUGE. The Gauges will be arranged in a JsonArray of JsonObjects. Said objects have a first attribute indicating the used tags and the second attribute will have the JsonObject that was retrieved from the REST service.- Returns:
- a JsonArray representing the set of Gauges of the number of threads sorted by state
-
getLogbackEvents
Retrieves the count of logback events from the resource sorted by level.
The metric received is of typeMeterType#COUNTER. The Counters will be arranged in a JsonArray of JsonObjects. Said objects have a first attribute indicating the used tags and the second attribute will have the JsonObject that was retrieved from the REST service.- Returns:
- a JsonArray representing the set of Counters of the count of logback events sorted by level
-
getProcessCpuUsage
Retrieves percentage of the CPU that the process is using.
The metric received is of typeMeterType#GAUGE.- Returns:
- a JsonObject representing the Gauge of process CPU usage
-
getProcessStartTime
Retrieves the start time of the process being monitored.
The metric received is of typeMeterType#GAUGE.- Returns:
- a JsonObject representing the Gauge of process start time
-
getProcessUptime
Retrieves the total time the process being monitored has been running.
The metric received is of typeMeterType#GAUGE.- Returns:
- a JsonObject representing the Gauge of process uptime
-
getSystemCpuCount
Retrieves the number of CPUs running in the resource.
The metric received is of typeMeterType#GAUGE.- Returns:
- a JsonObject representing the Gauge of CPU count
-
getSystemCpuUsage
Retrieves percentage of usage of the CPU running in the resource.
The metric received is of typeMeterType#GAUGE.- Returns:
- a JsonObject representing the Gauge of system CPU usage
-
getSystemDiskFree
Retrieves the free disk capacity in the resource.
The metric received is of typeMeterType#GAUGE.- Returns:
- a JsonObject representing the Gauge of free disk space
-
getSystemDiskTotal
Retrieves the total disk capacity in the resource.
The metric received is of typeMeterType#GAUGE.- Returns:
- a JsonObject representing the Gauge of total disk space
-
getSystemDiskUsable
Retrieves the usable disk capacity in the resource.
The metric received is of typeMeterType#GAUGE.- Returns:
- a JsonObject representing the Gauge of usable disk space
-
getSystemsDiskUsed
Retrieves the used disk capacity in the resource.
The metric received is of typeMeterType#GAUGE.- Returns:
- a JsonObject representing the Gauge of used disk space
-
getSystemMemoryFree
Retrieves the amount of free physical memory in the resource.
The metric received is of typeMeterType#GAUGE.- Returns:
- a JsonObject representing the Gauge of free physical memory
-
getSystemMemoryTotal
Retrieves the total amount of physical memory in the resource.
The metric received is of typeMeterType#GAUGE.- Returns:
- a JsonObject representing the Gauge of total physical memory
-
getSystemMemoryUsage
Retrieves the percentage of usage of physical memory in the resource.
The metric received is of typeMeterType#GAUGE.- Returns:
- a JsonObject representing the Gauge of usage of physical memory
-
getSystemMemoryUsed
Retrieves the amount of used physical memory in the resource.
The metric received is of typeMeterType#GAUGE.- Returns:
- a JsonObject representing the Gauge of used physical memory
-
getCustomGauge
Retrieves a custom gauge.
All the metrics received are of typeMeterType#GAUGE.- Parameters:
name- URN of the custom gauge- Returns:
- a JsonObject representing the requested Custom Gauge
-
updateCustomGauge
Updates a Custom Gauge using the REST service.
This method is "forced" to follow the AAS signature, so there are some constraints. This method expects a single argument of typeStringthat will represent the body of the HTTP PUT request. Said body corresponds to the JsonObject provided byGaugeRepresentation.getUpdater()- Parameters:
args- object array containing the body of the PUT request- Returns:
- NULL, nothing is returned
- Throws:
IllegalArgumentException- if the number of arguments is not correct or if the argument is null
-
deleteCustomGauge
Deletes a Custom Gauge using the REST service.
This method is "forced" to follow the AAS signature, so there are some constraints. This method expects a single argument of typeStringthat will represent the resource URN of the HTTP DELETE request. Said resource URN corresponds to the name that was given to the custom Gauge.- Parameters:
args- object array containing the resource URN for the DELETE request- Returns:
- NULL, nothing is returned
-
getCustomCounter
Retrieves a custom counter.
All the metrics received are of typeMeterType#COUNTER.- Parameters:
name- URN of the custom counter- Returns:
- a JsonObject representing the requested Custom Counter
-
updateCustomCounter
Updates a Custom Counter using the REST service.
This method is "forced" to follow the AAS signature, so there are some constraints. This method expects a single argument of typeStringthat will represent the body of the HTTP PUT request. Said body corresponds to the JsonObject provided byCounterRepresentation.getUpdater()- Parameters:
args- object array containing the body of the PUT request- Returns:
- NULL, nothing is returned
-
deleteCustomCounter
Deletes a Custom Counter using the REST service.
This method is "forced" to follow the AAS signature, so there are some constraints. This method expects a single argument of typeStringthat will represent the resource URN of the HTTP DELETE request. Said resource URN corresponds to the name that was given to the custom Counter.- Parameters:
args- object array containing the resource URN for the DELETE request- Returns:
- NULL, nothing is returned
-
getCustomTimer
Retrieves a custom timer.
All the metrics received are of typeMeterType#TIMER.- Parameters:
name- URN of the custom gauge- Returns:
- a JsonObject representing the requested Custom Timer
-
updateCustomTimer
Updates a Custom Timer using the REST service.
This method is "forced" to follow the AAS signature, so there are some constraints. This method expects a single argument of typeStringthat will represent the body of the HTTP PUT request. Said body corresponds to the JsonObject provided byTimerRepresentation.getUpdater()- Parameters:
args- object array containing the body of the PUT request- Returns:
- NULL, nothing is returned
-
deleteCustomTimer
Deletes a Custom Timer using the REST service.
This method is "forced" to follow the AAS signature, so there are some constraints. This method expects a single argument of typeStringthat will represent the resource URN of the HTTP DELETE request. Said resource URN corresponds to the name that was given to the custom Timer.- Parameters:
args- object array containing the resource URN for the DELETE request- Returns:
- NULL, nothing is returned
-
getMemoryMetric
Retrieves a memory metric from the REST service.
The memory metrics exposed by Micrometer use the same tags, so this method is created to avoid code repetition.- Parameters:
name- name of the memory metric- Returns:
- the JsonArray with the requested metrics
-
getBufferMetric
Retrieves a buffer metric from the REST service.
The buffer metrics exposed by Micrometer use the same tags, so this method is created to avoid code repetition.- Parameters:
name- name of the buffer metric- Returns:
- the JsonArray with the requested metrics
-
setMemoryBaseUnit
Updates the memory base unit used for the system physical memory metrics.
This method is "forced" to follow the AAS signature, so there are some constraints. This method expects a single argument of typeStringwhich is a JSON object that contains the new unit. For example, to set the base unit to kilobytes, we send a JsonObject like this one:{ "unit":"kilobytes" }- Parameters:
args- object array containing the body of the PUT request- Returns:
- NULL, nothing is returned
-
setDiskBaseUnit
Updates the capacity base unit used for the system disk capacity metrics.
This method is "forced" to follow the AAS signature, so there are some constraints. This method expects a single argument of typeStringwhich is a JSON object that contains the new unit. For example, to set the base unit to kilobytes, we send a JsonObject like this one:{ "unit":"kilobytes" }- Parameters:
args- object array containing the body of the PUT request- Returns:
- NULL, nothing is returned
-
getGaugeList
Retrieves the list of custom gauges registered in the Metrics Provider.- Returns:
- a JsonArray representing a list with the names of all the custom gauges
-
getCounterList
Retrieves the list of custom counters registered in the Metrics Provider.- Returns:
- a JsonArray representing a list with the names of all the custom counters
-
getTimerList
Retrieves the list of custom timers registered in the Metrics Provider.- Returns:
- a JsonArray representing a list with the names of all the custom timers
-
getTaggedMeterList
Retrieves the list of tagged meters registered in the Metrics Provider.- Returns:
- a JsonArray representing a list with the names of relevant tagged meters in the meter registry
-
getSimpleMeterList
Retrieves the list of non-tagged meters registered in the Metrics Provider.- Returns:
- a JsonArray representing a list with the names of relevant non-tagged meters in the meter registry
-