diff --git a/src/java/org/apache/hadoop/hbase/ipc/HBaseRPCStatistics.java b/src/java/org/apache/hadoop/hbase/ipc/HBaseRPCStatistics.java new file mode 100644 index 0000000..e11f828 --- /dev/null +++ b/src/java/org/apache/hadoop/hbase/ipc/HBaseRPCStatistics.java @@ -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.ipc; + +import javax.management.ObjectName; + +import org.apache.hadoop.metrics.util.MBeanUtil; +import org.apache.hadoop.metrics.util.MetricsDynamicMBeanBase; +import org.apache.hadoop.metrics.util.MetricsRegistry; + +/** + * Exports HBase RPC statistics recorded in {@link HBaseRpcMetrics} as an MBean + * for JMX monitoring. + */ +public class HBaseRPCStatistics extends MetricsDynamicMBeanBase { + private final ObjectName mbeanName; + + public HBaseRPCStatistics(MetricsRegistry registry, + String hostName, String port) { + super(registry, "HBaseRPCStatistics"); + + String name = String.format("RPCStatistics-%s", + (port != null ? port : "unknown")); + + mbeanName = MBeanUtil.registerMBean("HBase", name, this); + } + + public void shutdown() { + if (mbeanName != null) + MBeanUtil.unregisterMBean(mbeanName); + } + +} diff --git a/src/java/org/apache/hadoop/hbase/ipc/HBaseRpcMetrics.java b/src/java/org/apache/hadoop/hbase/ipc/HBaseRpcMetrics.java index fcfd139..950d02a 100644 --- a/src/java/org/apache/hadoop/hbase/ipc/HBaseRpcMetrics.java +++ b/src/java/org/apache/hadoop/hbase/ipc/HBaseRpcMetrics.java @@ -47,6 +47,7 @@ import org.apache.hadoop.metrics.util.MetricsRegistry; public class HBaseRpcMetrics implements Updater { private MetricsRecord metricsRecord; private static Log LOG = LogFactory.getLog(HBaseRpcMetrics.class); + private final HBaseRPCStatistics rpcStatistics; public HBaseRpcMetrics(String hostName, String port) { MetricsContext context = MetricsUtil.getContext("rpc"); @@ -58,6 +59,8 @@ public class HBaseRpcMetrics implements Updater { + hostName + ", port=" + port); context.registerUpdater(this); + + rpcStatistics = new HBaseRPCStatistics(this.registry, hostName, port); } @@ -110,6 +113,7 @@ public class HBaseRpcMetrics implements Updater { } public void shutdown() { - // Nothing to do + if (rpcStatistics != null) + rpcStatistics.shutdown(); } } \ No newline at end of file diff --git a/src/java/org/apache/hadoop/hbase/master/metrics/MasterMetrics.java b/src/java/org/apache/hadoop/hbase/master/metrics/MasterMetrics.java index 4d527b0..62d7cf3 100644 --- a/src/java/org/apache/hadoop/hbase/master/metrics/MasterMetrics.java +++ b/src/java/org/apache/hadoop/hbase/master/metrics/MasterMetrics.java @@ -39,6 +39,7 @@ public class MasterMetrics implements Updater { private final Log LOG = LogFactory.getLog(this.getClass()); private final MetricsRecord metricsRecord; private final MetricsRegistry registry = new MetricsRegistry(); + private final MasterStatistics masterStatistics; /* * Count of requests to the cluster since last call to metrics update */ @@ -52,11 +53,16 @@ public class MasterMetrics implements Updater { metricsRecord.setTag("Master", name); context.registerUpdater(this); JvmMetrics.init("Master", name); + + // expose the MBean for metrics + masterStatistics = new MasterStatistics(this.registry); + LOG.info("Initialized"); } public void shutdown() { - // nought to do. + if (masterStatistics != null) + masterStatistics.shutdown(); } /** diff --git a/src/java/org/apache/hadoop/hbase/master/metrics/MasterStatistics.java b/src/java/org/apache/hadoop/hbase/master/metrics/MasterStatistics.java new file mode 100644 index 0000000..f172b29 --- /dev/null +++ b/src/java/org/apache/hadoop/hbase/master/metrics/MasterStatistics.java @@ -0,0 +1,42 @@ +/** + * 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 javax.management.ObjectName; + +import org.apache.hadoop.metrics.util.MBeanUtil; +import org.apache.hadoop.metrics.util.MetricsDynamicMBeanBase; +import org.apache.hadoop.metrics.util.MetricsRegistry; + +/** + * Exports the {@link MasterMetrics} statistics as an MBean + * for JMX. + */ +public class MasterStatistics extends MetricsDynamicMBeanBase { + private final ObjectName mbeanName; + + public MasterStatistics(MetricsRegistry registry) { + super(registry, "MasterStatistics"); + mbeanName = MBeanUtil.registerMBean("Master", "MasterStatistics", this); + } + + public void shutdown() { + if (mbeanName != null) + MBeanUtil.unregisterMBean(mbeanName); + } +} diff --git a/src/java/org/apache/hadoop/hbase/regionserver/metrics/RegionServerMetrics.java b/src/java/org/apache/hadoop/hbase/regionserver/metrics/RegionServerMetrics.java index 52ab21f..49e8197 100644 --- a/src/java/org/apache/hadoop/hbase/regionserver/metrics/RegionServerMetrics.java +++ b/src/java/org/apache/hadoop/hbase/regionserver/metrics/RegionServerMetrics.java @@ -47,6 +47,7 @@ public class RegionServerMetrics implements Updater { private long lastUpdate = System.currentTimeMillis(); private static final int MB = 1024*1024; private MetricsRegistry registry = new MetricsRegistry(); + private final RegionServerStatistics statistics; public final MetricsTimeVaryingRate atomicIncrementTime = new MetricsTimeVaryingRate("atomicIncrementTime", registry); @@ -112,13 +113,18 @@ public class RegionServerMetrics implements Updater { context.registerUpdater(this); // Add jvmmetrics. JvmMetrics.init("RegionServer", name); + + // export for JMX + statistics = new RegionServerStatistics(this.registry, name); + LOG.info("Initialized"); } - + public void shutdown() { - // nought to do. + if (statistics != null) + statistics.shutdown(); } - + /** * Since this object is a registered updater, this method will be called * periodically, e.g. every 5 seconds. @@ -141,7 +147,7 @@ public class RegionServerMetrics implements Updater { this.metricsRecord.update(); this.lastUpdate = System.currentTimeMillis(); } - + public void resetAllMinMax() { // Nothing to do } diff --git a/src/java/org/apache/hadoop/hbase/regionserver/metrics/RegionServerStatistics.java b/src/java/org/apache/hadoop/hbase/regionserver/metrics/RegionServerStatistics.java new file mode 100644 index 0000000..79467e1 --- /dev/null +++ b/src/java/org/apache/hadoop/hbase/regionserver/metrics/RegionServerStatistics.java @@ -0,0 +1,45 @@ +/** + * 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 javax.management.ObjectName; + +import org.apache.hadoop.metrics.util.MBeanUtil; +import org.apache.hadoop.metrics.util.MetricsDynamicMBeanBase; +import org.apache.hadoop.metrics.util.MetricsRegistry; + +/** + * Exports metrics recorded by {@link RegionServerMetrics} as an MBean + * for JMX monitoring. + */ +public class RegionServerStatistics extends MetricsDynamicMBeanBase { + + private final ObjectName mbeanName; + + public RegionServerStatistics(MetricsRegistry registry, String rsName) { + super(registry, "RegionServerStatistics"); + mbeanName = MBeanUtil.registerMBean("RegionServer", + "RegionServerStatistics", this); + } + + public void shutdown() { + if (mbeanName != null) + MBeanUtil.unregisterMBean(mbeanName); + } + +} \ No newline at end of file