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
19 package org.apache.hadoop.hbase.metrics;
20
21
22 import org.apache.commons.lang.builder.HashCodeBuilder;
23 import org.apache.hadoop.hbase.classification.InterfaceAudience;
24
25 /**
26 * HBase Metrics are grouped in different MetricRegistry'ies. All metrics that correspond to a
27 * subcomponent (like RPC, GC, WAL) are managed in a single MetricRegistry.
28 * This class holds the name and description and JMX related context names for such group of
29 * metrics.
30 */
31 @InterfaceAudience.Private
32 public class MetricRegistryInfo {
33
34 protected final String metricsName;
35 protected final String metricsDescription;
36 protected final String metricsContext;
37 protected final String metricsJmxContext;
38 protected final boolean existingSource;
39
40 public MetricRegistryInfo(
41 String metricsName,
42 String metricsDescription,
43 String metricsJmxContext,
44 String metricsContext,
45 boolean existingSource) {
46 this.metricsName = metricsName;
47 this.metricsDescription = metricsDescription;
48 this.metricsContext = metricsContext;
49 this.metricsJmxContext = metricsJmxContext;
50 this.existingSource = existingSource;
51 }
52
53 /**
54 * Get the metrics context. For hadoop metrics2 system this is usually an all lowercased string.
55 * eg. regionserver, master, thriftserver
56 *
57 * @return The string context used to register this source to hadoop's metrics2 system.
58 */
59 public String getMetricsContext() {
60 return metricsContext;
61 }
62
63 /**
64 * Get the description of what this source exposes.
65 */
66 public String getMetricsDescription() {
67 return metricsDescription;
68 }
69
70 /**
71 * Get the name of the context in JMX that this source will be exposed through.
72 * This is in ObjectName format. With the default context being Hadoop -> HBase
73 */
74 public String getMetricsJmxContext() {
75 return metricsJmxContext;
76 }
77
78 /**
79 * Get the name of the metrics that are being exported by this source.
80 * Eg. IPC, GC, WAL
81 */
82 public String getMetricsName() {
83 return metricsName;
84 }
85
86 /**
87 * Returns whether or not this MetricRegistry is for an existing BaseSource
88 * @return true if this MetricRegistry is for an existing BaseSource.
89 */
90 public boolean isExistingSource() {
91 return existingSource;
92 }
93
94 @Override
95 public boolean equals(Object obj) {
96 if (obj instanceof MetricRegistryInfo) {
97 return this.hashCode() == obj.hashCode();
98 } else {
99 return false;
100 }
101 }
102
103 @Override
104 public int hashCode() {
105 return new HashCodeBuilder()
106 .append(metricsName)
107 .append(metricsDescription)
108 .append(metricsContext)
109 .append(metricsJmxContext)
110 .toHashCode();
111 }
112 }