Class MetricsProviderRestService
java.lang.Object
de.iip_ecosphere.platform.services.environment.spring.metricsProvider.MetricsProviderRestService
This class provides a RESTful Service to access the
The idea behind this RESTful Service is to continue down the line of a uniform HTTP communication between AAS and the MetricsProvider that would allow the AAS to update and delete values from the provider remotely. This can be used to unify the custom metrics from services running elsewhere into a single MetricsProvider instance.
The services offered by this class are:
MetricsProvider
instance running in the Spring Service. The idea behind this RESTful Service is to continue down the line of a uniform HTTP communication between AAS and the MetricsProvider that would allow the AAS to update and delete values from the provider remotely. This can be used to unify the custom metrics from services running elsewhere into a single MetricsProvider instance.
The services offered by this class are:
- Update a custom gauge
- Increase a custom counter
- Record time events with a custom timer
- Delete a custom metric
- Change the memory base unit for the physical memory metrics
- Change the disk capacity base unit for the physical memory metrics
- Author:
- Miguel Gomez
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionMetricsProviderRestService(MetricsProvider metricsProvider) Creates a new RestMetricsUpdater instance.
This method should be called by the Spring Boot Application that will inject theMetricsProviderinstance running in the service. -
Method Summary
Modifier and TypeMethodDescriptionvoidchangeDiskBaseUnit(String body) Changes the base unit for the disk capacity metrics of the system.
The body will contain a single string that has a validCapacityBaseUnit.voidchangeMemoryBaseUnit(String body) Changes the base unit for the physical memory metrics of the system.
The body will contain a single string that has a validCapacityBaseUnit.voiddeleteCounter(String name) Deletes a custom counter.
The custom counter is deleted and removed from the registry, similar to the execution ofMetricsProvider.removeCounter(String).voiddeleteGauge(String name) Deletes a custom gauge.
The custom gauge is deleted and removed from the registry, similar to the execution ofMetricsProvider.removeGauge(String).voiddeleteTimer(String name) Deletes a custom timer.
The custom timer is deleted and removed from the registry, similar to the execution ofMetricsProvider.removeTimer(String).getCounter(String name) Retrieves a custom counter.Retrieves a list of all the custom counters present in the Metrics Provider.Retrieves a list of all the custom gauges present in the Metrics Provider.Retrieves a custom gauge.Retrieves a meter with no tags.
Most of the meters do not have tags, so this method will be used to retrieve most metrics.private StringRetrieves a JSON Object representation of the meter from the MetricsProvider.Retrieves a meter with tags.
As some of the system meters have tags, this method will allow said metrics to be retrieved using the appropriate tags.Provides a list of all simple meters registered.
All the simple meters are meters extracted by micrometer and cannot be modified.Provides a list of all tagged meters registered.
All the tagged meters are meters extracted by micrometer and cannot be modified.Retrieves a custom timer.Retrieves a list of all the custom timers present in the Metrics Provider.Parses a Json Object into a Map to extract the values.
Quick fix to the Json Part not working.parseTimer(String json) Parses a Json Object into a Map to extract the values.
Quick fix to the Json Part not working.voidputCounterValue(String body) Increases a custom counter value.
The request body is expected to have plain text with two values separated by a comma, being the first value the URN (or name) of the counter we want to modify and the second the value by which we want to increase the counter.
Similar to the implementation ofMetricsProvider.increaseCounterBy(String, double), if there is no counter with the indicated URN, said counter is created.voidputGaugeValue(String body) Updates a custom gauge value.
The request body is expected to have plain text with two values separated by a comma, being the first value the URN (or name) of the gauge we want to modify and the second the value we want the gauge to have.
Similar to the implementation ofMetricsProvider.addGaugeValue(String, double), if there is no gauge with the indicated URN, said gauge is created.voidputTimerValue(String body) Increases a custom timer value.
The request body is expected to have plain text with multiple values separated by commas, being the first value the URN (or name) of the timer we want to modify and the remaining values the amounts of time in nanoseconds that we want to record with the timer.
Similar to the implementation ofMetricsProvider.recordWithTimer(String, long, TimeUnit), if there is no timer with the indicated URN, said timer is created.
-
Field Details
-
metricsProvider
-
-
Constructor Details
-
MetricsProviderRestService
Creates a new RestMetricsUpdater instance.
This method should be called by the Spring Boot Application that will inject theMetricsProviderinstance running in the service.- Parameters:
metricsProvider- metrics provider instance of the service
-
-
Method Details
-
getCustomGaugeList
Retrieves a list of all the custom gauges present in the Metrics Provider.- Returns:
- a JSON Array with a list of all the custom gauges registered
-
putGaugeValue
Updates a custom gauge value.
The request body is expected to have plain text with two values separated by a comma, being the first value the URN (or name) of the gauge we want to modify and the second the value we want the gauge to have.
Similar to the implementation ofMetricsProvider.addGaugeValue(String, double), if there is no gauge with the indicated URN, said gauge is created. Otherwise, the gauge is retrieved and the value is updated.
Following the REST standards, it is indicated that the entity being updated is, technically, the Gauge map, which involves creating or updating a custom gauge within.- Parameters:
body- request body containing the CSV representing the Gauge update
-
deleteGauge
@ResponseStatus(OK) @DeleteMapping("/gauges/{name}") public void deleteGauge(@PathVariable String name) Deletes a custom gauge.
The custom gauge is deleted and removed from the registry, similar to the execution ofMetricsProvider.removeGauge(String).- Parameters:
name- URN of the gauge we want to remove
-
getCustomCounterList
Retrieves a list of all the custom counters present in the Metrics Provider.- Returns:
- a JSON Array with a list of all the custom counters registered
-
putCounterValue
Increases a custom counter value.
The request body is expected to have plain text with two values separated by a comma, being the first value the URN (or name) of the counter we want to modify and the second the value by which we want to increase the counter.
Similar to the implementation ofMetricsProvider.increaseCounterBy(String, double), if there is no counter with the indicated URN, said counter is created. Otherwise, the counter is retrieved and the value is incremented.
Following the REST standards, it is indicated that the entity being updated is, technically, the Counter map, which involves creating or updating a custom counter within.- Parameters:
body- request body containing the CSV representing the Counter update
-
deleteCounter
@ResponseStatus(OK) @DeleteMapping("/counters/{name}") public void deleteCounter(@PathVariable String name) Deletes a custom counter.
The custom counter is deleted and removed from the registry, similar to the execution ofMetricsProvider.removeCounter(String).- Parameters:
name- URN of the counter we want to remove
-
getTimerCounterList
Retrieves a list of all the custom timers present in the Metrics Provider.- Returns:
- a JSON Array with a list of all the custom timers registered
-
putTimerValue
Increases a custom timer value.
The request body is expected to have plain text with multiple values separated by commas, being the first value the URN (or name) of the timer we want to modify and the remaining values the amounts of time in nanoseconds that we want to record with the timer.
Similar to the implementation ofMetricsProvider.recordWithTimer(String, long, TimeUnit), if there is no timer with the indicated URN, said timer is created. Otherwise, the timer is retrieved and the values are recorded.
Following the REST standards, it is indicated that the entity being updated is, technically, the Timer map, which involves creating or updating a custom timer within.- Parameters:
body- request body containing the CSV representing the Timer update
-
deleteTimer
@ResponseStatus(OK) @DeleteMapping("/timers/{name}") public void deleteTimer(@PathVariable String name) Deletes a custom timer.
The custom timer is deleted and removed from the registry, similar to the execution ofMetricsProvider.removeTimer(String).- Parameters:
name- URN of the timer we want to remove
-
changeMemoryBaseUnit
@ResponseStatus(OK) @PutMapping("/config/memory-base-unit") public void changeMemoryBaseUnit(@RequestBody String body) Changes the base unit for the physical memory metrics of the system.
The body will contain a single string that has a validCapacityBaseUnit. Maintaining the implementation used for theapplication.ymlfile, this is not letter case sensitive and the String will be accepted regardless of lower-case and upper-case values.- Parameters:
body- request body containing the String representing the value we want to set as memory base unit
-
changeDiskBaseUnit
@ResponseStatus(OK) @PutMapping("/config/disk-base-unit") public void changeDiskBaseUnit(@RequestBody String body) Changes the base unit for the disk capacity metrics of the system.
The body will contain a single string that has a validCapacityBaseUnit. Maintaining the implementation used for theapplication.ymlfile, this is not letter case sensitive and the String will be accepted regardless of lower-case and upper-case values.- Parameters:
body- request body containing the String representing the value we want to set as disk capacity base unit
-
getTaggedMeterList
Provides a list of all tagged meters registered.
All the tagged meters are meters extracted by micrometer and cannot be modified.- Returns:
- list of the tagged micrometer meters
-
getMeter
@ResponseStatus(OK) @GetMapping("/tagged-meter/{name}") public String getMeter(@PathVariable String name, @RequestParam(required=false) org.springframework.util.MultiValueMap<String, String> params) Retrieves a meter with tags.
As some of the system meters have tags, this method will allow said metrics to be retrieved using the appropriate tags.- Parameters:
name- name of the meterparams- tags of the meter- Returns:
- requested meter in JSON format
-
getSimpleMeterList
Provides a list of all simple meters registered.
All the simple meters are meters extracted by micrometer and cannot be modified.- Returns:
- list of the simple micrometer meters
-
getMeter
@ResponseStatus(OK) @GetMapping("/simple-meter/{name}") public String getMeter(@PathVariable String name) Retrieves a meter with no tags.
Most of the meters do not have tags, so this method will be used to retrieve most metrics. This method will also retrieve the first value found in the registry if we request a tagged metrics without specifying the tags.- Parameters:
name- name of the meter- Returns:
- requested meter in JSON format
-
getMeter
Retrieves a JSON Object representation of the meter from the MetricsProvider.- Parameters:
name- of the meterlist- of tags- Returns:
- JsonObject representation of the meter
-
getGauge
Retrieves a custom gauge.- Parameters:
name- of the gauge- Returns:
- JsonObject representation of the Gauge.
-
getCounter
@ResponseStatus(OK) @GetMapping("/counters/{name}") public String getCounter(@PathVariable String name) Retrieves a custom counter.- Parameters:
name- of the counter- Returns:
- JsonObject representation of the counter.
-
getTimer
Retrieves a custom timer.- Parameters:
name- of the timer- Returns:
- JsonObject representation of the timer.
-
parseCounterdGaugeAndConfig
Parses a Json Object into a Map to extract the values.
Quick fix to the Json Part not working. This Method parses Counters, Gauges and configuration updaters.- Parameters:
json- String representing a JsonObject- Returns:
- JsonObject mapped as a Map
-
parseTimer
Parses a Json Object into a Map to extract the values.
Quick fix to the Json Part not working. This Method parses Timers.- Parameters:
json- String representing a JsonObject- Returns:
- JsonObject mapped as a Map
-