diff --git a/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/ipc/MetricsHBaseServerSourceImpl.java b/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/ipc/MetricsHBaseServerSourceImpl.java index cfb3dee..9a8b13e 100644 --- a/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/ipc/MetricsHBaseServerSourceImpl.java +++ b/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/ipc/MetricsHBaseServerSourceImpl.java @@ -88,15 +88,15 @@ public class MetricsHBaseServerSourceImpl extends BaseSourceImpl SENT_BYTES_DESC, 0l); this.receivedBytes = this.getMetricsRegistry().newCounter(RECEIVED_BYTES_NAME, RECEIVED_BYTES_DESC, 0l); - this.queueCallTime = this.getMetricsRegistry().newHistogram(QUEUE_CALL_TIME_NAME, + this.queueCallTime = this.getMetricsRegistry().newTimeHistogram(QUEUE_CALL_TIME_NAME, QUEUE_CALL_TIME_DESC); - this.processCallTime = this.getMetricsRegistry().newHistogram(PROCESS_CALL_TIME_NAME, + this.processCallTime = this.getMetricsRegistry().newTimeHistogram(PROCESS_CALL_TIME_NAME, PROCESS_CALL_TIME_DESC); - this.totalCallTime = this.getMetricsRegistry().newHistogram(TOTAL_CALL_TIME_NAME, + this.totalCallTime = this.getMetricsRegistry().newTimeHistogram(TOTAL_CALL_TIME_NAME, TOTAL_CALL_TIME_DESC); - this.requestSize = this.getMetricsRegistry().newHistogram(REQUEST_SIZE_NAME, + this.requestSize = this.getMetricsRegistry().newSizeHistogram(REQUEST_SIZE_NAME, REQUEST_SIZE_DESC); - this.responseSize = this.getMetricsRegistry().newHistogram(RESPONSE_SIZE_NAME, + this.responseSize = this.getMetricsRegistry().newSizeHistogram(RESPONSE_SIZE_NAME, RESPONSE_SIZE_DESC); } diff --git a/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsAssignmentManagerSourceImpl.java b/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsAssignmentManagerSourceImpl.java index 8f8869b..bb4e748 100644 --- a/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsAssignmentManagerSourceImpl.java +++ b/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsAssignmentManagerSourceImpl.java @@ -46,8 +46,8 @@ public class MetricsAssignmentManagerSourceImpl extends BaseSourceImpl implement ritGauge = metricsRegistry.newGauge(RIT_COUNT_NAME, "", 0l); ritCountOverThresholdGauge = metricsRegistry.newGauge(RIT_COUNT_OVER_THRESHOLD_NAME, "", 0l); ritOldestAgeGauge = metricsRegistry.newGauge(RIT_OLDEST_AGE_NAME, "", 0l); - assignTimeHisto = metricsRegistry.newHistogram(ASSIGN_TIME_NAME); - bulkAssignTimeHisto = metricsRegistry.newHistogram(BULK_ASSIGN_TIME_NAME); + assignTimeHisto = metricsRegistry.newTimeHistogram(ASSIGN_TIME_NAME); + bulkAssignTimeHisto = metricsRegistry.newTimeHistogram(BULK_ASSIGN_TIME_NAME); } @Override diff --git a/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsMasterFilesystemSourceImpl.java b/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsMasterFilesystemSourceImpl.java index 40c1e64..639609a 100644 --- a/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsMasterFilesystemSourceImpl.java +++ b/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsMasterFilesystemSourceImpl.java @@ -40,10 +40,10 @@ public class MetricsMasterFilesystemSourceImpl extends BaseSourceImpl implements @Override public void init() { - splitSizeHisto = metricsRegistry.newHistogram(SPLIT_SIZE_NAME, SPLIT_SIZE_DESC); - splitTimeHisto = metricsRegistry.newHistogram(SPLIT_TIME_NAME, SPLIT_TIME_DESC); - metaSplitTimeHisto = metricsRegistry.newHistogram(META_SPLIT_TIME_NAME, META_SPLIT_TIME_DESC); - metaSplitSizeHisto = metricsRegistry.newHistogram(META_SPLIT_SIZE_NAME, META_SPLIT_SIZE_DESC); + splitSizeHisto = metricsRegistry.newSizeHistogram(SPLIT_SIZE_NAME, SPLIT_SIZE_DESC); + splitTimeHisto = metricsRegistry.newTimeHistogram(SPLIT_TIME_NAME, SPLIT_TIME_DESC); + metaSplitTimeHisto = metricsRegistry.newTimeHistogram(META_SPLIT_TIME_NAME, META_SPLIT_TIME_DESC); + metaSplitSizeHisto = metricsRegistry.newSizeHistogram(META_SPLIT_SIZE_NAME, META_SPLIT_SIZE_DESC); } @Override diff --git a/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsSnapshotSourceImpl.java b/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsSnapshotSourceImpl.java index 6b43d30..62e43b0 100644 --- a/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsSnapshotSourceImpl.java +++ b/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsSnapshotSourceImpl.java @@ -39,11 +39,11 @@ public class MetricsSnapshotSourceImpl extends BaseSourceImpl implements Metrics @Override public void init() { - snapshotTimeHisto = metricsRegistry.newHistogram( + snapshotTimeHisto = metricsRegistry.newTimeHistogram( SNAPSHOT_TIME_NAME, SNAPSHOT_TIME_DESC); - snapshotCloneTimeHisto = metricsRegistry.newHistogram( + snapshotCloneTimeHisto = metricsRegistry.newTimeHistogram( SNAPSHOT_CLONE_TIME_NAME, SNAPSHOT_CLONE_TIME_DESC); - snapshotRestoreTimeHisto = metricsRegistry.newHistogram( + snapshotRestoreTimeHisto = metricsRegistry.newTimeHistogram( SNAPSHOT_RESTORE_TIME_NAME, SNAPSHOT_RESTORE_TIME_DESC); } diff --git a/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/master/balancer/MetricsBalancerSourceImpl.java b/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/master/balancer/MetricsBalancerSourceImpl.java index 4311330..03804d0 100644 --- a/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/master/balancer/MetricsBalancerSourceImpl.java +++ b/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/master/balancer/MetricsBalancerSourceImpl.java @@ -40,7 +40,7 @@ public class MetricsBalancerSourceImpl extends BaseSourceImpl implements Metrics @Override public void init() { - blanceClusterHisto = metricsRegistry.newHistogram(BALANCE_CLUSTER); + blanceClusterHisto = metricsRegistry.newTimeHistogram(BALANCE_CLUSTER); miscCount = metricsRegistry.newCounter(MISC_INVOATION_COUNT, "", 0L); } diff --git a/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServerSourceImpl.java b/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServerSourceImpl.java index 269f61f..487b670 100644 --- a/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServerSourceImpl.java +++ b/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServerSourceImpl.java @@ -64,26 +64,26 @@ public class MetricsRegionServerSourceImpl super(metricsName, metricsDescription, metricsContext, metricsJmxContext); this.rsWrap = rsWrap; - putHisto = getMetricsRegistry().newHistogram(MUTATE_KEY); + putHisto = getMetricsRegistry().newTimeHistogram(MUTATE_KEY); slowPut = getMetricsRegistry().newCounter(SLOW_MUTATE_KEY, SLOW_MUTATE_DESC, 0l); - deleteHisto = getMetricsRegistry().newHistogram(DELETE_KEY); + deleteHisto = getMetricsRegistry().newTimeHistogram(DELETE_KEY); slowDelete = getMetricsRegistry().newCounter(SLOW_DELETE_KEY, SLOW_DELETE_DESC, 0l); - getHisto = getMetricsRegistry().newHistogram(GET_KEY); + getHisto = getMetricsRegistry().newTimeHistogram(GET_KEY); slowGet = getMetricsRegistry().newCounter(SLOW_GET_KEY, SLOW_GET_DESC, 0l); - incrementHisto = getMetricsRegistry().newHistogram(INCREMENT_KEY); + incrementHisto = getMetricsRegistry().newTimeHistogram(INCREMENT_KEY); slowIncrement = getMetricsRegistry().newCounter(SLOW_INCREMENT_KEY, SLOW_INCREMENT_DESC, 0l); - appendHisto = getMetricsRegistry().newHistogram(APPEND_KEY); + appendHisto = getMetricsRegistry().newTimeHistogram(APPEND_KEY); slowAppend = getMetricsRegistry().newCounter(SLOW_APPEND_KEY, SLOW_APPEND_DESC, 0l); - replayHisto = getMetricsRegistry().newHistogram(REPLAY_KEY); - scanNextHisto = getMetricsRegistry().newHistogram(SCAN_NEXT_KEY); + replayHisto = getMetricsRegistry().newTimeHistogram(REPLAY_KEY); + scanNextHisto = getMetricsRegistry().newTimeHistogram(SCAN_NEXT_KEY); - splitTimeHisto = getMetricsRegistry().newHistogram(SPLIT_KEY); - flushTimeHisto = getMetricsRegistry().newHistogram(FLUSH_KEY); + splitTimeHisto = getMetricsRegistry().newTimeHistogram(SPLIT_KEY); + flushTimeHisto = getMetricsRegistry().newTimeHistogram(FLUSH_KEY); splitRequest = getMetricsRegistry().newCounter(SPLIT_REQUEST_KEY, SPLIT_REQUEST_DESC, 0l); splitSuccess = getMetricsRegistry().newCounter(SPLIT_SUCCESS_KEY, SPLIT_SUCCESS_DESC, 0l); diff --git a/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionSourceImpl.java b/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionSourceImpl.java index 87a2b3c..730c05e7 100644 --- a/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionSourceImpl.java +++ b/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionSourceImpl.java @@ -81,10 +81,10 @@ public class MetricsRegionSourceImpl implements MetricsRegionSource { regionAppend = registry.getLongCounter(regionAppendKey, 0l); regionGetKey = regionNamePrefix + MetricsRegionServerSource.GET_KEY; - regionGet = registry.newHistogram(regionGetKey); + regionGet = registry.newTimeHistogram(regionGetKey); regionScanNextKey = regionNamePrefix + MetricsRegionServerSource.SCAN_NEXT_KEY; - regionScanNext = registry.newHistogram(regionScanNextKey); + regionScanNext = registry.newTimeHistogram(regionScanNextKey); } @Override diff --git a/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/regionserver/wal/MetricsEditsReplaySourceImpl.java b/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/regionserver/wal/MetricsEditsReplaySourceImpl.java index dfb94f2..0ddbedb 100644 --- a/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/regionserver/wal/MetricsEditsReplaySourceImpl.java +++ b/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/regionserver/wal/MetricsEditsReplaySourceImpl.java @@ -51,11 +51,11 @@ public class MetricsEditsReplaySourceImpl @Override public void init() { super.init(); - replayTimeHisto = metricsRegistry.newHistogram(REPLAY_TIME_NAME, REPLAY_TIME_DESC); + replayTimeHisto = metricsRegistry.newTimeHistogram(REPLAY_TIME_NAME, REPLAY_TIME_DESC); replayBatchSizeHisto = - metricsRegistry.newHistogram(REPLAY_BATCH_SIZE_NAME, REPLAY_BATCH_SIZE_DESC); + metricsRegistry.newSizeHistogram(REPLAY_BATCH_SIZE_NAME, REPLAY_BATCH_SIZE_DESC); replayDataSizeHisto = - metricsRegistry.newHistogram(REPLAY_DATA_SIZE_NAME, REPLAY_DATA_SIZE_DESC); + metricsRegistry.newSizeHistogram(REPLAY_DATA_SIZE_NAME, REPLAY_DATA_SIZE_DESC); } @Override diff --git a/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/regionserver/wal/MetricsWALSourceImpl.java b/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/regionserver/wal/MetricsWALSourceImpl.java index 505e989..ea5ec51 100644 --- a/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/regionserver/wal/MetricsWALSourceImpl.java +++ b/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/regionserver/wal/MetricsWALSourceImpl.java @@ -48,12 +48,12 @@ public class MetricsWALSourceImpl extends BaseSourceImpl implements MetricsWALSo super(metricsName, metricsDescription, metricsContext, metricsJmxContext); //Create and store the metrics that will be used. - appendTimeHisto = this.getMetricsRegistry().newHistogram(APPEND_TIME, APPEND_TIME_DESC); - appendSizeHisto = this.getMetricsRegistry().newHistogram(APPEND_SIZE, APPEND_SIZE_DESC); + appendTimeHisto = this.getMetricsRegistry().newTimeHistogram(APPEND_TIME, APPEND_TIME_DESC); + appendSizeHisto = this.getMetricsRegistry().newSizeHistogram(APPEND_SIZE, APPEND_SIZE_DESC); appendCount = this.getMetricsRegistry().newCounter(APPEND_COUNT, APPEND_COUNT_DESC, 0l); slowAppendCount = this.getMetricsRegistry().newCounter(SLOW_APPEND_COUNT, SLOW_APPEND_COUNT_DESC, 0l); - syncTimeHisto = this.getMetricsRegistry().newHistogram(SYNC_TIME, SYNC_TIME_DESC); + syncTimeHisto = this.getMetricsRegistry().newTimeHistogram(SYNC_TIME, SYNC_TIME_DESC); logRollRequested = this.getMetricsRegistry().newCounter(ROLL_REQUESTED, ROLL_REQUESTED_DESC, 0L); lowReplicationLogRollRequested = this.getMetricsRegistry() diff --git a/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/thrift/MetricsThriftServerSourceImpl.java b/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/thrift/MetricsThriftServerSourceImpl.java index 112a6a3..f3d96a5 100644 --- a/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/thrift/MetricsThriftServerSourceImpl.java +++ b/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/thrift/MetricsThriftServerSourceImpl.java @@ -52,11 +52,11 @@ public class MetricsThriftServerSourceImpl extends BaseSourceImpl implements @Override public void init() { super.init(); - batchGetStat = getMetricsRegistry().newHistogram(BATCH_GET_KEY); - batchMutateStat = getMetricsRegistry().newHistogram(BATCH_MUTATE_KEY); - queueTimeStat = getMetricsRegistry().newHistogram(TIME_IN_QUEUE_KEY); - thriftCallStat = getMetricsRegistry().newHistogram(THRIFT_CALL_KEY); - thriftSlowCallStat = getMetricsRegistry().newHistogram(SLOW_THRIFT_CALL_KEY); + batchGetStat = getMetricsRegistry().newTimeHistogram(BATCH_GET_KEY); + batchMutateStat = getMetricsRegistry().newTimeHistogram(BATCH_MUTATE_KEY); + queueTimeStat = getMetricsRegistry().newTimeHistogram(TIME_IN_QUEUE_KEY); + thriftCallStat = getMetricsRegistry().newTimeHistogram(THRIFT_CALL_KEY); + thriftSlowCallStat = getMetricsRegistry().newTimeHistogram(SLOW_THRIFT_CALL_KEY); callQueueLenGauge = getMetricsRegistry().getLongGauge(CALL_QUEUE_LEN_KEY, 0); } diff --git a/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/metrics2/lib/DynamicMetricsRegistry.java b/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/metrics2/lib/DynamicMetricsRegistry.java index 3f0bc47..32fa3e0 100644 --- a/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/metrics2/lib/DynamicMetricsRegistry.java +++ b/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/metrics2/lib/DynamicMetricsRegistry.java @@ -202,6 +202,46 @@ public class DynamicMetricsRegistry { } /** + * Create a new histogram with time range counts. + * @param name Name of the histogram. + * @return A new MetricMutableTimeHistogram + */ + public MetricMutableTimeHistogram newTimeHistogram(String name) { + return newTimeHistogram(name, ""); + } + + /** + * Create a new histogram with time range counts. + * @param name The name of the histogram + * @param desc The description of the data in the histogram. + * @return A new MetricMutableTimeHistogram + */ + public MetricMutableTimeHistogram newTimeHistogram(String name, String desc) { + MetricMutableTimeHistogram histo = new MetricMutableTimeHistogram(name, desc); + return addNewMetricIfAbsent(name, histo, MetricMutableTimeHistogram.class); + } + + /** + * Create a new histogram with size range counts. + * @param name Name of the histogram. + * @return A new MetricMutableSizeHistogram + */ + public MetricMutableSizeHistogram newSizeHistogram(String name) { + return newSizeHistogram(name, ""); + } + + /** + * Create a new histogram with size range counts. + * @param name The name of the histogram + * @param desc The description of the data in the histogram. + * @return A new MetricMutableSizeHistogram + */ + public MetricMutableSizeHistogram newSizeHistogram(String name, String desc) { + MetricMutableSizeHistogram histo = new MetricMutableSizeHistogram(name, desc); + return addNewMetricIfAbsent(name, histo, MetricMutableSizeHistogram.class); + } + + /** * Create a new MutableQuantile(A more accurate histogram). * @param name The name of the histogram * @return a new MutableQuantile diff --git a/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/metrics2/lib/MetricMutableHistogram.java b/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/metrics2/lib/MetricMutableHistogram.java index bc99ebe..62a47e0 100644 --- a/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/metrics2/lib/MetricMutableHistogram.java +++ b/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/metrics2/lib/MetricMutableHistogram.java @@ -106,6 +106,11 @@ public class MetricMutableHistogram extends MetricMutable implements MetricHisto public void snapshot(MetricsRecordBuilder metricsRecordBuilder, boolean all) { if (all || changed()) { clearChanged(); + updateSnapshotMetrics(metricsRecordBuilder); + } + } + + public void updateSnapshotMetrics(MetricsRecordBuilder metricsRecordBuilder) { final Snapshot s = sample.getSnapshot(); metricsRecordBuilder.addCounter(name + NUM_OPS_METRIC_NAME, "", count.get()); metricsRecordBuilder.addGauge(name + MIN_METRIC_NAME, "", getMin()); @@ -117,6 +122,5 @@ public class MetricMutableHistogram extends MetricMutable implements MetricHisto metricsRecordBuilder.addGauge(name + NINETIETH_PERCENTILE_METRIC_NAME, "", s.getValue(0.90)); metricsRecordBuilder.addGauge(name + NINETY_FIFTH_PERCENTILE_METRIC_NAME, "", s.get95thPercentile()); metricsRecordBuilder.addGauge(name + NINETY_NINETH_PERCENTILE_METRIC_NAME, "", s.get99thPercentile()); - } } } diff --git a/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/metrics2/lib/MetricMutableRangeHistogram.java b/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/metrics2/lib/MetricMutableRangeHistogram.java index e69de29..efae5a5 100644 --- a/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/metrics2/lib/MetricMutableRangeHistogram.java +++ b/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/metrics2/lib/MetricMutableRangeHistogram.java @@ -0,0 +1,89 @@ +/** + * 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.metrics2.lib; + +import java.util.concurrent.atomic.AtomicLongArray; + +import org.apache.hadoop.hbase.classification.InterfaceAudience; +import org.apache.hadoop.metrics2.MetricsRecordBuilder; + +/** + * Extended histogram implementation with metric range counters. + */ +@InterfaceAudience.Private +public abstract class MetricMutableRangeHistogram extends MetricMutableHistogram { + + public MetricMutableRangeHistogram(String name, String description) { + super(name, description); + } + + /** + * Returns the type of range histogram size or time + */ + public abstract String getRangeType(); + + /** + * Returns the ranges to be counted + */ + public abstract long[] getRange(); + + /** + * Returns the range counts + */ + public abstract AtomicLongArray getRangeVals(); + + @Override + public void add(final long val) { + super.add(val); + updateBand(val); + } + + private void updateBand(final long val) { + int i; + for (i=0; i getRange()[i]; i++); + getRangeVals().incrementAndGet(i); + } + + @Override + public void snapshot(MetricsRecordBuilder metricsRecordBuilder, boolean all) { + if (all || changed()) { + clearChanged(); + updateSnapshotMetrics(metricsRecordBuilder); + updateSnapshotRangeMetrics(metricsRecordBuilder); + } + } + + public void updateSnapshotRangeMetrics(MetricsRecordBuilder metricsRecordBuilder) { + long prior = 0; + for (int i = 0; i < getRange().length; i++) { + long val = getRangeVals().get(i); + if (val > 0) { + metricsRecordBuilder + .addCounter(name + "_" + getRangeType() + "_" + prior + "-" + getRange()[i], "", val); + } + prior = getRange()[i]; + } + long val = getRangeVals().get(getRange().length); + if (val > 0) { + metricsRecordBuilder.addCounter( + name + "_" + getRangeType() + "_>" + getRange()[getRange().length - 1], "", + getRangeVals().get(getRange().length)); + } + } +} diff --git a/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/metrics2/lib/MetricMutableSizeHistogram.java b/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/metrics2/lib/MetricMutableSizeHistogram.java index e69de29..8da9087 100644 --- a/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/metrics2/lib/MetricMutableSizeHistogram.java +++ b/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/metrics2/lib/MetricMutableSizeHistogram.java @@ -0,0 +1,52 @@ +/** + * 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.metrics2.lib; + +import java.util.concurrent.atomic.AtomicLongArray; + +import org.apache.hadoop.hbase.classification.InterfaceAudience; + +/** + * Extended histogram implementation with counters for metric size ranges. + */ +@InterfaceAudience.Private +public class MetricMutableSizeHistogram extends MetricMutableRangeHistogram { + private final String rangeDesc = "SizeRangeCount"; + private final long[] rangeType = {10,100,1000,10000,100000,1000000,10000000,100000000}; + private final AtomicLongArray rangeVals = new AtomicLongArray(getRange().length+1); + + public MetricMutableSizeHistogram(String name, String description) { + super(name, description); + } + + @Override + public String getRangeType() { + return rangeDesc; + } + + @Override + public long[] getRange() { + return rangeType; + } + + @Override + public AtomicLongArray getRangeVals() { + return rangeVals; + } +} diff --git a/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/metrics2/lib/MetricMutableTimeHistogram.java b/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/metrics2/lib/MetricMutableTimeHistogram.java index e69de29..b2882c9 100644 --- a/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/metrics2/lib/MetricMutableTimeHistogram.java +++ b/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/metrics2/lib/MetricMutableTimeHistogram.java @@ -0,0 +1,52 @@ +/** + * 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.metrics2.lib; + +import java.util.concurrent.atomic.AtomicLongArray; + +import org.apache.hadoop.hbase.classification.InterfaceAudience; + +/** + * Extended histogram implementation with counters for metric time ranges. + */ +@InterfaceAudience.Private +public class MetricMutableTimeHistogram extends MetricMutableRangeHistogram { + private final String rangeType = "TimeRangeCount"; + private final long[] ranges = {1,3,10,30,100,300,1000,3000,10000,30000,60000,120000,300000,600000}; + private final AtomicLongArray rangeVals = new AtomicLongArray(ranges.length+1); + + public MetricMutableTimeHistogram(String name, String description) { + super(name, description); + } + + @Override + public String getRangeType() { + return rangeType; + } + + @Override + public long[] getRange() { + return ranges; + } + + @Override + public AtomicLongArray getRangeVals() { + return rangeVals; + } +} diff --git a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/ipc/MetricsHBaseServerSourceImpl.java b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/ipc/MetricsHBaseServerSourceImpl.java index 6e3d1cc..4386fe4 100644 --- a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/ipc/MetricsHBaseServerSourceImpl.java +++ b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/ipc/MetricsHBaseServerSourceImpl.java @@ -91,15 +91,15 @@ public class MetricsHBaseServerSourceImpl extends BaseSourceImpl SENT_BYTES_DESC, 0L); this.receivedBytes = this.getMetricsRegistry().newCounter(RECEIVED_BYTES_NAME, RECEIVED_BYTES_DESC, 0L); - this.queueCallTime = this.getMetricsRegistry().newHistogram(QUEUE_CALL_TIME_NAME, + this.queueCallTime = this.getMetricsRegistry().newTimeHistogram(QUEUE_CALL_TIME_NAME, QUEUE_CALL_TIME_DESC); - this.processCallTime = this.getMetricsRegistry().newHistogram(PROCESS_CALL_TIME_NAME, + this.processCallTime = this.getMetricsRegistry().newTimeHistogram(PROCESS_CALL_TIME_NAME, PROCESS_CALL_TIME_DESC); - this.totalCallTime = this.getMetricsRegistry().newHistogram(TOTAL_CALL_TIME_NAME, + this.totalCallTime = this.getMetricsRegistry().newTimeHistogram(TOTAL_CALL_TIME_NAME, TOTAL_CALL_TIME_DESC); - this.requestSize = this.getMetricsRegistry().newHistogram(REQUEST_SIZE_NAME, + this.requestSize = this.getMetricsRegistry().newSizeHistogram(REQUEST_SIZE_NAME, REQUEST_SIZE_DESC); - this.responseSize = this.getMetricsRegistry().newHistogram(RESPONSE_SIZE_NAME, + this.responseSize = this.getMetricsRegistry().newSizeHistogram(RESPONSE_SIZE_NAME, RESPONSE_SIZE_DESC); } diff --git a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsAssignmentManagerSourceImpl.java b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsAssignmentManagerSourceImpl.java index 215855f..ccf1c1d 100644 --- a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsAssignmentManagerSourceImpl.java +++ b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsAssignmentManagerSourceImpl.java @@ -46,8 +46,8 @@ public class MetricsAssignmentManagerSourceImpl extends BaseSourceImpl implement ritGauge = metricsRegistry.newGauge(RIT_COUNT_NAME, "", 0l); ritCountOverThresholdGauge = metricsRegistry.newGauge(RIT_COUNT_OVER_THRESHOLD_NAME, "", 0l); ritOldestAgeGauge = metricsRegistry.newGauge(RIT_OLDEST_AGE_NAME, "", 0l); - assignTimeHisto = metricsRegistry.newHistogram(ASSIGN_TIME_NAME); - bulkAssignTimeHisto = metricsRegistry.newHistogram(BULK_ASSIGN_TIME_NAME); + assignTimeHisto = metricsRegistry.newTimeHistogram(ASSIGN_TIME_NAME); + bulkAssignTimeHisto = metricsRegistry.newTimeHistogram(BULK_ASSIGN_TIME_NAME); } @Override diff --git a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsMasterFilesystemSourceImpl.java b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsMasterFilesystemSourceImpl.java index 1644207..4a857c0 100644 --- a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsMasterFilesystemSourceImpl.java +++ b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsMasterFilesystemSourceImpl.java @@ -42,10 +42,10 @@ public class MetricsMasterFilesystemSourceImpl extends BaseSourceImpl implements @Override public void init() { - splitSizeHisto = metricsRegistry.newHistogram(SPLIT_SIZE_NAME, SPLIT_SIZE_DESC); - splitTimeHisto = metricsRegistry.newHistogram(SPLIT_TIME_NAME, SPLIT_TIME_DESC); - metaSplitTimeHisto = metricsRegistry.newHistogram(META_SPLIT_TIME_NAME, META_SPLIT_TIME_DESC); - metaSplitSizeHisto = metricsRegistry.newHistogram(META_SPLIT_SIZE_NAME, META_SPLIT_SIZE_DESC); + splitSizeHisto = metricsRegistry.newSizeHistogram(SPLIT_SIZE_NAME, SPLIT_SIZE_DESC); + splitTimeHisto = metricsRegistry.newTimeHistogram(SPLIT_TIME_NAME, SPLIT_TIME_DESC); + metaSplitTimeHisto = metricsRegistry.newTimeHistogram(META_SPLIT_TIME_NAME, META_SPLIT_TIME_DESC); + metaSplitSizeHisto = metricsRegistry.newSizeHistogram(META_SPLIT_SIZE_NAME, META_SPLIT_SIZE_DESC); } @Override diff --git a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsSnapshotSourceImpl.java b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsSnapshotSourceImpl.java index 80e1bad..c2fc6b9 100644 --- a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsSnapshotSourceImpl.java +++ b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsSnapshotSourceImpl.java @@ -41,11 +41,11 @@ public class MetricsSnapshotSourceImpl extends BaseSourceImpl implements Metrics @Override public void init() { - snapshotTimeHisto = metricsRegistry.newHistogram( + snapshotTimeHisto = metricsRegistry.newTimeHistogram( SNAPSHOT_TIME_NAME, SNAPSHOT_TIME_DESC); - snapshotCloneTimeHisto = metricsRegistry.newHistogram( + snapshotCloneTimeHisto = metricsRegistry.newTimeHistogram( SNAPSHOT_CLONE_TIME_NAME, SNAPSHOT_CLONE_TIME_DESC); - snapshotRestoreTimeHisto = metricsRegistry.newHistogram( + snapshotRestoreTimeHisto = metricsRegistry.newTimeHistogram( SNAPSHOT_RESTORE_TIME_NAME, SNAPSHOT_RESTORE_TIME_DESC); } diff --git a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/master/balancer/MetricsBalancerSourceImpl.java b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/master/balancer/MetricsBalancerSourceImpl.java index 774e2e7..da34df2 100644 --- a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/master/balancer/MetricsBalancerSourceImpl.java +++ b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/master/balancer/MetricsBalancerSourceImpl.java @@ -42,7 +42,7 @@ public class MetricsBalancerSourceImpl extends BaseSourceImpl implements Metrics @Override public void init() { - blanceClusterHisto = metricsRegistry.newHistogram(BALANCE_CLUSTER); + blanceClusterHisto = metricsRegistry.newTimeHistogram(BALANCE_CLUSTER); miscCount = metricsRegistry.newCounter(MISC_INVOATION_COUNT, "", 0L); } diff --git a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServerSourceImpl.java b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServerSourceImpl.java index 674621f..6827b94 100644 --- a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServerSourceImpl.java +++ b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServerSourceImpl.java @@ -68,26 +68,26 @@ public class MetricsRegionServerSourceImpl super(metricsName, metricsDescription, metricsContext, metricsJmxContext); this.rsWrap = rsWrap; - putHisto = getMetricsRegistry().newHistogram(MUTATE_KEY); + putHisto = getMetricsRegistry().newTimeHistogram(MUTATE_KEY); slowPut = getMetricsRegistry().newCounter(SLOW_MUTATE_KEY, SLOW_MUTATE_DESC, 0l); - deleteHisto = getMetricsRegistry().newHistogram(DELETE_KEY); + deleteHisto = getMetricsRegistry().newTimeHistogram(DELETE_KEY); slowDelete = getMetricsRegistry().newCounter(SLOW_DELETE_KEY, SLOW_DELETE_DESC, 0l); - getHisto = getMetricsRegistry().newHistogram(GET_KEY); + getHisto = getMetricsRegistry().newTimeHistogram(GET_KEY); slowGet = getMetricsRegistry().newCounter(SLOW_GET_KEY, SLOW_GET_DESC, 0l); - incrementHisto = getMetricsRegistry().newHistogram(INCREMENT_KEY); + incrementHisto = getMetricsRegistry().newTimeHistogram(INCREMENT_KEY); slowIncrement = getMetricsRegistry().newCounter(SLOW_INCREMENT_KEY, SLOW_INCREMENT_DESC, 0l); - appendHisto = getMetricsRegistry().newHistogram(APPEND_KEY); + appendHisto = getMetricsRegistry().newTimeHistogram(APPEND_KEY); slowAppend = getMetricsRegistry().newCounter(SLOW_APPEND_KEY, SLOW_APPEND_DESC, 0l); - replayHisto = getMetricsRegistry().newHistogram(REPLAY_KEY); - scanNextHisto = getMetricsRegistry().newHistogram(SCAN_NEXT_KEY); + replayHisto = getMetricsRegistry().newTimeHistogram(REPLAY_KEY); + scanNextHisto = getMetricsRegistry().newTimeHistogram(SCAN_NEXT_KEY); - splitTimeHisto = getMetricsRegistry().newHistogram(SPLIT_KEY); - flushTimeHisto = getMetricsRegistry().newHistogram(FLUSH_KEY); + splitTimeHisto = getMetricsRegistry().newTimeHistogram(SPLIT_KEY); + flushTimeHisto = getMetricsRegistry().newTimeHistogram(FLUSH_KEY); splitRequest = getMetricsRegistry().newCounter(SPLIT_REQUEST_KEY, SPLIT_REQUEST_DESC, 0l); splitSuccess = getMetricsRegistry().newCounter(SPLIT_SUCCESS_KEY, SPLIT_SUCCESS_DESC, 0l); diff --git a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionSourceImpl.java b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionSourceImpl.java index b0d6a3a..1bad5b3 100644 --- a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionSourceImpl.java +++ b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionSourceImpl.java @@ -89,10 +89,10 @@ public class MetricsRegionSourceImpl implements MetricsRegionSource { regionAppend = registry.getLongCounter(regionAppendKey, 0l); regionGetKey = regionNamePrefix + MetricsRegionServerSource.GET_KEY; - regionGet = registry.newHistogram(regionGetKey); + regionGet = registry.newTimeHistogram(regionGetKey); regionScanNextKey = regionNamePrefix + MetricsRegionServerSource.SCAN_NEXT_KEY; - regionScanNext = registry.newHistogram(regionScanNextKey); + regionScanNext = registry.newTimeHistogram(regionScanNextKey); } @Override diff --git a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/wal/MetricsEditsReplaySourceImpl.java b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/wal/MetricsEditsReplaySourceImpl.java index b10a69e..787fe76 100644 --- a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/wal/MetricsEditsReplaySourceImpl.java +++ b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/wal/MetricsEditsReplaySourceImpl.java @@ -52,11 +52,11 @@ public class MetricsEditsReplaySourceImpl extends BaseSourceImpl implements @Override public void init() { super.init(); - replayTimeHisto = metricsRegistry.newHistogram(REPLAY_TIME_NAME, REPLAY_TIME_DESC); - replayBatchSizeHisto = metricsRegistry.newHistogram(REPLAY_BATCH_SIZE_NAME, + replayTimeHisto = metricsRegistry.newTimeHistogram(REPLAY_TIME_NAME, REPLAY_TIME_DESC); + replayBatchSizeHisto = metricsRegistry.newSizeHistogram(REPLAY_BATCH_SIZE_NAME, REPLAY_BATCH_SIZE_DESC); replayDataSizeHisto = metricsRegistry - .newHistogram(REPLAY_DATA_SIZE_NAME, REPLAY_DATA_SIZE_DESC); + .newSizeHistogram(REPLAY_DATA_SIZE_NAME, REPLAY_DATA_SIZE_DESC); } @Override diff --git a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/wal/MetricsWALSourceImpl.java b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/wal/MetricsWALSourceImpl.java index f6f12b8..50cbda1 100644 --- a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/wal/MetricsWALSourceImpl.java +++ b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/wal/MetricsWALSourceImpl.java @@ -51,12 +51,12 @@ public class MetricsWALSourceImpl extends BaseSourceImpl implements MetricsWALSo super(metricsName, metricsDescription, metricsContext, metricsJmxContext); //Create and store the metrics that will be used. - appendTimeHisto = this.getMetricsRegistry().newHistogram(APPEND_TIME, APPEND_TIME_DESC); - appendSizeHisto = this.getMetricsRegistry().newHistogram(APPEND_SIZE, APPEND_SIZE_DESC); + appendTimeHisto = this.getMetricsRegistry().newTimeHistogram(APPEND_TIME, APPEND_TIME_DESC); + appendSizeHisto = this.getMetricsRegistry().newSizeHistogram(APPEND_SIZE, APPEND_SIZE_DESC); appendCount = this.getMetricsRegistry().newCounter(APPEND_COUNT, APPEND_COUNT_DESC, 0l); slowAppendCount = this.getMetricsRegistry().newCounter(SLOW_APPEND_COUNT, SLOW_APPEND_COUNT_DESC, 0l); - syncTimeHisto = this.getMetricsRegistry().newHistogram(SYNC_TIME, SYNC_TIME_DESC); + syncTimeHisto = this.getMetricsRegistry().newTimeHistogram(SYNC_TIME, SYNC_TIME_DESC); logRollRequested = this.getMetricsRegistry().newCounter(ROLL_REQUESTED, ROLL_REQUESTED_DESC, 0L); lowReplicationLogRollRequested = this.getMetricsRegistry() diff --git a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/thrift/MetricsThriftServerSourceImpl.java b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/thrift/MetricsThriftServerSourceImpl.java index e572e19..f9612e5 100644 --- a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/thrift/MetricsThriftServerSourceImpl.java +++ b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/thrift/MetricsThriftServerSourceImpl.java @@ -51,11 +51,11 @@ public class MetricsThriftServerSourceImpl extends BaseSourceImpl implements @Override public void init() { super.init(); - batchGetStat = getMetricsRegistry().newHistogram(BATCH_GET_KEY); - batchMutateStat = getMetricsRegistry().newHistogram(BATCH_MUTATE_KEY); - queueTimeStat = getMetricsRegistry().newHistogram(TIME_IN_QUEUE_KEY); - thriftCallStat = getMetricsRegistry().newHistogram(THRIFT_CALL_KEY); - thriftSlowCallStat = getMetricsRegistry().newHistogram(SLOW_THRIFT_CALL_KEY); + batchGetStat = getMetricsRegistry().newTimeHistogram(BATCH_GET_KEY); + batchMutateStat = getMetricsRegistry().newTimeHistogram(BATCH_MUTATE_KEY); + queueTimeStat = getMetricsRegistry().newTimeHistogram(TIME_IN_QUEUE_KEY); + thriftCallStat = getMetricsRegistry().newTimeHistogram(THRIFT_CALL_KEY); + thriftSlowCallStat = getMetricsRegistry().newTimeHistogram(SLOW_THRIFT_CALL_KEY); callQueueLenGauge = getMetricsRegistry().getLongGauge(CALL_QUEUE_LEN_KEY, 0); } diff --git a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/DynamicMetricsRegistry.java b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/DynamicMetricsRegistry.java index 281200c..972f5ac 100644 --- a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/DynamicMetricsRegistry.java +++ b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/DynamicMetricsRegistry.java @@ -271,6 +271,46 @@ public class DynamicMetricsRegistry { MutableHistogram histo = new MutableHistogram(name, desc); return addNewMetricIfAbsent(name, histo, MutableHistogram.class); } + + /** + * Create a new histogram with time range counts. + * @param name Name of the histogram. + * @return A new MutableTimeHistogram + */ + public MutableTimeHistogram newTimeHistogram(String name) { + return newTimeHistogram(name, ""); + } + + /** + * Create a new histogram with time range counts. + * @param name The name of the histogram + * @param desc The description of the data in the histogram. + * @return A new MutableTimeHistogram + */ + public MutableTimeHistogram newTimeHistogram(String name, String desc) { + MutableTimeHistogram histo = new MutableTimeHistogram(name, desc); + return addNewMetricIfAbsent(name, histo, MutableTimeHistogram.class); + } + + /** + * Create a new histogram with size range counts. + * @param name Name of the histogram. + * @return A new MutableSizeHistogram + */ + public MutableSizeHistogram newSizeHistogram(String name) { + return newSizeHistogram(name, ""); + } + + /** + * Create a new histogram with size range counts. + * @param name The name of the histogram + * @param desc The description of the data in the histogram. + * @return A new MutableSizeHistogram + */ + public MutableSizeHistogram newSizeHistogram(String name, String desc) { + MutableSizeHistogram histo = new MutableSizeHistogram(name, desc); + return addNewMetricIfAbsent(name, histo, MutableSizeHistogram.class); + } /** * Create a new MutableQuantile(A more accurate histogram). diff --git a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableHistogram.java b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableHistogram.java index 1251d9f..b66094e 100644 --- a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableHistogram.java +++ b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableHistogram.java @@ -41,8 +41,8 @@ public class MutableHistogram extends MutableMetric implements MetricHistogram { // Per Cormode et al. an alpha of 0.015 strongly biases to the last 5 minutes private static final double DEFAULT_ALPHA = 0.015; - private final String name; - private final String desc; + protected final String name; + protected final String desc; private final Sample sample; private final AtomicLong min; private final AtomicLong max; @@ -116,6 +116,11 @@ public class MutableHistogram extends MutableMetric implements MetricHistogram { public void snapshot(MetricsRecordBuilder metricsRecordBuilder, boolean all) { if (all || changed()) { clearChanged(); + updateSnapshotMetrics(metricsRecordBuilder); + } + } + + public void updateSnapshotMetrics(MetricsRecordBuilder metricsRecordBuilder) { final Snapshot s = sample.getSnapshot(); metricsRecordBuilder.addCounter(Interns.info(name + NUM_OPS_METRIC_NAME, desc), count.get()); @@ -131,7 +136,6 @@ public class MutableHistogram extends MutableMetric implements MetricHistogram { metricsRecordBuilder.addGauge(Interns.info(name + NINETY_FIFTH_PERCENTILE_METRIC_NAME, desc), s.get95thPercentile()); metricsRecordBuilder.addGauge(Interns.info(name + NINETY_NINETH_PERCENTILE_METRIC_NAME, desc), - s.get99thPercentile()); - } + s.get99thPercentile()); } } diff --git a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableRangeHistogram.java b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableRangeHistogram.java index e69de29..40fdf33 100644 --- a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableRangeHistogram.java +++ b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableRangeHistogram.java @@ -0,0 +1,94 @@ +/** + * 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.metrics2.lib; + +import java.util.concurrent.atomic.AtomicLongArray; + +import org.apache.hadoop.hbase.classification.InterfaceAudience; +import org.apache.hadoop.metrics2.MetricsInfo; +import org.apache.hadoop.metrics2.MetricsRecordBuilder; + +/** + * Extended histogram implementation with metric range counters. + */ +@InterfaceAudience.Private +public abstract class MutableRangeHistogram extends MutableHistogram { + + public MutableRangeHistogram(MetricsInfo info) { + this(info.name(), info.description()); + } + + public MutableRangeHistogram(String name, String description) { + super(name, description); + } + + /** + * Returns the type of range histogram size or time + */ + public abstract String getRangeType(); + + /** + * Returns the ranges to be counted + */ + public abstract long[] getRange(); + + /** + * Returns the range counts + */ + public abstract AtomicLongArray getRangeVals(); + + @Override + public void add(final long val) { + super.add(val); + updateBand(val); + } + + private void updateBand(final long val) { + int i; + for (i=0; i getRange()[i]; i++); + getRangeVals().incrementAndGet(i); + } + + @Override + public void snapshot(MetricsRecordBuilder metricsRecordBuilder, boolean all) { + if (all || changed()) { + clearChanged(); + updateSnapshotMetrics(metricsRecordBuilder); + updateSnapshotRangeMetrics(metricsRecordBuilder); + } + } + + public void updateSnapshotRangeMetrics(MetricsRecordBuilder metricsRecordBuilder) { + long prior = 0; + for (int i = 0; i < getRange().length; i++) { + long val = getRangeVals().get(i); + if (val > 0) { + metricsRecordBuilder + .addCounter(Interns.info(name + "_" + getRangeType() + "_" + prior + "-" + getRange()[i], desc), val); + } + prior = getRange()[i]; + } + long val = getRangeVals().get(getRange().length); + if (val > 0) { + metricsRecordBuilder.addCounter( + Interns.info(name + "_" + getRangeType() + "_>" + getRange()[getRange().length - 1], desc), + getRangeVals().get(getRange().length)); + } + } +} diff --git a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableSizeHistogram.java b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableSizeHistogram.java index e69de29..f764c30 100644 --- a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableSizeHistogram.java +++ b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableSizeHistogram.java @@ -0,0 +1,57 @@ +/** + * 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.metrics2.lib; + +import java.util.concurrent.atomic.AtomicLongArray; + +import org.apache.hadoop.hbase.classification.InterfaceAudience; +import org.apache.hadoop.metrics2.MetricsInfo; + +/** + * Extended histogram implementation with counters for metric size ranges. + */ +@InterfaceAudience.Private +public class MutableSizeHistogram extends MutableRangeHistogram { + private final String rangeDesc = "SizeRangeCount"; + private final long[] rangeType = {10,100,1000,10000,100000,1000000,10000000,100000000}; + private final AtomicLongArray rangeVals = new AtomicLongArray(getRange().length+1); + + public MutableSizeHistogram(MetricsInfo info) { + this(info.name(), info.description()); + } + + public MutableSizeHistogram(String name, String description) { + super(name, description); + } + + @Override + public String getRangeType() { + return rangeDesc; + } + + @Override + public long[] getRange() { + return rangeType; + } + + @Override + public AtomicLongArray getRangeVals() { + return rangeVals; + } +} diff --git a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableTimeHistogram.java b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableTimeHistogram.java index e69de29..62d9daf 100644 --- a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableTimeHistogram.java +++ b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableTimeHistogram.java @@ -0,0 +1,57 @@ +/** + * 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.metrics2.lib; + +import java.util.concurrent.atomic.AtomicLongArray; + +import org.apache.hadoop.hbase.classification.InterfaceAudience; +import org.apache.hadoop.metrics2.MetricsInfo; + +/** + * Extended histogram implementation with counters for metric time ranges. + */ +@InterfaceAudience.Private +public class MutableTimeHistogram extends MutableRangeHistogram { + private final String rangeType = "TimeRangeCount"; + private final long[] ranges = {1,3,10,30,100,300,1000,3000,10000,30000,60000,120000,300000,600000}; + private final AtomicLongArray rangeVals = new AtomicLongArray(ranges.length+1); + + public MutableTimeHistogram(MetricsInfo info) { + this(info.name(), info.description()); + } + + public MutableTimeHistogram(String name, String description) { + super(name, description); + } + + @Override + public String getRangeType() { + return rangeType; + } + + @Override + public long[] getRange() { + return ranges; + } + + @Override + public AtomicLongArray getRangeVals() { + return rangeVals; + } +}