HBASE-15435 Add WAL (in bytes) written metric (Alicia Ying Shu)

This commit is contained in:
Enis Soztutar 2016-03-10 19:30:31 -08:00
parent 6628d2df11
commit a979d85582
4 changed files with 31 additions and 0 deletions

View File

@ -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();
}

View File

@ -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();
}
}

View File

@ -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();

View File

@ -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);
}
}