Index: src/java/org/apache/hadoop/hbase/metrics/MetricsRate.java =================================================================== --- src/java/org/apache/hadoop/hbase/metrics/MetricsRate.java (revision 799219) +++ src/java/org/apache/hadoop/hbase/metrics/MetricsRate.java (working copy) @@ -20,25 +20,32 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.metrics.MetricsRecord; +import org.apache.hadoop.metrics.util.MetricsBase; +import org.apache.hadoop.metrics.util.MetricsRegistry; import org.apache.hadoop.util.StringUtils; /** * Publishes a rate based on a counter - you increment the counter each * time an event occurs (eg: an RPC call) and this publishes a rate. */ -public class MetricsRate { +public class MetricsRate extends MetricsBase { private static final Log LOG = LogFactory.getLog("org.apache.hadoop.hbase.metrics"); - private String name; private int value; private float prevRate; private long ts; - public MetricsRate(final String name) { - this.name = name; + public MetricsRate(final String name, final MetricsRegistry registry, + final String description) { + super(name, description); this.value = 0; this.prevRate = 0; this.ts = System.currentTimeMillis(); + registry.add(name, this); + } + + public MetricsRate(final String name, final MetricsRegistry registry) { + this(name, registry, NO_DESCRIPTION); } public synchronized void inc(final int incr) { @@ -58,15 +65,17 @@ this.ts = now; } + @Override public synchronized void pushMetric(final MetricsRecord mr) { intervalHeartBeat(); try { - mr.setMetric(name, getPreviousIntervalValue()); + mr.setMetric(getName(), getPreviousIntervalValue()); } catch (Exception e) { - LOG.info("pushMetric failed for " + name + "\n" + + LOG.info("pushMetric failed for " + getName() + "\n" + StringUtils.stringifyException(e)); } } + public synchronized float getPreviousIntervalValue() { return this.prevRate; } Index: src/java/org/apache/hadoop/hbase/master/metrics/MasterMetrics.java =================================================================== --- src/java/org/apache/hadoop/hbase/master/metrics/MasterMetrics.java (revision 832376) +++ src/java/org/apache/hadoop/hbase/master/metrics/MasterMetrics.java (working copy) @@ -19,12 +19,12 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.hadoop.hbase.metrics.MetricsRate; import org.apache.hadoop.metrics.MetricsContext; import org.apache.hadoop.metrics.MetricsRecord; import org.apache.hadoop.metrics.MetricsUtil; import org.apache.hadoop.metrics.Updater; import org.apache.hadoop.metrics.jvm.JvmMetrics; -import org.apache.hadoop.metrics.util.MetricsIntValue; import org.apache.hadoop.metrics.util.MetricsRegistry; @@ -43,8 +43,8 @@ /* * Count of requests to the cluster since last call to metrics update */ - private final MetricsIntValue cluster_requests = - new MetricsIntValue("cluster_requests", registry); + private final MetricsRate cluster_requests = + new MetricsRate("cluster_requests", registry); public MasterMetrics(final String name) { MetricsContext context = MetricsUtil.getContext("hbase"); @@ -71,11 +71,7 @@ */ public void doUpdates(MetricsContext unused) { synchronized (this) { - synchronized(this.cluster_requests) { - this.cluster_requests.pushMetric(metricsRecord); - // Set requests down to zero again. - this.cluster_requests.set(0); - } + this.cluster_requests.pushMetric(metricsRecord); } this.metricsRecord.update(); } @@ -87,16 +83,14 @@ /** * @return Count of requests. */ - public int getRequests() { - return this.cluster_requests.get(); + public float getRequests() { + return this.cluster_requests.getPreviousIntervalValue(); } /** * @param inc How much to add to requests. */ public void incrementRequests(final int inc) { - synchronized(this.cluster_requests) { - this.cluster_requests.set(this.cluster_requests.get() + inc); - } + this.cluster_requests.inc(inc); } } \ No newline at end of file Index: src/java/org/apache/hadoop/hbase/regionserver/metrics/RegionServerMetrics.java =================================================================== --- src/java/org/apache/hadoop/hbase/regionserver/metrics/RegionServerMetrics.java (revision 832376) +++ src/java/org/apache/hadoop/hbase/regionserver/metrics/RegionServerMetrics.java (working copy) @@ -81,7 +81,7 @@ /* * Count of requests to the regionservers since last call to metrics update */ - private final MetricsRate requests = new MetricsRate("requests"); + private final MetricsRate requests = new MetricsRate("requests", registry); /** * Count of stores open on the regionserver.