001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.metrics;
019
020import java.util.Optional;
021
022import org.apache.hadoop.hbase.HBaseInterfaceAudience;
023import org.apache.yetus.audience.InterfaceAudience;
024import org.apache.yetus.audience.InterfaceStability;
025
026/**
027 * General purpose factory for creating various metrics.
028 */
029@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC)
030@InterfaceStability.Evolving
031public interface MetricRegistry extends MetricSet {
032
033  /**
034   * Get or construct a {@link Timer} used to measure durations and report rates.
035   *
036   * @param name the name of the timer.
037   * @return An instance of {@link Timer}.
038   */
039  Timer timer(String name);
040
041  /**
042   * Get or construct a {@link Histogram} used to measure a distribution of values.
043   *
044   * @param name The name of the Histogram.
045   * @return An instance of {@link Histogram}.
046   */
047  Histogram histogram(String name);
048
049  /**
050   * Get or construct a {@link Meter} used to measure durations and report distributions (a
051   * combination of a {@link Timer} and a {@link Histogram}.
052   *
053   * @param name The name of the Meter.
054   * @return An instance of {@link Meter}.
055   */
056  Meter meter(String name);
057
058  /**
059   * Get or construct a {@link Counter} used to track a mutable number.
060   *
061   * @param name The name of the Counter
062   * @return An instance of {@link Counter}.
063   */
064  Counter counter(String name);
065
066  /**
067   * Register a {@link Gauge}. The Gauge will be invoked at a period defined by the implementation
068   * of {@link MetricRegistry}.
069   * @param name The name of the Gauge.
070   * @param gauge A callback to compute the current value.
071   * @return the registered gauge, or the existing gauge
072   */
073  <T> Gauge<T> register(String name, Gauge<T> gauge);
074
075  /**
076   * Registers the {@link Metric} with the given name if there does not exist one with the same
077   * name. Returns the newly registered or existing Metric.
078   * @param name The name of the Metric.
079   * @param metric the metric to register
080   * @return the registered metric, or the existing metrid
081   */
082  Metric register(String name, Metric metric);
083
084  /**
085   * Registers the {@link Metric}s in the given MetricSet.
086   * @param metricSet set of metrics to register.
087   */
088  void registerAll(MetricSet metricSet);
089
090  /**
091   * Returns previously registered metric with the name if any.
092   * @param name the name of the metric
093   * @return previously registered metric
094   */
095  Optional<Metric> get(String name);
096
097  /**
098   * Removes the metric with the given name.
099   *
100   * @param name the name of the metric
101   * @return true if the metric is removed.
102   */
103  boolean remove(String name);
104
105  /**
106   * Return the MetricRegistryInfo object for this registry.
107   * @return MetricRegistryInfo describing the registry.
108   */
109  @InterfaceAudience.Private
110  MetricRegistryInfo getMetricRegistryInfo();
111}