/** * Given a new {@link 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 <T> Gauge<T> newGauge(MetricName metricName, Gauge<T> metric) { return getOrAdd(metricName, metric); }
/** * Creates a new {@link Counter} and registers it under the given metric name. * * @param metricName the name of the metric * @return a new {@link Counter} */ public Counter newCounter(MetricName metricName) { return getOrAdd(metricName, new Counter()); }
/** * Creates a new {@link 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 Histogram} */ public Histogram newHistogram(MetricName metricName, boolean biased) { return getOrAdd(metricName, new Histogram(biased ? SampleType.BIASED : SampleType.UNIFORM)); }
/** * Creates a new {@link 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 Meter} */ public Meter newMeter(MetricName metricName, String eventType, TimeUnit unit) { final Metric existingMetric = metrics.get(metricName); if (existingMetric != null) { return (Meter) existingMetric; } return getOrAdd(metricName, new Meter(newMeterTickThreadPool(), eventType, unit, clock)); }
/** * 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(MetricName metricName, TimeUnit durationUnit, TimeUnit rateUnit) { final Metric existingMetric = metrics.get(metricName); if (existingMetric != null) { return (Timer) existingMetric; } return getOrAdd(metricName, new Timer(newMeterTickThreadPool(), durationUnit, rateUnit, clock)); }
/** * A static factory method to create an instance of Delta Counter. * * @param registry The MetricRegistry to use * @param metricName The MetricName to use * @return An instance of DeltaCounter */ @VisibleForTesting public static synchronized DeltaCounter get(MetricsRegistry registry, MetricName metricName) { if (registry == null || metricName == null || metricName.getName().isEmpty()) { throw new IllegalArgumentException("Invalid arguments"); } DeltaCounter counter = new DeltaCounter(); MetricName newMetricName = getDeltaCounterMetricName(metricName); registry.getOrAdd(newMetricName, counter); return counter; }
/** * A static factory method to create an instance of Delta Counter. * * @param registry The MetricRegistry to use * @param metricName The MetricName to use * @return An instance of DeltaCounter */ @VisibleForTesting public static synchronized DeltaCounter get(MetricsRegistry registry, MetricName metricName) { if (registry == null || metricName == null || metricName.getName().isEmpty()) { throw new IllegalArgumentException("Invalid arguments"); } DeltaCounter counter = new DeltaCounter(); MetricName newMetricName = getDeltaCounterMetricName(metricName); registry.getOrAdd(newMetricName, counter); return counter; }
@VisibleForTesting public static WavefrontHistogram get(MetricsRegistry registry, MetricName metricName, Supplier<Long> clock) { // Awkward construction trying to fit in with Yammer Histograms TDigestSample sample = new TDigestSample(); WavefrontHistogram tDigestHistogram = new WavefrontHistogram(sample, clock); sample.set(tDigestHistogram); return registry.getOrAdd(metricName, tDigestHistogram); }
@VisibleForTesting public static WavefrontHistogram get(MetricsRegistry registry, MetricName metricName, Supplier<Long> clock) { // Awkward construction trying to fit in with Yammer Histograms TDigestSample sample = new TDigestSample(); WavefrontHistogram tDigestHistogram = new WavefrontHistogram(sample, clock); sample.set(tDigestHistogram); return registry.getOrAdd(metricName, tDigestHistogram); }