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

@RestController public class MetricsProviderRestService extends Object
This class provides a RESTful Service to access the 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
Needless to say, only custom metrics can be modified. System metrics cannot be changed as they are directly extracted from the system.
Author:
Miguel Gomez
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final MetricsProvider
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new RestMetricsUpdater instance.
    This method should be called by the Spring Boot Application that will inject the MetricsProvider instance running in the service.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Changes the base unit for the disk capacity metrics of the system.
    The body will contain a single string that has a valid CapacityBaseUnit.
    void
    Changes the base unit for the physical memory metrics of the system.
    The body will contain a single string that has a valid CapacityBaseUnit.
    void
    Deletes a custom counter.
    The custom counter is deleted and removed from the registry, similar to the execution of MetricsProvider.removeCounter(String).
    void
    Deletes a custom gauge.
    The custom gauge is deleted and removed from the registry, similar to the execution of MetricsProvider.removeGauge(String).
    void
    Deletes a custom timer.
    The custom timer is deleted and removed from the registry, similar to the execution of MetricsProvider.removeTimer(String).
    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 String
    getMeter(String name, List<de.iip_ecosphere.platform.support.metrics.Tag> list)
    Retrieves a JSON Object representation of the meter from the MetricsProvider.
    getMeter(String name, 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.
    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.
    private Map<String,String>
    Parses a Json Object into a Map to extract the values.
    Quick fix to the Json Part not working.
    private Map<String,Object>
    Parses a Json Object into a Map to extract the values.
    Quick fix to the Json Part not working.
    void
    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 of MetricsProvider.increaseCounterBy(String, double), if there is no counter with the indicated URN, said counter is created.
    void
    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 of MetricsProvider.addGaugeValue(String, double), if there is no gauge with the indicated URN, said gauge is created.
    void
    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 of MetricsProvider.recordWithTimer(String, long, TimeUnit), if there is no timer with the indicated URN, said timer is created.

    Methods inherited from class java.lang.Object

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

  • Constructor Details

    • MetricsProviderRestService

      public MetricsProviderRestService(MetricsProvider metricsProvider)
      Creates a new RestMetricsUpdater instance.
      This method should be called by the Spring Boot Application that will inject the MetricsProvider instance running in the service.
      Parameters:
      metricsProvider - metrics provider instance of the service
  • Method Details

    • getCustomGaugeList

      @ResponseStatus(OK) @GetMapping("/gauges") public String 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

      @ResponseStatus(OK) @PutMapping("/gauges") public void putGaugeValue(@RequestBody 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 of MetricsProvider.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 of MetricsProvider.removeGauge(String).
      Parameters:
      name - URN of the gauge we want to remove
    • getCustomCounterList

      @ResponseStatus(OK) @GetMapping("/counters") public String 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

      @ResponseStatus(OK) @PutMapping("/counters") public void putCounterValue(@RequestBody 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 of MetricsProvider.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 of MetricsProvider.removeCounter(String).
      Parameters:
      name - URN of the counter we want to remove
    • getTimerCounterList

      @ResponseStatus(OK) @GetMapping("/timers") public String 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

      @ResponseStatus(OK) @PutMapping("/timers") public void putTimerValue(@RequestBody 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 of MetricsProvider.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 of MetricsProvider.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 valid CapacityBaseUnit. Maintaining the implementation used for the application.yml file, 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 valid CapacityBaseUnit. Maintaining the implementation used for the application.yml file, 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

      @ResponseStatus(OK) @GetMapping("/tagged-meter") public String 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 meter
      params - tags of the meter
      Returns:
      requested meter in JSON format
    • getSimpleMeterList

      @ResponseStatus(OK) @GetMapping("/simple-meter") public String 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

      private String getMeter(String name, List<de.iip_ecosphere.platform.support.metrics.Tag> list)
      Retrieves a JSON Object representation of the meter from the MetricsProvider.
      Parameters:
      name - of the meter
      list - of tags
      Returns:
      JsonObject representation of the meter
    • getGauge

      @ResponseStatus(OK) @GetMapping("/gauges/{name}") public String getGauge(@PathVariable String name)
      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

      @ResponseStatus(OK) @GetMapping("/timers/{name}") public String getTimer(@PathVariable String name)
      Retrieves a custom timer.
      Parameters:
      name - of the timer
      Returns:
      JsonObject representation of the timer.
    • parseCounterdGaugeAndConfig

      private Map<String,String> parseCounterdGaugeAndConfig(String json)
      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

      private Map<String,Object> parseTimer(String json)
      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