2015-12-17 08:26:19 +01:00
|
|
|
package com.scylladb.jmx.metrics;
|
2015-06-11 13:11:25 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2015 Cloudius Systems
|
|
|
|
*
|
|
|
|
* Modified by Cloudius Systems
|
|
|
|
*/
|
|
|
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
import com.yammer.metrics.core.APIMetricsRegistry;
|
|
|
|
import com.yammer.metrics.core.Counter;
|
|
|
|
import com.yammer.metrics.core.Gauge;
|
|
|
|
import com.yammer.metrics.core.Histogram;
|
|
|
|
import com.yammer.metrics.core.Meter;
|
|
|
|
import com.yammer.metrics.core.MetricName;
|
|
|
|
import com.yammer.metrics.core.Timer;
|
|
|
|
import com.yammer.metrics.reporting.JmxReporter;
|
2016-05-17 10:17:00 +02:00
|
|
|
import com.yammer.metrics.core.APIMeter;
|
2015-06-11 13:11:25 +02:00
|
|
|
|
|
|
|
public class APIMetrics {
|
|
|
|
private static final APIMetricsRegistry DEFAULT_REGISTRY = new APIMetricsRegistry();
|
|
|
|
private static final Thread SHUTDOWN_HOOK = new Thread() {
|
|
|
|
public void run() {
|
|
|
|
JmxReporter.shutdownDefault();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static {
|
|
|
|
JmxReporter.startDefault(DEFAULT_REGISTRY);
|
|
|
|
Runtime.getRuntime().addShutdownHook(SHUTDOWN_HOOK);
|
|
|
|
}
|
|
|
|
|
|
|
|
private APIMetrics() { /* unused */
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given a new {@link com.yammer.metrics.core.Gauge}, registers it under the
|
|
|
|
* given class and name.
|
|
|
|
*
|
|
|
|
* @param klass
|
|
|
|
* the class which owns the metric
|
|
|
|
* @param name
|
|
|
|
* the name of the metric
|
|
|
|
* @param metric
|
|
|
|
* the metric
|
|
|
|
* @param <T>
|
|
|
|
* the type of the value returned by the metric
|
|
|
|
* @return {@code metric}
|
|
|
|
*/
|
|
|
|
public static <T> Gauge<T> newGauge(Class<?> klass, String name,
|
|
|
|
Gauge<T> metric) {
|
|
|
|
return DEFAULT_REGISTRY.newGauge(klass, name, metric);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given a new {@link com.yammer.metrics.core.Gauge}, registers it under the
|
|
|
|
* given class and name.
|
|
|
|
*
|
|
|
|
* @param klass
|
|
|
|
* the class which owns the metric
|
|
|
|
* @param name
|
|
|
|
* the name of the metric
|
|
|
|
* @param scope
|
|
|
|
* the scope of the metric
|
|
|
|
* @param metric
|
|
|
|
* the metric
|
|
|
|
* @param <T>
|
|
|
|
* the type of the value returned by the metric
|
|
|
|
* @return {@code metric}
|
|
|
|
*/
|
|
|
|
public static <T> Gauge<T> newGauge(Class<?> klass, String name,
|
|
|
|
String scope, Gauge<T> metric) {
|
|
|
|
return DEFAULT_REGISTRY.newGauge(klass, name, scope, metric);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given a new {@link com.yammer.metrics.core.Gauge}, registers it under the
|
|
|
|
* given metric name.
|
|
|
|
*
|
|
|
|
* @param metricName
|
|
|
|
* the name of the metric
|
|
|
|
* @param metric
|
|
|
|
* the metric
|
|
|
|
* @param <T>
|
|
|
|
* the type of the value returned by the metric
|
|
|
|
* @return {@code metric}
|
|
|
|
*/
|
|
|
|
public static <T> Gauge<T> newGauge(MetricName metricName, Gauge<T> metric) {
|
|
|
|
return DEFAULT_REGISTRY.newGauge(metricName, metric);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new {@link com.yammer.metrics.core.Counter} and registers it
|
|
|
|
* under the given class and name.
|
|
|
|
*
|
|
|
|
* @param klass
|
|
|
|
* the class which owns the metric
|
|
|
|
* @param name
|
|
|
|
* the name of the metric
|
|
|
|
* @return a new {@link com.yammer.metrics.core.Counter}
|
|
|
|
*/
|
|
|
|
public static Counter newCounter(String url, Class<?> klass, String name) {
|
|
|
|
return DEFAULT_REGISTRY.newCounter(url, klass, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new {@link com.yammer.metrics.core.Counter} 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 scope
|
|
|
|
* the scope of the metric
|
|
|
|
* @return a new {@link com.yammer.metrics.core.Counter}
|
|
|
|
*/
|
|
|
|
public static Counter newCounter(String url, Class<?> klass, String name,
|
|
|
|
String scope) {
|
|
|
|
return DEFAULT_REGISTRY.newCounter(url, klass, name, scope);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new {@link com.yammer.metrics.core.Counter} and registers it
|
|
|
|
* under the given metric name.
|
|
|
|
*
|
|
|
|
* @param metricName
|
|
|
|
* the name of the metric
|
|
|
|
* @return a new {@link com.yammer.metrics.core.Counter}
|
|
|
|
*/
|
|
|
|
public static Counter newCounter(String url, MetricName metricName) {
|
|
|
|
return DEFAULT_REGISTRY.newCounter(url, metricName);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new {@link com.yammer.metrics.core.Histogram} 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 biased
|
|
|
|
* whether or not the histogram should be biased
|
|
|
|
* @return a new {@link com.yammer.metrics.core.Histogram}
|
|
|
|
*/
|
2015-06-18 10:40:22 +02:00
|
|
|
public static Histogram newHistogram(String url, Class<?> klass,
|
|
|
|
String name, boolean biased) {
|
|
|
|
return DEFAULT_REGISTRY.newHistogram(url, klass, name, biased);
|
2015-06-11 13:11:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new {@link com.yammer.metrics.core.Histogram} 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 biased
|
|
|
|
* whether or not the histogram should be biased
|
|
|
|
* @return a new {@link com.yammer.metrics.core.Histogram}
|
|
|
|
*/
|
2015-06-18 10:40:22 +02:00
|
|
|
public static Histogram newHistogram(String url, Class<?> klass,
|
|
|
|
String name, String scope, boolean biased) {
|
|
|
|
return DEFAULT_REGISTRY.newHistogram(url, klass, name, scope, biased);
|
2015-06-11 13:11:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new {@link com.yammer.metrics.core.Histogram} and registers it
|
|
|
|
* under the given metric name.
|
|
|
|
*
|
|
|
|
* @param metricName
|
|
|
|
* the name of the metric
|
|
|
|
* @param biased
|
|
|
|
* whether or not the histogram should be biased
|
|
|
|
* @return a new {@link com.yammer.metrics.core.Histogram}
|
|
|
|
*/
|
2015-06-18 10:40:22 +02:00
|
|
|
public static Histogram newHistogram(String url, MetricName metricName,
|
|
|
|
boolean biased) {
|
|
|
|
return DEFAULT_REGISTRY.newHistogram(url, metricName, biased);
|
2015-06-11 13:11:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new non-biased {@link com.yammer.metrics.core.Histogram} and
|
|
|
|
* registers it under the given class and name.
|
|
|
|
*
|
|
|
|
* @param klass
|
|
|
|
* the class which owns the metric
|
|
|
|
* @param name
|
|
|
|
* the name of the metric
|
|
|
|
* @return a new {@link com.yammer.metrics.core.Histogram}
|
|
|
|
*/
|
2015-06-18 10:40:22 +02:00
|
|
|
public static Histogram newHistogram(String url, Class<?> klass, String name) {
|
|
|
|
return DEFAULT_REGISTRY.newHistogram(url, klass, name);
|
2015-06-11 13:11:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new non-biased {@link com.yammer.metrics.core.Histogram} 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
|
|
|
|
* @return a new {@link com.yammer.metrics.core.Histogram}
|
|
|
|
*/
|
2015-06-18 10:40:22 +02:00
|
|
|
public static Histogram newHistogram(String url, Class<?> klass,
|
|
|
|
String name, String scope) {
|
|
|
|
return DEFAULT_REGISTRY.newHistogram(url, klass, name, scope);
|
2015-06-11 13:11:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new non-biased {@link com.yammer.metrics.core.Histogram} and
|
|
|
|
* registers it under the given metric name.
|
|
|
|
*
|
|
|
|
* @param metricName
|
|
|
|
* the name of the metric
|
|
|
|
* @return a new {@link com.yammer.metrics.core.Histogram}
|
|
|
|
*/
|
2015-06-18 10:40:22 +02:00
|
|
|
public static Histogram newHistogram(String url, MetricName metricName) {
|
|
|
|
return newHistogram(url, metricName, false);
|
2015-06-11 13:11:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new {@link com.yammer.metrics.core.Meter} 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 eventType
|
|
|
|
* the plural name of the type of events the meter is measuring
|
|
|
|
* (e.g., {@code "requests"})
|
|
|
|
* @param unit
|
|
|
|
* the rate unit of the new meter
|
|
|
|
* @return a new {@link com.yammer.metrics.core.Meter}
|
|
|
|
*/
|
2016-05-17 10:17:00 +02:00
|
|
|
public static APIMeter newMeter(String url, Class<?> klass, String name,
|
2015-06-11 13:11:25 +02:00
|
|
|
String eventType, TimeUnit unit) {
|
|
|
|
return DEFAULT_REGISTRY.newMeter(url, klass, name, eventType, unit);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new {@link com.yammer.metrics.core.Meter} 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 eventType
|
|
|
|
* the plural name of the type of events the meter is measuring
|
|
|
|
* (e.g., {@code "requests"})
|
|
|
|
* @param unit
|
|
|
|
* the rate unit of the new meter
|
|
|
|
* @return a new {@link com.yammer.metrics.core.Meter}
|
|
|
|
*/
|
2016-05-17 10:17:00 +02:00
|
|
|
public static APIMeter newMeter(String url, Class<?> klass, String name,
|
2015-06-11 13:11:25 +02:00
|
|
|
String scope, String eventType, TimeUnit unit) {
|
|
|
|
return DEFAULT_REGISTRY.newMeter(url, klass, name, scope, eventType,
|
|
|
|
unit);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new {@link com.yammer.metrics.core.Meter} and registers it
|
|
|
|
* under the given metric name.
|
|
|
|
*
|
|
|
|
* @param metricName
|
|
|
|
* the name of the metric
|
|
|
|
* @param eventType
|
|
|
|
* the plural name of the type of events the meter is measuring
|
|
|
|
* (e.g., {@code "requests"})
|
|
|
|
* @param unit
|
|
|
|
* the rate unit of the new meter
|
|
|
|
* @return a new {@link com.yammer.metrics.core.Meter}
|
|
|
|
*/
|
2016-05-17 10:17:00 +02:00
|
|
|
public static APIMeter newMeter(String url, MetricName metricName,
|
2015-06-11 13:11:25 +02:00
|
|
|
String eventType, TimeUnit unit) {
|
|
|
|
return DEFAULT_REGISTRY.newMeter(url, metricName, eventType, unit);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-07-14 17:01:30 +02:00
|
|
|
* Creates a new {@link com.yammer.metrics.core.APITimer} and registers it
|
2015-06-11 13:11:25 +02:00
|
|
|
* 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
|
2015-07-14 17:01:30 +02:00
|
|
|
* @return a new {@link com.yammer.metrics.core.APITimer}
|
2015-06-11 13:11:25 +02:00
|
|
|
*/
|
2015-07-14 17:01:30 +02:00
|
|
|
public static Timer newTimer(String url, Class<?> klass, String name,
|
2015-06-11 13:11:25 +02:00
|
|
|
TimeUnit durationUnit, TimeUnit rateUnit) {
|
2015-07-14 17:01:30 +02:00
|
|
|
return DEFAULT_REGISTRY.newTimer(url, klass, name, durationUnit, rateUnit);
|
2015-06-11 13:11:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-07-14 17:01:30 +02:00
|
|
|
* Creates a new {@link com.yammer.metrics.core.APITimer} and registers it
|
2015-06-11 13:11:25 +02:00
|
|
|
* 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
|
2015-07-14 17:01:30 +02:00
|
|
|
* @return a new {@link com.yammer.metrics.core.APITimer}
|
2015-06-11 13:11:25 +02:00
|
|
|
*/
|
2015-07-14 17:01:30 +02:00
|
|
|
public static Timer newTimer(String url, Class<?> klass, String name) {
|
|
|
|
return DEFAULT_REGISTRY.newTimer(url, klass, name);
|
2015-06-11 13:11:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-07-14 17:01:30 +02:00
|
|
|
* Creates a new {@link com.yammer.metrics.core.APITimer} and registers it
|
2015-06-11 13:11:25 +02:00
|
|
|
* 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
|
2015-07-14 17:01:30 +02:00
|
|
|
* @return a new {@link com.yammer.metrics.core.APITimer}
|
2015-06-11 13:11:25 +02:00
|
|
|
*/
|
2015-07-14 17:01:30 +02:00
|
|
|
public static Timer newTimer(String url, Class<?> klass, String name, String scope,
|
2015-06-11 13:11:25 +02:00
|
|
|
TimeUnit durationUnit, TimeUnit rateUnit) {
|
2015-07-14 17:01:30 +02:00
|
|
|
return DEFAULT_REGISTRY.newTimer(url, klass, name, scope, durationUnit,
|
2015-06-11 13:11:25 +02:00
|
|
|
rateUnit);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-07-14 17:01:30 +02:00
|
|
|
* Creates a new {@link com.yammer.metrics.core.APITimer} and registers it
|
2015-06-11 13:11:25 +02:00
|
|
|
* 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
|
2015-07-14 17:01:30 +02:00
|
|
|
* @return a new {@link com.yammer.metrics.core.APITimer}
|
2015-06-11 13:11:25 +02:00
|
|
|
*/
|
2015-07-14 17:01:30 +02:00
|
|
|
public static Timer newTimer(String url, Class<?> klass, String name, String scope) {
|
|
|
|
return DEFAULT_REGISTRY.newTimer(url, klass, name, scope);
|
2015-06-11 13:11:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-07-14 17:01:30 +02:00
|
|
|
* Creates a new {@link com.yammer.metrics.core.APITimer} and registers it
|
2015-06-11 13:11:25 +02:00
|
|
|
* 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
|
2015-07-14 17:01:30 +02:00
|
|
|
* @return a new {@link com.yammer.metrics.core.APITimer}
|
2015-06-11 13:11:25 +02:00
|
|
|
*/
|
2015-07-14 17:01:30 +02:00
|
|
|
public static Timer newTimer(String url, MetricName metricName, TimeUnit durationUnit,
|
2015-06-11 13:11:25 +02:00
|
|
|
TimeUnit rateUnit) {
|
2015-07-14 17:01:30 +02:00
|
|
|
return DEFAULT_REGISTRY.newTimer(url, metricName, durationUnit, rateUnit);
|
2015-06-11 13:11:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the (static) default registry.
|
|
|
|
*
|
|
|
|
* @return the metrics registry
|
|
|
|
*/
|
|
|
|
public static APIMetricsRegistry defaultRegistry() {
|
|
|
|
return DEFAULT_REGISTRY;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shuts down all thread pools for the default registry.
|
|
|
|
*/
|
|
|
|
public static void shutdown() {
|
|
|
|
DEFAULT_REGISTRY.shutdown();
|
|
|
|
JmxReporter.shutdownDefault();
|
|
|
|
Runtime.getRuntime().removeShutdownHook(SHUTDOWN_HOOK);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|