Adding Timer creation to APIMetricsRegistry
This adds a Timer creation methods to the APIMetricsRegistry, the newTimer method would create an APITimer and would pass it the url for quering. Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
This commit is contained in:
parent
479a0769d1
commit
9d143efb07
@ -263,4 +263,100 @@ public class APIMetricsRegistry extends MetricsRegistry {
|
||||
return getOrAdd(metricName, new APIHistogram(url,
|
||||
biased ? SampleType.BIASED : SampleType.UNIFORM));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link Timer} and registers it under the given class and
|
||||
* name, measuring elapsed time in milliseconds and invocations per second.
|
||||
*
|
||||
* @param klass
|
||||
* the class which owns the metric
|
||||
* @param name
|
||||
* the name of the metric
|
||||
* @return a new {@link Timer}
|
||||
*/
|
||||
public Timer newTimer(String url, Class<?> klass, String name) {
|
||||
return newTimer(url, klass, name, null, TimeUnit.MILLISECONDS,
|
||||
TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link Timer} and registers it under the given class and
|
||||
* name.
|
||||
*
|
||||
* @param klass
|
||||
* the class which owns the metric
|
||||
* @param name
|
||||
* the name of the metric
|
||||
* @param durationUnit
|
||||
* the duration scale unit of the new timer
|
||||
* @param rateUnit
|
||||
* the rate scale unit of the new timer
|
||||
* @return a new {@link Timer}
|
||||
*/
|
||||
public Timer newTimer(String url, Class<?> klass, String name,
|
||||
TimeUnit durationUnit, TimeUnit rateUnit) {
|
||||
return newTimer(url, klass, name, null, durationUnit, rateUnit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link Timer} and registers it under the given class, name,
|
||||
* and scope, measuring elapsed time in milliseconds and invocations per
|
||||
* second.
|
||||
*
|
||||
* @param klass
|
||||
* the class which owns the metric
|
||||
* @param name
|
||||
* the name of the metric
|
||||
* @param scope
|
||||
* the scope of the metric
|
||||
* @return a new {@link Timer}
|
||||
*/
|
||||
public Timer newTimer(String url, Class<?> klass, String name, String scope) {
|
||||
return newTimer(url, klass, name, scope, TimeUnit.MILLISECONDS,
|
||||
TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link Timer} and registers it under the given class, name,
|
||||
* and scope.
|
||||
*
|
||||
* @param klass
|
||||
* the class which owns the metric
|
||||
* @param name
|
||||
* the name of the metric
|
||||
* @param scope
|
||||
* the scope of the metric
|
||||
* @param durationUnit
|
||||
* the duration scale unit of the new timer
|
||||
* @param rateUnit
|
||||
* the rate scale unit of the new timer
|
||||
* @return a new {@link Timer}
|
||||
*/
|
||||
public Timer newTimer(String url, Class<?> klass, String name,
|
||||
String scope, TimeUnit durationUnit, TimeUnit rateUnit) {
|
||||
return newTimer(url, createName(klass, name, scope), durationUnit,
|
||||
rateUnit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link Timer} and registers it under the given metric name.
|
||||
*
|
||||
* @param metricName
|
||||
* the name of the metric
|
||||
* @param durationUnit
|
||||
* the duration scale unit of the new timer
|
||||
* @param rateUnit
|
||||
* the rate scale unit of the new timer
|
||||
* @return a new {@link Timer}
|
||||
*/
|
||||
public Timer newTimer(String url, MetricName metricName,
|
||||
TimeUnit durationUnit, TimeUnit rateUnit) {
|
||||
final Metric existingMetric = getMetrics().get(metricName);
|
||||
if (existingMetric != null) {
|
||||
return (Timer) existingMetric;
|
||||
}
|
||||
return getOrAdd(metricName, new APITimer(url, newMeterTickThreadPool(),
|
||||
durationUnit, rateUnit, getClock()));
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user