Interface MetricStrategy
Strategy for tracking metrics of profiled code blocks, to be used with
Metrics.
Only metric timers and histograms created through Metrics.timer(String),
Metrics.startTimer(String), Metrics.histogram(String), Timers.timerWithMetric(java.lang.String, java.lang.String) and
Timers.startWithMetric(java.lang.String) will interact with
configured MetricStrategy instances.
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidcleanupMetrics(MetricsFilter filter) Removes existing metrics that are not accepted by the specified filter.default voidincrementCounter(MetricKey metricKey, long deltaValue) Does not guarantee safety from lost-updates, check implementations.default voidincrementGauge(MetricKey metricKey, long deltaValue) Does not guarantee safety from lost-updates, check implementations.default voidMethod that is called to signal that the request has completed.default voidresetMetric(MetricKey metricKey) Resets (that may mean removal depending on the metric strategy) a specific metric that exactly matches aMetricKey.default voidsetConfiguration(MetricsConfiguration configuration) Method that is called when the strategy isregistered.default voidCalled to set the gauge by the value.default TickerstartLongRunningTimer(MetricKey metricKey) Called to time something that is long-running and could benefit from periodic updates on the timer duration.default TickerstartLongRunningTimer(String metricName) Called to time something that is long-running and could benefit from periodic updates on the timer duration.default TickerstartTimer(MetricKey metricKey) Called to mark the end of a block of code for which metrics should be calculated.startTimer(String metricName) Called to mark the end of a block of code for which metrics should be calculated.default voidupdateHistogram(MetricKey metricKey, long value) Called when a histogram isupdated.voidupdateHistogram(String metricName, long value) Called when a histogram isupdated.default voidupdateTimer(MetricKey metricKey, Duration time) Called when a metric isupdated.voidupdateTimer(String metricName, long time, TimeUnit timeUnit) Called when a metric isupdated.
-
Method Details
-
cleanupMetrics
Removes existing metrics that are not accepted by the specified filter.Note: this optional for strategies to support
- Parameters:
filter- Metrics that are not accepted by the specified filter will be removed from this strategy.- Since:
- 4.1
-
resetMetric
Resets (that may mean removal depending on the metric strategy) a specific metric that exactly matches aMetricKey.- Parameters:
metricKey- metric key to be reset.- Since:
- 4.9.0
-
onRequestEnd
default void onRequestEnd() -
setConfiguration
Method that is called when the strategy isregistered.- Parameters:
configuration- the configuration
-
startTimer
Called to mark the end of a block of code for which metrics should be calculated.- Parameters:
metricName- the name of metric- Returns:
- a
tickerthat can be used tomarkthe end of the code block for which metrics should be calculated. Must be non-null, but can beTicker.NO_OPif the strategy opts out of tracking.
-
startTimer
Called to mark the end of a block of code for which metrics should be calculated.- Parameters:
metricKey- the key of metric- Returns:
- a
tickerthat can be used tomarkthe end of the code block for which metrics should be calculated. Must be non-null, but can beTicker.NO_OPif the strategy opts out of tracking. - Since:
- 3.4
-
startLongRunningTimer
Called to time something that is long-running and could benefit from periodic updates on the timer duration.Note: this optional for strategies to support This is an optional method, not all strategies will support this
- Parameters:
metricName- the name of metric- Returns:
- a
tickerthat can be used tomarkthe end of the code block for which metrics should be calculated. Must be non-null, but can beTicker.NO_OPif the strategy opts out of tracking. - Since:
- 3.5.0
-
startLongRunningTimer
Called to time something that is long-running and could benefit from periodic updates on the timer duration.Note: this optional for strategies to support This is an optional method, not all strategies will support this
- Parameters:
metricKey- the key of metric- Returns:
- a
tickerthat can be used tomarkthe end of the code block for which metrics should be calculated. Must be non-null, but can beTicker.NO_OPif the strategy opts out of tracking. - Since:
- 3.5.0
-
incrementCounter
Does not guarantee safety from lost-updates, check implementations.Called to increment the count of the number of occurences.
- Parameters:
metricKey- the key of counterdeltaValue- the amount to add to the counter- Since:
- 3.7.0
-
incrementGauge
Does not guarantee safety from lost-updates, check implementations.Called to increment the gauge by the value. Starts from 0
- Parameters:
metricKey- the key of the gaugedeltaValue- the change in gauge that should be recorded- Since:
- 4.8.0
-
updateHistogram
Called when a histogram isupdated.- Parameters:
metricName- the histogram namevalue- the value to record
-
updateHistogram
Called when a histogram isupdated.- Parameters:
metricKey- the histogram keyvalue- the value to record- Since:
- 3.4
-
updateTimer
Called when a metric isupdated.- Parameters:
metricName- the name of metrictime- the time to recordtimeUnit- the time unit oftime
-
updateTimer
Called when a metric isupdated.- Parameters:
metricKey- the key of timertime- the time to record- Since:
- 3.4
-
setGauge
Called to set the gauge by the value.- Parameters:
metricKey- the key of the gaugecurrentValue- the value of gauge that should be recorded- Since:
- 4.8.0
-