diff --git a/CHANGES.txt b/CHANGES.txt index 05466fa181f..d81a17cbca7 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -34,6 +34,7 @@ Release 0.21.0 - Unreleased HBASE-1800 Too many ZK connections HBASE-1819 Update to 0.20.1 hadoop and zk 3.2.1 HBASE-1820 Update jruby from 1.2 to 1.3.1 + HBASE-1722 Add support for exporting HBase metrics via JMX OPTIMIZATIONS HBASE-1765 Delay Result deserialization until asked for and permit diff --git a/src/docs/src/documentation/content/xdocs/metrics.xml b/src/docs/src/documentation/content/xdocs/metrics.xml index c8744f438de..b01d7bd06cc 100644 --- a/src/docs/src/documentation/content/xdocs/metrics.xml +++ b/src/docs/src/documentation/content/xdocs/metrics.xml @@ -63,5 +63,118 @@ in ganglia, the stats are aggregated rather than reported per instance.

+ +
+ Using with JMX +

+ In addition to the standard output contexts supported by the Hadoop + metrics package, you can also export HBase metrics via Java Management + Extensions (JMX). This will allow viewing HBase stats in JConsole or + any other JMX client. +

+
+ Enable HBase stats collection +

+ To enable JMX support in HBase, first edit + $HBASE_HOME/conf/hadoop-metrics.properties to support + metrics refreshing. (If you've already configured + hadoop-metrics.properties for another output context, + you can skip this step). +

+ +# Configuration of the "hbase" context for null +hbase.class=org.apache.hadoop.metrics.spi.NullContextWithUpdateThread +hbase.period=60 + +# Configuration of the "jvm" context for null +jvm.class=org.apache.hadoop.metrics.spi.NullContextWithUpdateThread +jvm.period=60 + +# Configuration of the "rpc" context for null +rpc.class=org.apache.hadoop.metrics.spi.NullContextWithUpdateThread +rpc.period=60 + +
+
+ Setup JMX remote access +

+ For remote access, you will need to configure JMX remote passwords + and access profiles. Create the files: +

+
+
$HBASE_HOME/conf/jmxremote.passwd (set permissions + to 600)
+
+ +monitorRole monitorpass +controlRole controlpass + +
+ +
$HBASE_HOME/conf/jmxremote.access
+
+ +monitorRole readonly +controlRole readwrite + +
+
+
+
+ Configure JMX in HBase startup +

+ Finally, edit the $HBASE_HOME/conf/hbase-env.sh and + $HBASE_HOME/bin/hbase scripts for JMX support: +

+
+
$HBASE_HOME/conf/hbase-env.sh
+
+

Add the lines:

+ +JMX_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.ssl=false" +JMX_OPTS="$JMX_OPTS -Dcom.sun.management.jmxremote.password.file=$HBASE_HOME/conf/jmxremote.passwd" +JMX_OPTS="$JMX_OPTS -Dcom.sun.management.jmxremote.access.file=$HBASE_HOME/conf/jmxremote.access" + +export HBASE_MASTER_OPTS="$JMX_OPTS -Dcom.sun.management.jmxremote.port=10101" +export HBASE_REGIONSERVER_OPTS="$JMX_OPTS -Dcom.sun.management.jmxremote.port=10102" + +
+
$HBASE_HOME/bin/hbase
+
+

Towards the end of the script, replace the lines:

+ + # figure out which class to run +if [ "$COMMAND" = "shell" ] ; then + CLASS="org.jruby.Main ${HBASE_HOME}/bin/hirb.rb" +elif [ "$COMMAND" = "master" ] ; then + CLASS='org.apache.hadoop.hbase.master.HMaster' +elif [ "$COMMAND" = "regionserver" ] ; then + CLASS='org.apache.hadoop.hbase.regionserver.HRegionServer' + +

+ with the lines: (adding the "HBASE_OPTS=..." lines for "master" and + "regionserver" commands) +

+ + # figure out which class to run +if [ "$COMMAND" = "shell" ] ; then + CLASS="org.jruby.Main ${HBASE_HOME}/bin/hirb.rb" +elif [ "$COMMAND" = "master" ] ; then + CLASS='org.apache.hadoop.hbase.master.HMaster' + HBASE_OPTS="$HBASE_OPTS $HBASE_MASTER_OPTS" +elif [ "$COMMAND" = "regionserver" ] ; then + CLASS='org.apache.hadoop.hbase.regionserver.HRegionServer' + HBASE_OPTS="$HBASE_OPTS $HBASE_REGIONSERVER_OPTS" + +
+
+

+ After restarting the processes you want to monitor, you should now be + able to run JConsole (included with the JDK since JDK 5.0) to view + the statistics via JMX. HBase MBeans are exported under the + hadoop domain in JMX. +

+
+
diff --git a/src/java/org/apache/hadoop/hbase/ipc/HBaseRpcMetrics.java b/src/java/org/apache/hadoop/hbase/ipc/HBaseRpcMetrics.java index fcfd1394381..950d02a4390 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 4d527b0a5b1..62d7cf3888c 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/regionserver/metrics/RegionServerMetrics.java b/src/java/org/apache/hadoop/hbase/regionserver/metrics/RegionServerMetrics.java index 52ab21ffffe..49e81972496 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 }