diff --git src/main/java/org/apache/hadoop/hbase/master/HMaster.java src/main/java/org/apache/hadoop/hbase/master/HMaster.java index 9d21903..c11ae8e 100644 --- src/main/java/org/apache/hadoop/hbase/master/HMaster.java +++ src/main/java/org/apache/hadoop/hbase/master/HMaster.java @@ -29,6 +29,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.Map.Entry; import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; @@ -36,6 +37,10 @@ import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; +import javax.management.NotCompliantMBeanException; +import javax.management.ObjectName; +import javax.management.StandardMBean; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; @@ -69,7 +74,7 @@ import org.apache.hadoop.hbase.ipc.HMasterInterface; import org.apache.hadoop.hbase.ipc.HMasterRegionInterface; import org.apache.hadoop.hbase.ipc.ProtocolSignature; import org.apache.hadoop.hbase.ipc.RpcServer; -import org.apache.hadoop.hbase.master.CatalogJanitor.SplitParentFirstComparator; +import org.apache.hadoop.hbase.master.AssignmentManager.RegionState; import org.apache.hadoop.hbase.master.handler.CreateTableHandler; import org.apache.hadoop.hbase.master.handler.DeleteTableHandler; import org.apache.hadoop.hbase.master.handler.DisableTableHandler; @@ -80,6 +85,7 @@ import org.apache.hadoop.hbase.master.handler.TableAddFamilyHandler; import org.apache.hadoop.hbase.master.handler.TableDeleteFamilyHandler; import org.apache.hadoop.hbase.master.handler.TableModifyFamilyHandler; import org.apache.hadoop.hbase.master.metrics.MasterMetrics; +import org.apache.hadoop.hbase.metrics.HBaseMasterMXBean; import org.apache.hadoop.hbase.monitoring.MemoryBoundedLogMessageBuffer; import org.apache.hadoop.hbase.monitoring.MonitoredTask; import org.apache.hadoop.hbase.monitoring.TaskMonitor; @@ -101,9 +107,11 @@ import org.apache.hadoop.hbase.zookeeper.RegionServerTracker; import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher; import org.apache.hadoop.io.MapWritable; import org.apache.hadoop.io.Text; +import org.apache.hadoop.metrics2.util.MBeans; import org.apache.hadoop.net.DNS; import org.apache.zookeeper.KeeperException; import org.apache.zookeeper.Watcher; +import org.mortbay.util.ajax.JSON; /** * HMaster is the "master server" for HBase. An HBase cluster has one active @@ -123,7 +131,8 @@ import org.apache.zookeeper.Watcher; * @see Watcher */ public class HMaster extends HasThread -implements HMasterInterface, HMasterRegionInterface, MasterServices, Server { +implements HMasterInterface, HMasterRegionInterface, MasterServices, +Server, HBaseMasterMXBean { private static final Log LOG = LogFactory.getLog(HMaster.class.getName()); // MASTER is name of the webapp and the attribute name used stuffing this @@ -544,6 +553,8 @@ implements HMasterInterface, HMasterRegionInterface, MasterServices, Server { // Schema janitor chore. this.schemaJanitorChore = getAndStartSchemaJanitorChore(this); + + registerMBean(); status.markComplete("Initialization successful"); LOG.info("Master has completed initialization"); @@ -1387,10 +1398,6 @@ implements HMasterInterface, HMasterRegionInterface, MasterServices, Server { this.getCoprocessors()); } - public String getClusterId() { - return fileSystemManager.getClusterId(); - } - /** * The set of loaded coprocessors is stored in a static set. Since it's * statically allocated, it does not require that HMaster's cpHost be @@ -1401,20 +1408,6 @@ implements HMasterInterface, HMasterRegionInterface, MasterServices, Server { public static String getLoadedCoprocessors() { return CoprocessorHost.getLoadedCoprocessors().toString(); } - - /** - * @return timestamp in millis when HMaster was started. - */ - public long getMasterStartTime() { - return masterStartTime; - } - - /** - * @return timestamp in millis when HMaster became the active master. - */ - public long getMasterActiveTime() { - return masterActiveTime; - } /** * @return array of coprocessor SimpleNames. @@ -1567,6 +1560,9 @@ implements HMasterInterface, HMasterRegionInterface, MasterServices, Server { LOG.error("Error call master coprocessor preShutdown()", ioe); } } + if (mxBean != null) { + MBeans.unregister(mxBean); + } if (this.assignmentManager != null) this.assignmentManager.shutdown(); if (this.serverManager != null) this.serverManager.shutdownCluster(); try { @@ -1769,4 +1765,76 @@ implements HMasterInterface, HMasterRegionInterface, MasterServices, Server { VersionInfo.logVersion(); new HMasterCommandLine(HMaster.class).doMain(args); } + + private ObjectName mxBean = null; + + void registerMBean() { + mxBean = MBeans.register("HBase", "HBaseMasterInfo", this); + LOG.info("Registered HBaseMasterMXBean"); + } + + @Override + public String getClusterId() { + return fileSystemManager.getClusterId(); + } + + @Override + public String getZookeeperQuorumInfo() { + return getZooKeeperWatcher().getQuorum(); + } + + @Override + public String getCoprocessorsInfo() { + return JSON.toString(getCoprocessors()); + } + + /** + * @return timestamp in millis when HMaster was started. + */ + @Override + public long getMasterStartTime() { + return masterStartTime; + } + + /** + * @return timestamp in millis when HMaster became the active master. + */ + @Override + public long getMasterActiveTime() { + return masterActiveTime; + } + + @Override + public String getRegionServers() { + final Map info = new HashMap(); + for (Entry entry : + getServerManager().getOnlineServers().entrySet()) { + final Map innerinfo = new HashMap(); + innerinfo.put("startcode", entry.getKey().getStartcode()); + innerinfo.put("requestsPerSecond", + entry.getValue().getNumberOfRequests()); + innerinfo.put("numberOfOnlineRegions", + entry.getValue().getNumberOfRegions()); + innerinfo.put("usedHeapMB", entry.getValue().getUsedHeapMB()); + innerinfo.put("maxHeapMB", entry.getValue().getMaxHeapMB()); + info.put(entry.getKey().getHostAndPort(), innerinfo); + } + return JSON.toString(info); + } + + @Override + public String getDeadRegionServers() { + return JSON.toString(getServerManager().getDeadServers().toArray()); + } + + @Override + public String getRegionsInTransition() { + final Map info = new HashMap(); + for (Entry entry : + getAssignmentManager().getRegionsInTransition().entrySet()) { + info.put(entry.getKey(), entry.getValue().getState().toString()); + } + return JSON.toString(info); + } + } diff --git src/main/java/org/apache/hadoop/hbase/metrics/HBaseMasterMXBean.java src/main/java/org/apache/hadoop/hbase/metrics/HBaseMasterMXBean.java new file mode 100644 index 0000000..ba45907 --- /dev/null +++ src/main/java/org/apache/hadoop/hbase/metrics/HBaseMasterMXBean.java @@ -0,0 +1,76 @@ +/** + * Copyright 2012 The Apache Software Foundation + * + * 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; + +/** + * + * This is the JMX management interface for Hbase master information + */ +public interface HBaseMasterMXBean { + + /** + * Get the Cluster ID + * @return Cluster ID + */ + public String getClusterId(); + + /** + * Get the Zookeeper Quorum Info + * @return Zookeeper Quorum Info + */ + public String getZookeeperQuorumInfo(); + + /** + * Get the co-processors + * @return Co-processors + */ + public String getCoprocessorsInfo(); + + /** + * Get hbase master start time + * @return Start time of master in milliseconds + */ + public long getMasterStartTime(); + + /** + * Get the hbase master active time + * @return Time in milliseconds when master became active + */ + public long getMasterActiveTime(); + + /** + * Get the live region servers + * @return Live region servers + */ + public String getRegionServers(); + + /** + * Get the dead region servers + * @return Dead region Servers + */ + public String getDeadRegionServers(); + + /** + * Get information on regions in transition + * @return Regions in transition + */ + public String getRegionsInTransition(); + +}