1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18 package org.apache.hadoop.hbase.metrics;
19
20
21 import org.apache.hadoop.hbase.HBaseInterfaceAudience;
22 import org.apache.hadoop.hbase.classification.InterfaceAudience;
23 import org.apache.hadoop.hbase.classification.InterfaceStability;
24
25 import com.google.common.base.Optional;
26
27 /**
28 * General purpose factory for creating various metrics.
29 */
30 @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC)
31 @InterfaceStability.Evolving
32 public interface MetricRegistry extends MetricSet {
33
34 /**
35 * Get or construct a {@link Timer} used to measure durations and report rates.
36 *
37 * @param name the name of the timer.
38 * @return An instance of {@link Timer}.
39 */
40 Timer timer(String name);
41
42 /**
43 * Get or construct a {@link Histogram} used to measure a distribution of values.
44 *
45 * @param name The name of the Histogram.
46 * @return An instance of {@link Histogram}.
47 */
48 Histogram histogram(String name);
49
50 /**
51 * Get or construct a {@link Meter} used to measure durations and report distributions (a
52 * combination of a {@link Timer} and a {@link Histogram}.
53 *
54 * @param name The name of the Meter.
55 * @return An instance of {@link Meter}.
56 */
57 Meter meter(String name);
58
59 /**
60 * Get or construct a {@link Counter} used to track a mutable number.
61 *
62 * @param name The name of the Counter
63 * @return An instance of {@link Counter}.
64 */
65 Counter counter(String name);
66
67 /**
68 * Register a {@link Gauge}. The Gauge will be invoked at a period defined by the implementation
69 * of {@link MetricRegistry}.
70 * @param name The name of the Gauge.
71 * @param gauge A callback to compute the current value.
72 * @return the registered gauge, or the existing gauge
73 */
74 <T> Gauge<T> register(String name, Gauge<T> gauge);
75
76 /**
77 * Registers the {@link Metric} with the given name if there does not exist one with the same
78 * name. Returns the newly registered or existing Metric.
79 * @param name The name of the Metric.
80 * @param metric the metric to register
81 * @return the registered metric, or the existing metrid
82 */
83 Metric register(String name, Metric metric);
84
85 /**
86 * Registers the {@link Metric}s in the given MetricSet.
87 * @param metricSet set of metrics to register.
88 */
89 void registerAll(MetricSet metricSet);
90
91 /**
92 * Returns previously registered metric with the name if any.
93 * @param name the name of the metric
94 * @return previously registered metric
95 */
96 Optional<Metric> get(String name);
97
98 /**
99 * Removes the metric with the given name.
100 *
101 * @param name the name of the metric
102 * @return true if the metric is removed.
103 */
104 boolean remove(String name);
105
106 /**
107 * Return the MetricRegistryInfo object for this registry.
108 * @return MetricRegistryInfo describing the registry.
109 */
110 @InterfaceAudience.Private
111 MetricRegistryInfo getMetricRegistryInfo();
112 }