Index: hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/metrics/RegionServerMetrics2.java =================================================================== --- hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/metrics/RegionServerMetrics2.java (revision 0) +++ hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/metrics/RegionServerMetrics2.java (revision 0) @@ -0,0 +1,57 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hbase.regionserver.metrics; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.hadoop.classification.InterfaceAudience; +import org.apache.hadoop.classification.InterfaceStability; +import org.apache.hadoop.hbase.CompatibilitySingletonFactory; + +/** + * This class is for maintaining the various regionserver statistics + * and publishing them through the metrics interfaces. + *
+ * This class has a number of metrics variables that are publicly accessible; + * these variables (objects) have methods to update their values. + */ +@InterfaceStability.Evolving +@InterfaceAudience.Private +public class RegionServerMetrics2 { + private final Log LOG = LogFactory.getLog(this.getClass()); + private RegionServerMetricsSource regionServerMetricsSource; + + public RegionServerMetrics2(final String name) { + regionServerMetricsSource = + CompatibilitySingletonFactory.getInstance(RegionServerMetricsSource.class); + } + + // for unit-test usage + public RegionServerMetricsSource getMetricsSource() { + return regionServerMetricsSource; + } + + /** + * Set the number of regions carried by this regionserver. + * @param count Amount to set. + */ + public void setRegions(final int count) { + regionServerMetricsSource.setRegions(count); + + } +} Index: hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java =================================================================== --- hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java (revision 1377167) +++ hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java (working copy) @@ -187,6 +187,7 @@ import org.apache.hadoop.hbase.regionserver.metrics.RegionMetricsStorage; import org.apache.hadoop.hbase.regionserver.metrics.RegionServerDynamicMetrics; import org.apache.hadoop.hbase.regionserver.metrics.RegionServerMetrics; +import org.apache.hadoop.hbase.regionserver.metrics.RegionServerMetrics2; import org.apache.hadoop.hbase.regionserver.metrics.SchemaMetrics; import org.apache.hadoop.hbase.regionserver.metrics.SchemaMetrics.StoreMetricType; import org.apache.hadoop.hbase.regionserver.wal.HLog; @@ -374,6 +375,8 @@ private RegionServerDynamicMetrics dynamicMetrics; + private RegionServerMetrics2 metrics2; + /* * Check for compactions requests. */ @@ -1172,6 +1175,7 @@ // Init in here rather than in constructor after thread name has been set this.metrics = new RegionServerMetrics(); this.dynamicMetrics = RegionServerDynamicMetrics.newInstance(); + this.metrics2 = new RegionServerMetrics2(getServerName().toString()); startServiceThreads(); LOG.info("Serving as " + this.serverNameFromMasterPOV + ", RPC listening on " + this.isa + @@ -1415,6 +1419,7 @@ protected void metrics() { this.metrics.regions.set(this.onlineRegions.size()); + this.metrics2.setRegions(this.onlineRegions.size()); this.metrics.incrementRequests(this.requestCount.get()); this.metrics.requests.intervalHeartBeat(); // Is this too expensive every three seconds getting a lock on onlineRegions @@ -1564,6 +1569,10 @@ return this.metrics; } + RegionServerMetrics2 getMetrics2() { + return this.metrics2; + } + /** * @return Master address tracker instance. */ Index: hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/regionserver/metrics/RegionServerMetricsSourceImplTest.java =================================================================== --- hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/regionserver/metrics/RegionServerMetricsSourceImplTest.java (revision 0) +++ hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/regionserver/metrics/RegionServerMetricsSourceImplTest.java (revision 0) @@ -0,0 +1,40 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hbase.regionserver.metrics; + +import org.apache.hadoop.hbase.CompatibilitySingletonFactory; +import org.junit.Test; + +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; + +/** + * Test for RegionServerMetricsSourceImpl + */ +public class RegionServerMetricsSourceImplTest { + + @Test + public void testGetInstance() throws Exception { + RegionServerMetricsSource rms = CompatibilitySingletonFactory + .getInstance(RegionServerMetricsSource.class); + assertTrue(rms instanceof RegionServerMetricsSourceImpl); + assertSame(rms, CompatibilitySingletonFactory.getInstance(RegionServerMetricsSource.class)); + } + +} Index: hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/regionserver/metrics/RegionServerMetricsSourceImpl.java =================================================================== --- hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/regionserver/metrics/RegionServerMetricsSourceImpl.java (revision 0) +++ hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/regionserver/metrics/RegionServerMetricsSourceImpl.java (revision 0) @@ -0,0 +1,48 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hbase.regionserver.metrics; + +import org.apache.hadoop.hbase.metrics.BaseMetricsSourceImpl; +import org.apache.hadoop.metrics2.lib.MetricMutableCounterLong; +import org.apache.hadoop.metrics2.lib.MetricMutableGaugeLong; + +/** + * Hadoop1 implementation of RegionServerMetricsSource. + */ +public class RegionServerMetricsSourceImpl + extends BaseMetricsSourceImpl implements RegionServerMetricsSource { + + MetricMutableGaugeLong regions; + + public RegionServerMetricsSourceImpl() { + this(METRICS_NAME, METRICS_DESCRIPTION, METRICS_CONTEXT); + } + + public RegionServerMetricsSourceImpl(String metricsName, + String metricsDescription, + String metricsContext) { + super(metricsName, metricsDescription, metricsContext); + + regions = getLongGauge("regions", 0); + } + + public void setRegions(final int count) { + regions.set(count); + } +} Index: hbase-hadoop1-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.regionserver.metrics.RegionServerMetricsSource =================================================================== --- hbase-hadoop1-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.regionserver.metrics.RegionServerMetricsSource (revision 0) +++ hbase-hadoop1-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.regionserver.metrics.RegionServerMetricsSource (revision 0) @@ -0,0 +1 @@ +org.apache.hadoop.hbase.regionserver.metrics.RegionServerMetricsSourceImpl Index: hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/regionserver/metrics/RegionServerMetricsSourceImplTest.java =================================================================== --- hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/regionserver/metrics/RegionServerMetricsSourceImplTest.java (revision 0) +++ hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/regionserver/metrics/RegionServerMetricsSourceImplTest.java (revision 0) @@ -0,0 +1,40 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hbase.regionserver.metrics; + +import org.apache.hadoop.hbase.CompatibilitySingletonFactory; +import org.junit.Test; + +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; + +/** + * Test for RegionServerMetricsSourceImpl + */ +public class RegionServerMetricsSourceImplTest { + + @Test + public void testGetInstance() throws Exception { + RegionServerMetricsSource rms = CompatibilitySingletonFactory + .getInstance(RegionServerMetricsSource.class); + assertTrue(rms instanceof RegionServerMetricsSourceImpl); + assertSame(rms, CompatibilitySingletonFactory.getInstance(RegionServerMetricsSource.class)); + } + +} Index: hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/metrics/RegionServerMetricsSourceImpl.java =================================================================== --- hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/metrics/RegionServerMetricsSourceImpl.java (revision 0) +++ hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/metrics/RegionServerMetricsSourceImpl.java (revision 0) @@ -0,0 +1,48 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hbase.regionserver.metrics; + +import org.apache.hadoop.hbase.metrics.BaseMetricsSourceImpl; +import org.apache.hadoop.metrics2.lib.MutableCounterLong; +import org.apache.hadoop.metrics2.lib.MutableGaugeLong; + +/** + * Hadoop2 implementation of RegionServerMetricsSource. + */ +public class RegionServerMetricsSourceImpl + extends BaseMetricsSourceImpl implements RegionServerMetricsSource { + + MutableGaugeLong regions; + + public RegionServerMetricsSourceImpl() { + this(METRICS_NAME, METRICS_DESCRIPTION, METRICS_CONTEXT); + } + + public RegionServerMetricsSourceImpl(String metricsName, + String metricsDescription, + String metricsContext) { + super(metricsName, metricsDescription, metricsContext); + + regions = getLongGauge("regions", 0); + } + + public void setRegions(final int count) { + regions.set(count); + } +} Index: hbase-hadoop2-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.regionserver.metrics.RegionServerMetricsSource =================================================================== --- hbase-hadoop2-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.regionserver.metrics.RegionServerMetricsSource (revision 0) +++ hbase-hadoop2-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.regionserver.metrics.RegionServerMetricsSource (revision 0) @@ -0,0 +1 @@ +org.apache.hadoop.hbase.regionserver.metrics.RegionServerMetricsSourceImpl Index: hbase-hadoop-compat/src/test/java/org/apache/hadoop/hbase/regionserver/metrics/RegionServerMetricsSourceFactoryTest.java =================================================================== --- hbase-hadoop-compat/src/test/java/org/apache/hadoop/hbase/regionserver/metrics/RegionServerMetricsSourceFactoryTest.java (revision 0) +++ hbase-hadoop-compat/src/test/java/org/apache/hadoop/hbase/regionserver/metrics/RegionServerMetricsSourceFactoryTest.java (revision 0) @@ -0,0 +1,35 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hbase.regionserver.metrics; + +import org.apache.hadoop.hbase.CompatibilitySingletonFactory; +import org.junit.Test; + +/** + * Test for the CompatibilitySingletonFactory and building RegionServerMetricsSource + */ +public class RegionServerMetricsSourceFactoryTest { + + @Test(expected=RuntimeException.class) + public void testGetInstanceNoHadoopCompat() throws Exception { + //This should throw an exception because there is no compat lib on the class path. + CompatibilitySingletonFactory.getInstance(RegionServerMetricsSource.class); + + } +} Index: hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/regionserver/metrics/RegionServerMetricsSource.java =================================================================== --- hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/regionserver/metrics/RegionServerMetricsSource.java (revision 0) +++ hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/regionserver/metrics/RegionServerMetricsSource.java (revision 0) @@ -0,0 +1,48 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hbase.regionserver.metrics; + +import org.apache.hadoop.hbase.metrics.BaseMetricsSource; + +/** + * Interface that classes that expose metrics about the regionserver will implement. + */ +public interface RegionServerMetricsSource extends BaseMetricsSource { + + /** + * The name of the metrics + */ + public static final String METRICS_NAME = "HRegionServer"; + + /** + * The name of the metrics context that metrics will be under. + */ + public static final String METRICS_CONTEXT = "HRegionServer,sub=Dynamic"; + + /** + * Description + */ + public static final String METRICS_DESCRIPTION = "Metrics about HBase regionserver"; + + /** + * Set the number of regions carried by this regionserver. + * @param count Amount to set. + */ + public void setRegions(final int count); +}