HBASE-14719 Add metrics for master WAL count (numMasterWALs). Metric numMasterWALs appears as follows in metrics dump

{
    "name" : "Hadoop:service=HBase,name=Master,sub=Procedure",
    "modelerType" : "Master,sub=Procedure",
    "tag.Context" : "master",
    "tag.Hostname" : "vrishal-mbp",
    "numMasterWALs" : 1
},

Signed-off-by: Elliott Clark <eclark@apache.org>
This commit is contained in:
Vrishal Kulkarni 2015-11-20 06:57:18 -08:00 committed by Elliott Clark
parent 8bf70144e4
commit 1f999c1e2b
14 changed files with 289 additions and 6 deletions

View File

@ -0,0 +1,53 @@
/**
* 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.master;
import org.apache.hadoop.hbase.metrics.BaseSource;
/**
* Interface that classes that expose metrics about the master will implement.
*/
public interface MetricsMasterProcSource extends BaseSource {
/**
* The name of the metrics
*/
String METRICS_NAME = "Procedure";
/**
* The context metrics will be under.
*/
String METRICS_CONTEXT = "master";
/**
* The name of the metrics context that metrics will be under in jmx
*/
String METRICS_JMX_CONTEXT = "Master,sub=" + METRICS_NAME;
/**
* Description
*/
String METRICS_DESCRIPTION = "Metrics about HBase master procedure";
// Strings used for exporting to metrics system.
String NUM_MASTER_WALS_NAME = "numMasterWALs";
String NUM_MASTER_WALS_DESC = "Number of master WAL files";
}

View File

@ -0,0 +1,28 @@
/**
* 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.master;
/**
* Interface of a factory to create MetricsMasterSource when given a MetricsMasterWrapper
*/
public interface MetricsMasterProcSourceFactory {
MetricsMasterProcSource create(MetricsMasterWrapper masterWrapper);
}

View File

