Interface MetricsProvider


public interface MetricsProvider
Simplified metrics provider interface.
Author:
Holger Eichelberger, SSE
  • Method Details

    • getClock

      Clock getClock()
      Returns the clock used in the underlying meter registry.
      Returns:
      the clock
    • getRegistry

      MeterRegistry getRegistry()
      Returns the meter registry.
      Returns:
      the meter registry
    • recordWithTimer

      void recordWithTimer(String timerId, Runnable runnable)
      Records the execution of a runnable using a timer.
      Parameters:
      timerId - identifier of the custom timer
      runnable - runnable function that we want to record
      Throws:
      IllegalArgumentException - if the runnable or the identifier are null
    • recordWithTimer

      <T> T recordWithTimer(String timerId, Supplier<T> supplier)
      Records the execution of a supplier using a timer.
      Type Parameters:
      T - the datatype that the supplier returns
      Parameters:
      timerId - identifier of the custom timer
      supplier - supplier function that we want to record
      Returns:
      the value returned by the supplier
      Throws:
      IllegalArgumentException - if the identifier or the supplier are null
    • recordWithTimer

      void recordWithTimer(String timerId, long time, TimeUnit unit)
      Adds time from a specific timer.
      Parameters:
      timerId - identifier of the custom timer
      time - amount of time we want to record
      unit - base unit of the time we want to record
      Throws:
      IllegalArgumentException - if the identifier or the supplier are null
      IllegalArgumentException - if the time is negative
    • addGaugeValue

      void addGaugeValue(String gaugeId, double value)
      Adds a gauge value to the MeterRegistry.
      If the identifier does not correspond to an existing gauge, a new gauge will be created and registered. If it is an existing gauge, the value will simply be modified.
      Parameters:
      gaugeId - identifier for the gauge
      value - value we want to set the gauge to
      Throws:
      IllegalArgumentException - if the identifier is null
    • removeGauge

      void removeGauge(String gaugeId)
      Remove a custom gauge from the Meter Registry.
      Parameters:
      gaugeId - identifier of the custom gauge
      Throws:
      IllegalArgumentException - if there is no gauge with that identifier
    • increaseCounterBy

      void increaseCounterBy(String counterId, double value)
      Increases the counter by a certain value.
      If the identifier does not correspond to an existing counter, a new counter will be created and registered. If it is an existing counter, the value will simply be incremented by the amount requested.
      Parameters:
      counterId - identifier of the custom counter
      value - the amount we want to increases the counter
      Throws:
      IllegalArgumentException - if value is negative or if counterId is null
    • createServiceReceivedCounter

      default Counter createServiceReceivedCounter(String serviceName, String serviceId, String appId, String appInstanceId)
      Creates and registers a default service received counter.
      Parameters:
      serviceName - the static name/id of the service
      serviceId - the (complete) id of the service
      appId - the id of the application
      appInstanceId - the id of the application instance
      Returns:
      the registered counter instance
      See Also:
    • createServiceSentCounter

      default Counter createServiceSentCounter(String serviceName, String serviceId, String appId, String appInstanceId)
      Creates and registers a default service sent counter.
      Parameters:
      serviceName - the static name/id of the service
      serviceId - the (complete) id of the service
      appId - the id of the application
      appInstanceId - the id of the application instance
      Returns:
      the registered counter instance
      See Also:
    • createServiceSentReceivedCounter

      Counter createServiceSentReceivedCounter(boolean receive, String serviceName, String serviceId, String appId, String appInstanceId)
      Creates and registers a default service send/receive counter.
      Parameters:
      receive - is it for receiving (true) or sending
      serviceName - the static name/id of the service
      serviceId - the (complete) id of the service
      appId - the id of the application
      appInstanceId - the id of the application instance
      Returns:
      the registered counter instance
    • createServiceProcessingTimer

      Timer createServiceProcessingTimer(String serviceName, String serviceId, String appId, String appInstanceId)
      Creates and registers a default service processing timer.
      Parameters:
      serviceName - the static name/id of the service
      serviceId - the (complete) id of the service
      appId - the id of the application
      appInstanceId - the id of the application instance
      Returns:
      the registered counter instance
    • increaseCounterBy

      static <T> T increaseCounterBy(Counter counter, double value, T data)
      Helper method to increase/increment the given counter by the specified value if data is not null. Does nothing if counter is null.
      Parameters:
      counter - the counter
      value - the value
      data - the data to consider
      Returns:
      data
    • increaseCounterBy

      static void increaseCounterBy(Counter counter, double value)
      Helper method to increase/increment the given counter by the specified value. Does nothing if counter is null.
      Parameters:
      counter - the counter
      value - the value
    • recordMsTime

      static void recordMsTime(Timer timer, MetricsProvider.TimeSupplier timeSupplier, Runnable function)
      Record milliseconds time.
      Parameters:
      timer - the timer to record the time on
      timeSupplier - the time supplier returning the time after executing function
      function - the function to execute
    • recordNsTime

      static void recordNsTime(Timer timer, MetricsProvider.TimeSupplier timeSupplier, Runnable function)
      Record nanoseconds time.
      Parameters:
      timer - the timer to record the time on
      timeSupplier - the time supplier returning the time after executing function
      function - the function to execute
    • addService

      void addService(MonitoringService service)
      Adds a service to be updated regularly regarding its monitoring data. Services are not added multiple times.
      Parameters:
      service - the service, ignored if null