Index: hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/MetricsSource.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/MetricsSource.java (revision ) +++ hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/MetricsSource.java (revision ) @@ -0,0 +1,26 @@ +/** + * 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.metrics; + +/** + * TODO + */ +public interface MetricsSource { + MetricsRegistry getRegistry(); +} Index: hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/MutableCounterLong.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/MutableCounterLong.java (revision ) +++ hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/MutableCounterLong.java (revision ) @@ -0,0 +1,27 @@ +/** + * 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.metrics; + +/** + * TODO + */ +public interface MutableCounterLong { + void inc(); + void inc(long delta); +} Index: hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/JvmMetricsSourceFactory.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/JvmMetricsSourceFactory.java (revision ) +++ hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/JvmMetricsSourceFactory.java (revision ) @@ -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.metrics; + +import java.util.ServiceLoader; + +/** + * Class to load JvmMetricsSourceFactory from the class path. Will only return a singleton + * instance. + */ +public abstract class JvmMetricsSourceFactory { + + private static JvmMetricsSourceFactory factory = null; + public static final String EXCEPTION_STRING = "Could not create a JvmMetricsSourceFactory metrics source. " + + "Is the hadoop compatibility jar on the classpath?"; + + public abstract void create(String processName, String sessionId); + + /** + * Get the singleton instance of ReplicationMetricsSource + * + * @return the singleton + */ + public static synchronized JvmMetricsSourceFactory getInstance() { + if (factory == null) { + try { + factory = ServiceLoader.load(JvmMetricsSourceFactory.class).iterator().next(); + } catch (Exception e) { + throw new RuntimeException(EXCEPTION_STRING, e); + } catch (Error e) { + throw new RuntimeException(EXCEPTION_STRING, e); + } + + // If there was nothing returned and no exception then throw an exception. + if (factory == null) { + throw new RuntimeException(EXCEPTION_STRING); + } + } + return factory; + } +} Index: hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/MetricsRegistryFactory.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/MetricsRegistryFactory.java (revision ) +++ hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/MetricsRegistryFactory.java (revision ) @@ -0,0 +1,59 @@ +/** + * 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.metrics; + +import java.util.ServiceLoader; + +import org.apache.hadoop.hbase.replication.regionserver.metrics.ReplicationMetricsSource; + +/** + * Class to load MetricsRegistryFactory from the class path. Will only return a singleton + * instance. + */ +public abstract class MetricsRegistryFactory { + + private static MetricsRegistryFactory factory = null; + public static final String EXCEPTION_STRING = "Could not create a MetricsRegistryFactory metrics source. " + + "Is the hadoop compatibility jar on the classpath?"; + + public abstract MetricsRegistry create(String name); + + /** + * Get the singleton instance of ReplicationMetricsSource + * + * @return the singleton + */ + public static synchronized MetricsRegistryFactory getInstance() { + if (factory == null) { + try { + factory = ServiceLoader.load(MetricsRegistryFactory.class).iterator().next(); + } catch (Exception e) { + throw new RuntimeException(EXCEPTION_STRING, e); + } catch (Error e) { + throw new RuntimeException(EXCEPTION_STRING, e); + } + + // If there was nothing returned and no exception then throw an exception. + if (factory == null) { + throw new RuntimeException(EXCEPTION_STRING); + } + } + return factory; + } +} Index: hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/DefaultMetricsSystemFactory.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/DefaultMetricsSystemFactory.java (revision ) +++ hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/DefaultMetricsSystemFactory.java (revision ) @@ -0,0 +1,74 @@ +/** + * 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.metrics; + +import java.util.ServiceLoader; + +/** + * Class to load DefaultMetricsSystemFactory from the class path. Will only return a singleton + * instance. + */ +public abstract class DefaultMetricsSystemFactory { + + private static DefaultMetricsSystemFactory factory = null; + public static final String EXCEPTION_STRING = "Could not create a JvmMetricsSourceFactory metrics source. " + + "Is the hadoop compatibility jar on the classpath?"; + + /** + * Register a metrics source + * @param the actual type of the source object + * @param source object to register + * @param name of the source. Must be unique or null (then extracted from + * the annotations of the source object.) + * @param desc the description of the source (or null. See above.) + * @return the source object + */ + public abstract T register(String name, String desc, T source); + + + /** + * Common static convenience method to initialize the metrics system + * @param prefix for configuration + * @return the metrics system instance + */ + public abstract void initialize(String prefix); + + /** + * Get the singleton instance of ReplicationMetricsSource + * + * @return the singleton + */ + public static synchronized DefaultMetricsSystemFactory getInstance() { + if (factory == null) { + try { + factory = ServiceLoader.load(DefaultMetricsSystemFactory.class).iterator().next(); + } catch (Exception e) { + throw new RuntimeException(EXCEPTION_STRING, e); + } catch (Error e) { + throw new RuntimeException(EXCEPTION_STRING, e); + } + + // If there was nothing returned and no exception then throw an exception. + if (factory == null) { + throw new RuntimeException(EXCEPTION_STRING); + } + } + return factory; + } +} Index: hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/MutableGaugeLong.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/MutableGaugeLong.java (revision ) +++ hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/MutableGaugeLong.java (revision ) @@ -0,0 +1,25 @@ +/** + * 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.metrics; + +/** + * TODO + */ +public interface MutableGaugeLong { +} Index: hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/MetricsRegistry.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/MetricsRegistry.java (revision ) +++ hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/MetricsRegistry.java (revision ) @@ -0,0 +1,70 @@ +/** + * 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.metrics; + +/** + * Metrics registry class for creating and maintaining a + * collection of MetricsMutables, making writing metrics source easier. + * + * This is similar to org.apache.hadoop.metrics2.lib.MetricsRegistry, but + * allows removing metrics. After HADOOP-8313 is implemented, this can be + * substituted with org.apache.hadoop.metrics2.lib.MetricsRegistry. + */ +public interface MetricsRegistry { + /** + * Set the metrics record name + * @param name of the record of the metrics + * @return the registry itself as a convenience + */ + MetricsRegistry setName(String name); + + /** + * Set the metrics context tag + * @param name of the context + * @return the registry itself as a convenience + */ + MetricsRegistry setContext(String name); + + /** + * Add a tag to the metrics + * @param name of the tag + * @param description of the tag + * @param value of the tag + * @return the registry (for keep adding tags) + */ + MetricsRegistry tag(String name, String description, String value); + + /** + * Create a mutable long integer counter + * @param name of the metric + * @param desc metric description + * @param iVal initial value + * @return a new counter object + */ + MutableCounterLong newCounter(String name, String desc, long iVal); + + /** + * Create a mutable long integer gauge + * @param name of the metric + * @param desc metric description + * @param iVal initial value + * @return a new gauge object + */ + MutableGaugeLong newGauge(String name, String desc, long iVal); +} Index: hbase-server/src/main/java/org/apache/hadoop/hbase/master/metrics/MasterMetrics2.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- hbase-server/src/main/java/org/apache/hadoop/hbase/master/metrics/MasterMetrics2.java (revision ) +++ hbase-server/src/main/java/org/apache/hadoop/hbase/master/metrics/MasterMetrics2.java (revision ) @@ -0,0 +1,83 @@ +/** + * 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.metrics; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.metrics.DefaultMetricsSystemFactory; +import org.apache.hadoop.hbase.metrics.JvmMetricsSourceFactory; +import org.apache.hadoop.hbase.metrics.MetricsRegistry; +import org.apache.hadoop.hbase.metrics.MetricsRegistryFactory; +import org.apache.hadoop.hbase.metrics.MetricsSource; +import org.apache.hadoop.hbase.metrics.MutableCounterLong; + +/** + * + * This class is for maintaining the various HMaster statistics + * and publishing them through the metrics interfaces. + * This also registers the JMX MBean for RPC. + *

+ * This class has a number of metrics variables that are publicly accessible; + * these variables (objects) have methods to update their values; + * for example: + *

{@link #clusterRequests#incr()} + * + */ +public class MasterMetrics2 implements MetricsSource { + final String name; + final MetricsRegistry registry = MetricsRegistryFactory.getInstance().create("hmaster"); + + final MutableCounterLong clusterRequests = + registry.newCounter("cluster_requests", "", 0); + + public MasterMetrics2(final String name, final String sessionId) { + this.name = name; + JvmMetricsSourceFactory.getInstance().create("HMaster", sessionId); + registry.setContext(name).tag("sessionId", "", sessionId); + } + + public static MasterMetrics2 create(Configuration conf, + String masterName + ) { + String name = "hmaster-" + masterName; + String sessionId = conf.get("session.id"); + + return DefaultMetricsSystemFactory.getInstance().register("HMaster", "HMaster metrics", + new MasterMetrics2(name, sessionId)); + } + + public String getName() { + return name; + } + + public void incClusterRequests() { + clusterRequests.inc(); + } + + public void incClusterRequests(int delta) { + clusterRequests.inc(delta); + } + + public MutableCounterLong getClusterRequests() { + return clusterRequests; + } + + @Override + public MetricsRegistry getRegistry() { + return registry; + } +} Index: hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java (revision 1363172) +++ hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java (revision ) @@ -79,6 +79,8 @@ import org.apache.hadoop.hbase.MasterMonitorProtocol; import org.apache.hadoop.hbase.MasterAdminProtocol; import org.apache.hadoop.hbase.RegionServerStatusProtocol; +import org.apache.hadoop.hbase.master.metrics.MasterMetrics2; +import org.apache.hadoop.hbase.metrics.DefaultMetricsSystemFactory; import org.apache.hadoop.hbase.protobuf.ProtobufUtil; import org.apache.hadoop.hbase.protobuf.RequestConverter; import org.apache.hadoop.hbase.ipc.ProtocolSignature; @@ -229,6 +231,9 @@ // Metrics for the HMaster private final MasterMetrics metrics; + + private final MasterMetrics2 myMetrics; + // file system manager for the master FS operations private MasterFileSystem fileSystemManager; @@ -354,6 +359,11 @@ this.zooKeeper = new ZooKeeperWatcher(conf, MASTER + ":" + isa.getPort(), this, true); this.rpcServer.startThreads(); this.metrics = new MasterMetrics(getServerName().toString()); + + DefaultMetricsSystemFactory.getInstance().initialize("HMaster"); + // TODO: move to where HMaster starts? + this.myMetrics = MasterMetrics2.create(conf, getServerName().toString()); + // metrics interval: using the same property as region server. this.msgInterval = conf.getInt("hbase.regionserver.msginterval", 3 * 1000);