diff --git a/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/regionserver/wal/MetricsWALSource.java b/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/regionserver/wal/MetricsWALSource.java index c6dc731c823..a665571868d 100644 --- a/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/regionserver/wal/MetricsWALSource.java +++ b/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/regionserver/wal/MetricsWALSource.java @@ -62,6 +62,8 @@ public interface MetricsWALSource extends BaseSource { String LOW_REPLICA_ROLL_REQUESTED = "lowReplicaRollRequest"; String LOW_REPLICA_ROLL_REQUESTED_DESC = "How many times a log roll was requested due to too few DN's in the write pipeline."; + String WRITTEN_BYTES = "writtenBytes"; + String WRITTEN_BYTES_DESC = "Size (in bytes) of the data written to the WAL."; /** * Add the append size. @@ -93,4 +95,8 @@ public interface MetricsWALSource extends BaseSource { void incrementLowReplicationLogRoll(); long getSlowAppendCount(); + + void incrementWrittenBytes(long val); + + long getWrittenBytes(); } 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 995e3343a79..9f9e09cd839 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 @@ -40,6 +40,7 @@ public class MetricsWALSourceImpl extends BaseSourceImpl implements MetricsWALSo private final MutableFastCounter slowAppendCount; private final MutableFastCounter logRollRequested; private final MutableFastCounter lowReplicationLogRollRequested; + private final MutableFastCounter writtenBytes; public MetricsWALSourceImpl() { this(METRICS_NAME, METRICS_DESCRIPTION, METRICS_CONTEXT, METRICS_JMX_CONTEXT); @@ -62,6 +63,7 @@ public class MetricsWALSourceImpl extends BaseSourceImpl implements MetricsWALSo this.getMetricsRegistry().newCounter(ROLL_REQUESTED, ROLL_REQUESTED_DESC, 0L); lowReplicationLogRollRequested = this.getMetricsRegistry() .newCounter(LOW_REPLICA_ROLL_REQUESTED, LOW_REPLICA_ROLL_REQUESTED_DESC, 0L); + writtenBytes = this.getMetricsRegistry().newCounter(WRITTEN_BYTES, WRITTEN_BYTES_DESC, 0l); } @Override @@ -103,4 +105,15 @@ public class MetricsWALSourceImpl extends BaseSourceImpl implements MetricsWALSo public long getSlowAppendCount() { return slowAppendCount.value(); } + + @Override + public void incrementWrittenBytes(long val) { + writtenBytes.incr(val); + } + + @Override + public long getWrittenBytes() { + return writtenBytes.value(); + } + } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/MetricsWAL.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/MetricsWAL.java index 24fd9405571..99792e558a4 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/MetricsWAL.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/MetricsWAL.java @@ -55,6 +55,7 @@ public class MetricsWAL extends WALActionsListener.Base { source.incrementAppendCount(); source.incrementAppendTime(time); source.incrementAppendSize(size); + source.incrementWrittenBytes(size); if (time > 1000) { source.incrementSlowAppendCount(); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestMetricsWAL.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestMetricsWAL.java index ba6915b636e..2e2aa080e73 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestMetricsWAL.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestMetricsWAL.java @@ -66,4 +66,15 @@ public class TestMetricsWAL { metricsWAL.postAppend(1, 2000); assertEquals(2, source.getSlowAppendCount()); } + + @Test + public void testWalWrittenInBytes() throws Exception { + MetricsWALSource source = mock(MetricsWALSourceImpl.class); + MetricsWAL metricsWAL = new MetricsWAL(source); + metricsWAL.postAppend(100, 900); + metricsWAL.postAppend(200, 2000); + verify(source, times(1)).incrementWrittenBytes(100); + verify(source, times(1)).incrementWrittenBytes(200); + } + } \ No newline at end of file