Interface Metric

All Known Implementing Classes:
MockMetric

public interface Metric

This interface provides an API for writing metric data to the configured MetricConsumer. If no Provider for the MetricConsumer class has been bound by the application, all calls to this interface are no-ops. The implementation of this interface uses thread local consumer instances, so as long as the MetricConsumer is thread-safe, so is this.

An instance of this class can be injected anywhere.

Author:
Simon Thoresen Hult
  • Method Details

    • set

      void set(String key, Number val, Metric.Context ctx)
      Set a metric value. This is typically used with histogram-type metrics.
      Parameters:
      key - The name of the metric to modify.
      val - The value to assign to the named metric.
      ctx - The context to further describe this entry.
    • add

      void add(String key, Number val, Metric.Context ctx)
      Add to a metric value. This is typically used with counter-type metrics.
      Parameters:
      key - the name of the metric to modify
      val - the value to add to the named metric
      ctx - the context to further describe this entry
    • createContext

      Metric.Context createContext(Map<String,?> properties)
      Creates a MetricConsumer-specific Metric.Context object that encapsulates the given properties. The returned Context object should be passed along every future call to set(String, Number, Context) and add(String, Number, Context) where the properties match those given here.
      Parameters:
      properties - the properties to incorporate in the context
      Returns:
      the created context