java.lang.Object
de.iip_ecosphere.platform.services.environment.metricsProvider.metricsAas.MetricsExtractorRestClient

public class MetricsExtractorRestClient extends Object
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.
Author:
Miguel Gomez
  • Field Details

  • Constructor Details

    • MetricsExtractorRestClient

      public MetricsExtractorRestClient(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.
      Parameters:
      hostAddr - inet address of the host that has the REST service
      portNo - 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

      private String sendGetRequest(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.
      Parameters:
      endpoint - endpoint where the resource is
      resource - resource we want to retrieve
      tags - tags that the resource has (if any)
      Returns:
      response body of the GET request
    • sendPutRequest

      private void sendPutRequest(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.
      Parameters:
      endpoint - endpoint where the request is sent
      body - request body
      Throws:
      IllegalArgumentException - if the request body causes an error in the server
    • sendDeleteRequest

      private void sendDeleteRequest(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.
      Parameters:
      endpoint - endpoint where the request is sent
      resource - 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

      public String getJvmBufferCount()
      Retrieves the number of buffers from the JVM.
      The metric received is of type MeterType#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

      public String getJvmBufferMemoryUsed()
      Retrieves the amount of buffer memory used by the JVM.
      The metric received is of type MeterType#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

      public String getJvmBufferTotalCapacity()
      Retrieves the total capacity of the buffers from the JVM.
      The metric received is of type MeterType#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

      public String getJvmClassesLoaded()
      Retrieves the number of classes loaded in the resource being monitored.
      The metric received is of type MeterType#GAUGE.
      Returns:
      a JsonObject representing the Gauge of loaded classes
    • getJvmClassesUnloaded

      public String getJvmClassesUnloaded()
      Retrieves the number of classes that has been unloaded from the JVM since execution started.
      The metric received is of type MeterType#COUNTER.
      Returns:
      a JsonObject representing the Counter of unloaded classes
    • getJvmGcLiveDataSize

      public String getJvmGcLiveDataSize()
      Retrieves the live data size of the garbage collector from the process being monitored.
      The metric received is of type MeterType#GAUGE.
      Returns:
      a JsonObject representing the Gauge of GC live data size
    • getJvmGcMaxDataSize

      public String getJvmGcMaxDataSize()
      Retrieves the max data size of the garbage collector from the process being monitored.
      The metric received is of type MeterType#GAUGE.
      Returns:
      a JsonObject representing the Gauge of GC max data size
    • getJvmGcMemoryAllocated

      public String getJvmGcMemoryAllocated()
      Retrieves the allocated memory of the garbage collector from the process being monitored.
      The metric received is of type MeterType#COUNTER.
      Returns:
      a JsonObject representing the Counter of GC allocated memory
    • getJvmGcMemoryPromoted

      public String getJvmGcMemoryPromoted()
      Retrieves the amount the memory of the garbage collector from the process being monitored has been promoted.
      The metric received is of type MeterType#COUNTER.
      Returns:
      a JsonObject representing the Counter of GC promoted memory
    • getJvmGcPause

      public String getJvmGcPause()
      Retrieves the timers for the Garbage Collector pause sorted by cause and action.
      The metric received is of type MeterType#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

      public String getJvmMemoryCommited()
      Retrieves the amount of committed memory from the JVM.
      The metric received is of type MeterType#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

      public String getJvmMemoryMax()
      Retrieves the max memory from the JVM.
      The metric received is of type MeterType#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

      public String getJvmMemoryUsed()
      Retrieves the amount of used memory from the JVM.
      The metric received is of type MeterType#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

      public String getJvmThreadsDaemon()
      Retrieves the number of Daemon threads running in the resource.
      The metric received is of type MeterType#GAUGE.
      Returns:
      a JsonObject representing the Gauge of Daemon threads
    • getJvmThreadsLive

      public String getJvmThreadsLive()
      Retrieves the number of live threads running in the resource.
      The metric received is of type MeterType#GAUGE.
      Returns:
      a JsonObject representing the Gauge of live threads
    • getJvmThreadsPeak

      public String getJvmThreadsPeak()
      Retrieves the peak number of threads running in the resource.
      The metric received is of type MeterType#GAUGE.
      Returns:
      a JsonObject representing the Gauge of peak threads
    • getJvmThreadsStates

      public String getJvmThreadsStates()
      Retrieves the number of threads running in the resource sorted by state.
      The metric received is of type MeterType#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

      public String getLogbackEvents()
      Retrieves the count of logback events from the resource sorted by level.
      The metric received is of type MeterType#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

      public String getProcessCpuUsage()
      Retrieves percentage of the CPU that the process is using.
      The metric received is of type MeterType#GAUGE.
      Returns:
      a JsonObject representing the Gauge of process CPU usage
    • getProcessStartTime

      public String getProcessStartTime()
      Retrieves the start time of the process being monitored.
      The metric received is of type MeterType#GAUGE.
      Returns:
      a JsonObject representing the Gauge of process start time
    • getProcessUptime

      public String getProcessUptime()
      Retrieves the total time the process being monitored has been running.
      The metric received is of type MeterType#GAUGE.
      Returns:
      a JsonObject representing the Gauge of process uptime
    • getSystemCpuCount

      public String getSystemCpuCount()
      Retrieves the number of CPUs running in the resource.
      The metric received is of type MeterType#GAUGE.
      Returns:
      a JsonObject representing the Gauge of CPU count
    • getSystemCpuUsage

      public String getSystemCpuUsage()
      Retrieves percentage of usage of the CPU running in the resource.
      The metric received is of type MeterType#GAUGE.
      Returns:
      a JsonObject representing the Gauge of system CPU usage
    • getSystemDiskFree

      public String getSystemDiskFree()
      Retrieves the free disk capacity in the resource.
      The metric received is of type MeterType#GAUGE.
      Returns:
      a JsonObject representing the Gauge of free disk space
    • getSystemDiskTotal

      public String getSystemDiskTotal()
      Retrieves the total disk capacity in the resource.
      The metric received is of type MeterType#GAUGE.
      Returns:
      a JsonObject representing the Gauge of total disk space
    • getSystemDiskUsable

      public String getSystemDiskUsable()
      Retrieves the usable disk capacity in the resource.
      The metric received is of type MeterType#GAUGE.
      Returns:
      a JsonObject representing the Gauge of usable disk space
    • getSystemsDiskUsed

      public String getSystemsDiskUsed()
      Retrieves the used disk capacity in the resource.
      The metric received is of type MeterType#GAUGE.
      Returns:
      a JsonObject representing the Gauge of used disk space
    • getSystemMemoryFree

      public String getSystemMemoryFree()
      Retrieves the amount of free physical memory in the resource.
      The metric received is of type MeterType#GAUGE.
      Returns:
      a JsonObject representing the Gauge of free physical memory
    • getSystemMemoryTotal

      public String getSystemMemoryTotal()
      Retrieves the total amount of physical memory in the resource.
      The metric received is of type MeterType#GAUGE.
      Returns:
      a JsonObject representing the Gauge of total physical memory
    • getSystemMemoryUsage

      public String getSystemMemoryUsage()
      Retrieves the percentage of usage of physical memory in the resource.
      The metric received is of type MeterType#GAUGE.
      Returns:
      a JsonObject representing the Gauge of usage of physical memory
    • getSystemMemoryUsed

      public String getSystemMemoryUsed()
      Retrieves the amount of used physical memory in the resource.
      The metric received is of type MeterType#GAUGE.
      Returns:
      a JsonObject representing the Gauge of used physical memory
    • getCustomGauge

      public String getCustomGauge(String name)
      Retrieves a custom gauge.
      All the metrics received are of type MeterType#GAUGE.
      Parameters:
      name - URN of the custom gauge
      Returns:
      a JsonObject representing the requested Custom Gauge
    • updateCustomGauge

      public Object 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. This method expects a single argument of type String that will represent the body of the HTTP PUT request. Said body corresponds to the JsonObject provided by GaugeRepresentation.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

      public Object 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. This method expects a single argument of type String that 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

      public String getCustomCounter(String name)
      Retrieves a custom counter.
      All the metrics received are of type MeterType#COUNTER.
      Parameters:
      name - URN of the custom counter
      Returns:
      a JsonObject representing the requested Custom Counter
    • updateCustomCounter

      public Object 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. This method expects a single argument of type String that will represent the body of the HTTP PUT request. Said body corresponds to the JsonObject provided by CounterRepresentation.getUpdater()
      Parameters:
      args - object array containing the body of the PUT request
      Returns:
      NULL, nothing is returned
    • deleteCustomCounter

      public Object deleteCustomCounter(Object[] args)
      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 type String that 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

      public String getCustomTimer(String name)
      Retrieves a custom timer.
      All the metrics received are of type MeterType#TIMER.
      Parameters:
      name - URN of the custom gauge
      Returns:
      a JsonObject representing the requested Custom Timer
    • updateCustomTimer

      public Object 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. This method expects a single argument of type String that will represent the body of the HTTP PUT request. Said body corresponds to the JsonObject provided by TimerRepresentation.getUpdater()
      Parameters:
      args - object array containing the body of the PUT request
      Returns:
      NULL, nothing is returned
    • deleteCustomTimer

      public Object 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. This method expects a single argument of type String that 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

      private String getMemoryMetric(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.
      Parameters:
      name - name of the memory metric
      Returns:
      the JsonArray with the requested metrics
    • getBufferMetric

      private String getBufferMetric(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.
      Parameters:
      name - name of the buffer metric
      Returns:
      the JsonArray with the requested metrics
    • setMemoryBaseUnit

      public Object 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. This method expects a single argument of type String which 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

      public Object 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. This method expects a single argument of type String which 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

      public String 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

      public String 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

      public String 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

      public String 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

      public String 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