Package com.yahoo.jdisc
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
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
Declares the interface for the arbitrary context object to pass to both theset(String, Number, Context)
andadd(String, Number, Context)
methods. -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(String key, Number val, Metric.Context ctx) Add to a metric value.createContext
(Map<String, ?> properties) Creates aMetricConsumer
-specificMetric.Context
object that encapsulates the given properties.void
set
(String key, Number val, Metric.Context ctx) Set a metric value.
-
Method Details
-
set
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
Add to a metric value. This is typically used with counter-type metrics.- Parameters:
key
- the name of the metric to modifyval
- the value to add to the named metricctx
- the context to further describe this entry
-
createContext
Creates aMetricConsumer
-specificMetric.Context
object that encapsulates the given properties. The returned Context object should be passed along every future call toset(String, Number, Context)
andadd(String, Number, Context)
where the properties match those given here.- Parameters:
properties
- the properties to incorporate in the context- Returns:
- the created context
-