@ -58,7 +58,6 @@ public interface MetricsMasterSource extends BaseSource {
String CLUSTER_ID_NAME = "clusterId";
String IS_ACTIVE_MASTER_NAME = "isActiveMaster";
String CLUSTER_REQUESTS_NAME = "clusterRequests";
String MASTER_ACTIVE_TIME_DESC = "Master Active Time";
String MASTER_START_TIME_DESC = "Master Start Time";

View File

@ -107,4 +107,9 @@ public interface MetricsMasterWrapper {
*/
int getNumDeadRegionServers();
/**
* Get the number of master WAL files.
*/
long getNumWALFiles();
}

View File

@ -0,0 +1,38 @@
/**
* 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.master;
import org.apache.hadoop.hbase.classification.InterfaceAudience;
/**
* Factory to create MetricsMasterProcSource when given a MetricsMasterWrapper
*/
@InterfaceAudience.Private
public class MetricsMasterProcSourceFactoryImpl implements MetricsMasterProcSourceFactory {
private MetricsMasterProcSource masterProcSource;
@Override
public synchronized MetricsMasterProcSource create(MetricsMasterWrapper masterWrapper) {
if (masterProcSource == null) {
masterProcSource = new MetricsMasterProcSourceImpl(masterWrapper);
}
return masterProcSource;
}
}

View File

@ -0,0 +1,75 @@
/**
* 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.master;
import org.apache.hadoop.hbase.classification.InterfaceAudience;
import org.apache.hadoop.hbase.metrics.BaseSourceImpl;
import org.apache.hadoop.metrics2.MetricsCollector;
import org.apache.hadoop.metrics2.MetricsRecordBuilder;
import org.apache.hadoop.metrics2.lib.Interns;
/**
* Hadoop2 implementation of MetricsMasterSource.
*
* Implements BaseSource through BaseSourceImpl, following the pattern
*/
@InterfaceAudience.Private
public class MetricsMasterProcSourceImpl
extends BaseSourceImpl implements MetricsMasterProcSource {
private final MetricsMasterWrapper masterWrapper;
public MetricsMasterProcSourceImpl(MetricsMasterWrapper masterWrapper) {
this(METRICS_NAME,
METRICS_DESCRIPTION,
METRICS_CONTEXT,
METRICS_JMX_CONTEXT,
masterWrapper);
}
public MetricsMasterProcSourceImpl(String metricsName,
String metricsDescription,
String metricsContext,
String metricsJmxContext,
MetricsMasterWrapper masterWrapper) {
super(metricsName, metricsDescription, metricsContext, metricsJmxContext);
this.masterWrapper = masterWrapper;
}
@Override
public void init() {
super.init();
}
@Override
public void getMetrics(MetricsCollector metricsCollector, boolean all) {
MetricsRecordBuilder metricsRecordBuilder = metricsCollector.addRecord(metricsName);
// masterWrapper can be null because this function is called inside of init.
if (masterWrapper != null) {
metricsRecordBuilder
.addGauge(Interns.info(NUM_MASTER_WALS_NAME, NUM_MASTER_WALS_DESC),
masterWrapper.getNumWALFiles());
}
metricsRegistry.snapshot(metricsRecordBuilder, all);
}
}

View File

@ -0,0 +1,18 @@
# 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.
#
org.apache.hadoop.hbase.master.MetricsMasterProcSourceFactoryImpl

View File

@ -0,0 +1,46 @@
/**
* 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.master;
import org.apache.hadoop.hbase.CompatibilitySingletonFactory;
import org.apache.hadoop.hbase.testclassification.MetricsTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
/**
* Test for MetricsMasterProcSourceImpl
*/
@Category({MetricsTests.class, SmallTests.class})
public class TestMetricsMasterProcSourceImpl {
@Test
public void testGetInstance() throws Exception {
MetricsMasterProcSourceFactory metricsMasterProcSourceFactory = CompatibilitySingletonFactory
.getInstance(MetricsMasterProcSourceFactory.class);
MetricsMasterProcSource masterProcSource = metricsMasterProcSourceFactory.create(null);
assertTrue(masterProcSource instanceof MetricsMasterProcSourceImpl);
assertSame(metricsMasterProcSourceFactory,
CompatibilitySingletonFactory.getInstance(MetricsMasterProcSourceFactory.class));
}
}

View File

@ -121,7 +121,7 @@ public class ProcedureWALFile implements Comparable<ProcedureWALFile> {
}
public long getSize() {
return logStatus.getLen();
return logStatus != null ? logStatus.getLen() : 0;
}
public void removeFile() throws IOException {

View File

@ -2186,6 +2186,10 @@ public class HMaster extends HRegionServer implements MasterServices, Server {
return masterActiveTime;
}
public int getNumWALFiles() {
return procedureStore != null ? procedureStore.getActiveLogs().size() : 0;
}
public int getRegionServerInfoPort(final ServerName sn) {
RegionServerInfo info = this.regionServerTracker.getRegionServerInfo(sn);
if (info == null || info.getInfoPort() == 0) {

View File

@ -23,9 +23,6 @@ import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hbase.classification.InterfaceAudience;
import org.apache.hadoop.hbase.classification.InterfaceStability;
import org.apache.hadoop.hbase.CompatibilitySingletonFactory;
import org.apache.hadoop.hbase.master.MetricsMasterSource;
import org.apache.hadoop.hbase.master.MetricsMasterSourceFactory;
import org.apache.hadoop.hbase.master.MetricsMasterWrapper;
/**
* This class is for maintaining the various master statistics
@ -39,9 +36,12 @@ import org.apache.hadoop.hbase.master.MetricsMasterWrapper;
public class MetricsMaster {
private static final Log LOG = LogFactory.getLog(MetricsMaster.class);
private MetricsMasterSource masterSource;
private MetricsMasterProcSource masterProcSource;
public MetricsMaster(MetricsMasterWrapper masterWrapper) {
masterSource = CompatibilitySingletonFactory.getInstance(MetricsMasterSourceFactory.class).create(masterWrapper);
masterProcSource =
CompatibilitySingletonFactory.getInstance(MetricsMasterProcSourceFactory.class).create(masterWrapper);
}
// for unit-test usage
@ -49,6 +49,10 @@ public class MetricsMaster {
return masterSource;
}
public MetricsMasterProcSource getMetricsProcSource() {
return masterProcSource;
}
/**
* @param inc How much to add to requests.
*/

View File

@ -118,4 +118,10 @@ public class MetricsMasterWrapperImpl implements MetricsMasterWrapper {
public boolean getIsActiveMaster() {
return master.isActiveMaster();
}
@Override
public long getNumWALFiles() {
return master.getNumWALFiles();
}
}

View File

@ -129,4 +129,10 @@ public class TestMasterMetrics {
metricsHelper.assertTag("clusterId", master.getClusterId(), masterSource);
metricsHelper.assertTag("zookeeperQuorum", master.getZooKeeper().getQuorum(), masterSource);
}
@Test
public void testDefaultMasterProcMetrics() throws Exception {
MetricsMasterProcSource masterSource = master.getMasterMetrics().getMetricsProcSource();
metricsHelper.assertGauge("numMasterWALs", master.getNumWALFiles(), masterSource);
}
}

View File

@ -73,5 +73,6 @@ public class TestMasterMetricsWrapper {
}
assertEquals(4, info.getNumRegionServers());
assertEquals(1, info.getNumDeadRegionServers());
assertEquals(1, info.getNumWALFiles());
}
}
}