public class MetricCollector extends Object
extractMetrics()
. This method will also reset all the metrics stored. Use this class if you want to count
or average metrics periodically and with high concurrency, extract them and report them somewhere.Constructor and Description |
---|
MetricCollector(List<String> frequencies)
A constructor that sets up the collector with an initial count of 0 for each of the given metrics.
|
MetricCollector(List<String> frequencies,
List<String> averages)
A constructor that sets up the collector with an initial count of 0 for each of the given metrics.
|
Modifier and Type | Method and Description |
---|---|
void |
add(String key,
long total)
Add the given total to the existing sum for the given key.
|
void |
average(String key,
long absoluteTotal)
Increment one instance of an average metric with the absolute total.
|
void |
average(String key,
long absoluteTotal,
long frequencyTotal)
Average the given absolute total and frequency total into the metric so far.
|
Map<String,Number> |
extractMetrics()
Gets and resets the metrics currently stored in the collector.
|
void |
increment(String key)
Increment the value for the given key.
|
public MetricCollector(List<String> frequencies)
frequencies
- The List
of metrics to initialize to a count of zero.public void increment(String key)
key
- The key to increment.public void add(String key, long total)
key
- The key to add to.total
- The total to add as.public void average(String key, long absoluteTotal)
key
- The average metric to add the total to.absoluteTotal
- The total to add.public void average(String key, long absoluteTotal, long frequencyTotal)
key
- The name of the average metric.absoluteTotal
- The total of the metric being averaged.frequencyTotal
- The total number of instances of the absolute metric provided in this call.Copyright © 2021. All rights reserved.