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 */ 018 019package org.apache.hadoop.hbase.metrics; 020 021 022import org.apache.commons.lang3.builder.HashCodeBuilder; 023import org.apache.yetus.audience.InterfaceAudience; 024 025/** 026 * HBase Metrics are grouped in different MetricRegistry'ies. All metrics that correspond to a 027 * subcomponent (like RPC, GC, WAL) are managed in a single MetricRegistry. 028 * This class holds the name and description and JMX related context names for such group of 029 * metrics. 030 */ 031@InterfaceAudience.Private 032public class MetricRegistryInfo { 033 034 protected final String metricsName; 035 protected final String metricsDescription; 036 protected final String metricsContext; 037 protected final String metricsJmxContext; 038 protected final boolean existingSource; 039 040 public MetricRegistryInfo( 041 String metricsName, 042 String metricsDescription, 043 String metricsJmxContext, 044 String metricsContext, 045 boolean existingSource) { 046 this.metricsName = metricsName; 047 this.metricsDescription = metricsDescription; 048 this.metricsContext = metricsContext; 049 this.metricsJmxContext = metricsJmxContext; 050 this.existingSource = existingSource; 051 } 052 053 /** 054 * Get the metrics context. For hadoop metrics2 system this is usually an all lowercased string. 055 * eg. regionserver, master, thriftserver 056 * 057 * @return The string context used to register this source to hadoop's metrics2 system. 058 */ 059 public String getMetricsContext() { 060 return metricsContext; 061 } 062 063 /** 064 * Get the description of what this source exposes. 065 */ 066 public String getMetricsDescription() { 067 return metricsDescription; 068 } 069 070 /** 071 * Get the name of the context in JMX that this source will be exposed through. 072 * This is in ObjectName format. With the default context being Hadoop -> HBase 073 */ 074 public String getMetricsJmxContext() { 075 return metricsJmxContext; 076 } 077 078 /** 079 * Get the name of the metrics that are being exported by this source. 080 * Eg. IPC, GC, WAL 081 */ 082 public String getMetricsName() { 083 return metricsName; 084 } 085 086 /** 087 * Returns whether or not this MetricRegistry is for an existing BaseSource 088 * @return true if this MetricRegistry is for an existing BaseSource. 089 */ 090 public boolean isExistingSource() { 091 return existingSource; 092 } 093 094 @Override 095 public boolean equals(Object obj) { 096 if (obj instanceof MetricRegistryInfo) { 097 return this.hashCode() == obj.hashCode(); 098 } else { 099 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}