Index: hbase-server/src/main/java/org/apache/hadoop/hbase/master/metrics/MasterMetrics.java =================================================================== --- hbase-server/src/main/java/org/apache/hadoop/hbase/master/metrics/MasterMetrics.java (revision 1387351) +++ hbase-server/src/main/java/org/apache/hadoop/hbase/master/metrics/MasterMetrics.java (working copy) @@ -51,8 +51,8 @@ * @param size length of original HLogs that were split */ public synchronized void addSplit(long time, long size) { - //TODO use new metrics histogram - + masterMetricsSource.updateSplitTime(time); + masterMetricsSource.updateSplitSize(size); } /** Index: hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/metrics/BaseMetricsSourceImpl.java =================================================================== --- hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/metrics/BaseMetricsSourceImpl.java (revision 1387351) +++ hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/metrics/BaseMetricsSourceImpl.java (working copy) @@ -27,6 +27,8 @@ import org.apache.hadoop.metrics2.lib.MetricMutable; import org.apache.hadoop.metrics2.lib.MetricMutableCounterLong; import org.apache.hadoop.metrics2.lib.MetricMutableGaugeLong; +import org.apache.hadoop.metrics2.lib.MetricMutableHistogram; +import org.apache.hadoop.metrics2.lib.MetricMutableQuantiles; import org.apache.hadoop.metrics2.source.JvmMetricsSource; import java.util.Map; @@ -128,6 +130,18 @@ } + @Override + public void updateHistogram(String name, long value) { + MetricMutableHistogram histo = metricsRegistry.getHistogram(name); + histo.add(value); + } + + @Override + public void updateQuantile(String name, long value) { + MetricMutableQuantiles histo = metricsRegistry.getQuantile(name); + histo.add(value); + } + /** * Remove a named gauge. * Index: hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/master/metrics/MasterMetricsSourceImpl.java =================================================================== --- hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/master/metrics/MasterMetricsSourceImpl.java (revision 1387351) +++ hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/master/metrics/MasterMetricsSourceImpl.java (working copy) @@ -25,6 +25,7 @@ import org.apache.hadoop.metrics2.MetricsRecordBuilder; import org.apache.hadoop.metrics2.lib.MetricMutableCounterLong; import org.apache.hadoop.metrics2.lib.MetricMutableGaugeLong; +import org.apache.hadoop.metrics2.lib.MetricMutableHistogram; /** Hadoop1 implementation of MasterMetricsSource. */ public class MasterMetricsSourceImpl @@ -38,6 +39,8 @@ MetricMutableGaugeLong ritOldestAgeGauge; private final MasterMetricsWrapper masterWrapper; + private MetricMutableHistogram splitTimeHisto; + private MetricMutableHistogram splitSizeHisto; public MasterMetricsSourceImpl(MasterMetricsWrapper masterWrapper) { this(METRICS_NAME, METRICS_DESCRIPTION, METRICS_CONTEXT, METRICS_JMX_CONTEXT, masterWrapper); @@ -50,6 +53,12 @@ MasterMetricsWrapper masterWrapper) { super(metricsName, metricsDescription, metricsContext, metricsJmxContext); this.masterWrapper = masterWrapper; + clusterRequestsCounter = metricsRegistry.newCounter(CLUSTER_REQUESTS_NAME, "", 0l); + ritGauge = metricsRegistry.newGauge(RIT_COUNT_NAME, "", 0l); + ritCountOverThresholdGauge = metricsRegistry.newGauge(RIT_COUNT_OVER_THRESHOLD_NAME, "", 0l); + ritOldestAgeGauge = metricsRegistry.newGauge(RIT_OLDEST_AGE_NAME, "", 0l); + splitTimeHisto = metricsRegistry.newHistogram(SPLIT_SIZE_NAME, SPLIT_SIZE_DESC); + splitSizeHisto = metricsRegistry.newHistogram(SPLIT_TIME_NAME, SPLIT_TIME_DESC); } @Override @@ -77,6 +86,16 @@ ritCountOverThresholdGauge.set(ritCount); } + @Override + public void updateSplitTime(long time) { + splitTimeHisto.add(time); + } + + @Override + public void updateSplitSize(long size) { + splitSizeHisto.add(size); + } + /** * Method to export all the metrics. * Index: hbase-hadoop1-compat/src/main/java/org/apache/hadoop/metrics2/lib/DynamicMetricsRegistry.java =================================================================== --- hbase-hadoop1-compat/src/main/java/org/apache/hadoop/metrics2/lib/DynamicMetricsRegistry.java (revision 1387351) +++ hbase-hadoop1-compat/src/main/java/org/apache/hadoop/metrics2/lib/DynamicMetricsRegistry.java (working copy) @@ -178,6 +178,46 @@ } /** + * Create a new histogram. + * @param name Name of the histogram. + * @return A new MutableHistogram + */ + public MetricMutableHistogram newHistogram(String name) { + return newHistogram(name, ""); + } + + /** + * Create a new histogram. + * @param name The name of the histogram + * @param desc The description of the data in the histogram. + * @return A new MutableHistogram + */ + public MetricMutableHistogram newHistogram(String name, String desc) { + MetricMutableHistogram histo = new MetricMutableHistogram(name, desc); + return addNewMetricIfAbsent(name, histo, MetricMutableHistogram.class); + } + + /** + * Create a new MutableQuantile(A more accurate histogram). + * @param name The name of the histogram + * @return a new MutableQuantile + */ + public MetricMutableQuantiles newQuantile(String name) { + return newQuantile(name, ""); + } + + /** + * Create a new MutableQuantile(A more accurate histogram). + * @param name The name of the histogram + * @param desc Description of the data. + * @return a new MutableQuantile + */ + public MetricMutableQuantiles newQuantile(String name, String desc) { + MetricMutableQuantiles histo = new MetricMutableQuantiles(name, desc); + return addNewMetricIfAbsent(name, histo, MetricMutableQuantiles.class); + } + + /** * Set the metrics context tag * @param name of the context * @return the registry itself as a convenience @@ -277,7 +317,7 @@ if (metric == null) { //Create the potential new gauge. - MetricMutableGaugeLong newGauge = new MetricMutableGaugeLong(gaugeName, "", + MetricMutableGaugeLong newGauge = mf.newGauge(gaugeName, "", potentialStartingValue); // Try and put the gauge in. This is atomic. @@ -313,7 +353,7 @@ MetricMutable counter = metricsMap.get(counterName); if (counter == null) { MetricMutableCounterLong newCounter = - new MetricMutableCounterLong(counterName, "", potentialStartingValue); + mf.newCounter(counterName, "", potentialStartingValue); counter = metricsMap.putIfAbsent(counterName, newCounter); if (counter == null) { return newCounter; @@ -328,6 +368,46 @@ return (MetricMutableCounterLong) counter; } + public MetricMutableHistogram getHistogram(String histoName) { + //See getLongGauge for description on how this works. + MetricMutable histo = metricsMap.get(histoName); + if (histo == null) { + MetricMutableHistogram newHisto = + new MetricMutableHistogram(histoName, ""); + histo = metricsMap.putIfAbsent(histoName, newHisto); + if (histo == null) { + return newHisto; + } + } + + if (!(histo instanceof MetricMutableHistogram)) { + throw new MetricsException("Metric already exists in registry for metric name: " + + name + "and not of type MetricMutableHistogram"); + } + + return (MetricMutableHistogram) histo; + } + + public MetricMutableQuantiles getQuantile(String histoName) { + //See getLongGauge for description on how this works. + MetricMutable histo = metricsMap.get(histoName); + if (histo == null) { + MetricMutableQuantiles newHisto = + new MetricMutableQuantiles(histoName, ""); + histo = metricsMap.putIfAbsent(histoName, newHisto); + if (histo == null) { + return newHisto; + } + } + + if (!(histo instanceof MetricMutableQuantiles)) { + throw new MetricsException("Metric already exists in registry for metric name: " + + name + "and not of type MetricMutableQuantiles"); + } + + return (MetricMutableQuantiles) histo; + } + private T addNewMetricIfAbsent(String name, T ret, Index: hbase-hadoop1-compat/pom.xml =================================================================== --- hbase-hadoop1-compat/pom.xml (revision 1387351) +++ hbase-hadoop1-compat/pom.xml (working copy) @@ -94,6 +94,10 @@ + com.yammer.metrics + metrics-core + + org.apache.hadoop hadoop-test ${hadoop-one.version} Index: hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/metrics/BaseMetricsSourceImpl.java =================================================================== --- hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/metrics/BaseMetricsSourceImpl.java (revision 1387351) +++ hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/metrics/BaseMetricsSourceImpl.java (working copy) @@ -22,8 +22,10 @@ import org.apache.hadoop.metrics2.MetricsSource; import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem; import org.apache.hadoop.metrics2.lib.DynamicMetricsRegistry; +import org.apache.hadoop.metrics2.lib.MetricMutableQuantiles; import org.apache.hadoop.metrics2.lib.MutableCounterLong; import org.apache.hadoop.metrics2.lib.MutableGaugeLong; +import org.apache.hadoop.metrics2.lib.MutableHistogram; import org.apache.hadoop.metrics2.source.JvmMetrics; /** @@ -117,6 +119,18 @@ } + @Override + public void updateHistogram(String name, long value) { + MutableHistogram histo = metricsRegistry.getHistogram(name); + histo.add(value); + } + + @Override + public void updateQuantile(String name, long value) { + MetricMutableQuantiles histo = metricsRegistry.getQuantile(name); + histo.add(value); + } + /** * Remove a named gauge. * Index: hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/master/metrics/MasterMetricsSourceImpl.java =================================================================== --- hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/master/metrics/MasterMetricsSourceImpl.java (revision 1387351) +++ hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/master/metrics/MasterMetricsSourceImpl.java (working copy) @@ -24,16 +24,20 @@ import org.apache.hadoop.metrics2.lib.Interns; import org.apache.hadoop.metrics2.lib.MutableCounterLong; import org.apache.hadoop.metrics2.lib.MutableGaugeLong; +import org.apache.hadoop.metrics2.lib.MutableHistogram; /** Hadoop2 implementation of MasterMetricsSource. */ public class MasterMetricsSourceImpl extends BaseMetricsSourceImpl implements MasterMetricsSource { + MutableCounterLong clusterRequestsCounter; MutableGaugeLong ritGauge; MutableGaugeLong ritCountOverThresholdGauge; MutableGaugeLong ritOldestAgeGauge; private final MasterMetricsWrapper masterWrapper; + private MutableHistogram splitTimeHisto; + private MutableHistogram splitSizeHisto; public MasterMetricsSourceImpl(MasterMetricsWrapper masterMetricsWrapper) { this(METRICS_NAME, @@ -50,6 +54,12 @@ MasterMetricsWrapper masterWrapper) { super(metricsName, metricsDescription, metricsContext, metricsJmxContext); this.masterWrapper = masterWrapper; + clusterRequestsCounter = metricsRegistry.newCounter(CLUSTER_REQUESTS_NAME, "", 0l); + ritGauge = metricsRegistry.newGauge(RIT_COUNT_NAME, "", 0l); + ritCountOverThresholdGauge = metricsRegistry.newGauge(RIT_COUNT_OVER_THRESHOLD_NAME, "", 0l); + ritOldestAgeGauge = metricsRegistry.newGauge(RIT_OLDEST_AGE_NAME, "", 0l); + splitTimeHisto = metricsRegistry.newHistogram(SPLIT_SIZE_NAME, SPLIT_SIZE_DESC); + splitSizeHisto = metricsRegistry.newHistogram(SPLIT_TIME_NAME, SPLIT_TIME_DESC); } @Override @@ -78,6 +88,16 @@ } @Override + public void updateSplitTime(long time) { + splitTimeHisto.add(time); + } + + @Override + public void updateSplitSize(long size) { + splitSizeHisto.add(size); + } + + @Override public void getMetrics(MetricsCollector metricsCollector, boolean all) { MetricsRecordBuilder metricsRecordBuilder = metricsCollector.addRecord(metricsName) Index: hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/DynamicMetricsRegistry.java =================================================================== --- hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/DynamicMetricsRegistry.java (revision 1387351) +++ hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/DynamicMetricsRegistry.java (working copy) @@ -250,10 +250,43 @@ } } MutableRate ret = new MutableRate(name, desc, extended); - metricsMap.put(name, ret); - return ret; + return addNewMetricIfAbsent(name, ret, MutableRate.class); } + /** + * Create a new histogram. + * @param name Name of the histogram. + * @return A new MutableHistogram + */ + public MutableHistogram newHistogram(String name) { + return newHistogram(name, ""); + } + + /** + * Create a new histogram. + * @param name The name of the histogram + * @param desc The description of the data in the histogram. + * @return A new MutableHistogram + */ + public MutableHistogram newHistogram(String name, String desc) { + MutableHistogram histo = new MutableHistogram(name, desc); + return addNewMetricIfAbsent(name, histo, MutableHistogram.class); + } + + /** + * Create a new MutableQuantile(A more accurate histogram). + * @param name The name of the histogram + * @return a new MutableQuantile + */ + public MetricMutableQuantiles newQuantile(String name) { + return newQuantile(name, ""); + } + + public MetricMutableQuantiles newQuantile(String name, String desc) { + MetricMutableQuantiles histo = new MetricMutableQuantiles(name, desc, "Ops", "", 60); + return addNewMetricIfAbsent(name, histo, MetricMutableQuantiles.class); + } + synchronized void add(String name, MutableMetric metric) { addNewMetricIfAbsent(name, metric, MutableMetric.class); } @@ -440,6 +473,48 @@ return (MutableCounterLong) counter; } + public MutableHistogram getHistogram(String histoName) { + //See getLongGauge for description on how this works. + MutableMetric histo = metricsMap.get(histoName); + if (histo == null) { + MutableHistogram newCounter = + new MutableHistogram(Interns.info(histoName, "")); + histo = metricsMap.putIfAbsent(histoName, newCounter); + if (histo == null) { + return newCounter; + } + } + + + if (!(histo instanceof MutableHistogram)) { + throw new MetricsException("Metric already exists in registry for metric name: " + + histoName + " and not of type MutableHistogram"); + } + + return (MutableHistogram) histo; + } + + public MetricMutableQuantiles getQuantile(String histoName) { + //See getLongGauge for description on how this works. + MutableMetric histo = metricsMap.get(histoName); + if (histo == null) { + MetricMutableQuantiles newCounter = + new MetricMutableQuantiles(histoName, "", "Ops", "", 60); + histo = metricsMap.putIfAbsent(histoName, newCounter); + if (histo == null) { + return newCounter; + } + } + + + if (!(histo instanceof MetricMutableQuantiles)) { + throw new MetricsException("Metric already exists in registry for metric name: " + + histoName + " and not of type MutableHistogram"); + } + + return (MetricMutableQuantiles) histo; + } + private T addNewMetricIfAbsent(String name, T ret, Index: hbase-hadoop2-compat/pom.xml =================================================================== --- hbase-hadoop2-compat/pom.xml (revision 1387351) +++ hbase-hadoop2-compat/pom.xml (working copy) @@ -134,6 +134,10 @@ hadoop-common ${hadoop-two.version} + + com.yammer.metrics + metrics-core + Index: hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/BaseMetricsSource.java =================================================================== --- hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/BaseMetricsSource.java (revision 1387351) +++ hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/BaseMetricsSource.java (working copy) @@ -68,6 +68,24 @@ public void incCounters(String counterName, long delta); /** + * Add some value to a histogram. + * + * @param name the name of the histogram + * @param value the value to add to the histogram + */ + public void updateHistogram(String name, long value); + + + /** + * Add some value to a Quantile (An accurate histogram). + * + * @param name the name of the quantile + * @param value the value to add to the quantile + */ + public void updateQuantile(String name, long value); + + + /** * Remove a counter and stop announcing it to metrics2. * * @param key Index: hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/master/metrics/MasterMetricsSource.java =================================================================== --- hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/master/metrics/MasterMetricsSource.java (revision 1387351) +++ hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/master/metrics/MasterMetricsSource.java (working copy) @@ -55,6 +55,12 @@ public static final String SERVER_NAME_NAME = "serverName"; public static final String CLUSTER_ID_NAME = "clusterId"; public static final String IS_ACTIVE_MASTER_NAME = "isActiveMaster"; + public static final String SPLIT_TIME_NAME = "hlogSplitTime"; + public static final String SPLIT_SIZE_NAME = "hlogSplitSize"; + public static final String CLUSTER_REQUESTS_NAME = "clusterRequests"; + public static final String RIT_COUNT_NAME = "ritCount"; + public static final String RIT_COUNT_OVER_THRESHOLD_NAME = "ritCountOverThreshold"; + public static final String RIT_OLDEST_AGE_NAME = "ritOldestAge"; public static final String MASTER_ACTIVE_TIME_DESC = "Master Active Time"; public static final String MASTER_START_TIME_DESC = "Master Start Time"; public static final String AVERAGE_LOAD_DESC = "AverageLoad"; @@ -64,6 +70,8 @@ public static final String SERVER_NAME_DESC = "Server Name"; public static final String CLUSTER_ID_DESC = "Cluster Id"; public static final String IS_ACTIVE_MASTER_DESC = "Is Active Master"; + public static final String SPLIT_TIME_DESC = "Time it takes to finish HLog.splitLog()"; + public static final String SPLIT_SIZE_DESC = "Size of HLog files being split"; /** @@ -90,4 +98,8 @@ */ public void setRITOldestAge(long age); + public void updateSplitTime(long time); + + public void updateSplitSize(long size); + }