HBASE-21107 add a metrics for netty direct memory

This commit is contained in:
Huaxiang Sun 2018-09-05 16:03:07 -07:00 committed by Huaxiang Sun
parent b7cdfe3ab0
commit bdc168713d
6 changed files with 39 additions and 1 deletions

View File

@ -95,6 +95,11 @@ public interface MetricsHBaseServerSource extends ExceptionTrackingSource {
String NUM_LIFO_MODE_SWITCHES_NAME = "numLifoModeSwitches";
String NUM_LIFO_MODE_SWITCHES_DESC = "Total number of calls in general queue which " +
"were served from the tail of the queue";
// Direct Memory Usage metrics
String NETTY_DM_USAGE_NAME = "nettyDirectMemoryUsage";
String NETTY_DM_USAGE_DESC = "Current Netty direct memory usage.";
void authorizationSuccess();

View File

@ -56,4 +56,6 @@ public interface MetricsHBaseServerWrapper {
int getActiveReadRpcHandlerCount();
int getActiveScanRpcHandlerCount();
long getNettyDmUsage();
}

View File

@ -179,7 +179,9 @@ public class MetricsHBaseServerSourceImpl extends ExceptionTrackingSourceImpl
.addGauge(Interns.info(NUM_ACTIVE_READ_HANDLER_NAME, NUM_ACTIVE_READ_HANDLER_DESC),
wrapper.getActiveReadRpcHandlerCount())
.addGauge(Interns.info(NUM_ACTIVE_SCAN_HANDLER_NAME, NUM_ACTIVE_SCAN_HANDLER_DESC),
wrapper.getActiveScanRpcHandlerCount());
wrapper.getActiveScanRpcHandlerCount())
.addGauge(Interns.info(NETTY_DM_USAGE_NAME, NETTY_DM_USAGE_DESC),
wrapper.getNettyDmUsage());
}
metricsRegistry.snapshot(mrb, all);

View File

@ -19,6 +19,7 @@
package org.apache.hadoop.hbase.ipc;
import org.apache.hadoop.hbase.util.DirectMemoryUtils;
import org.apache.yetus.audience.InterfaceAudience;
@InterfaceAudience.Private
@ -169,4 +170,13 @@ public class MetricsHBaseServerWrapperImpl implements MetricsHBaseServerWrapper
}
return server.getScheduler().getActiveScanRpcHandlerCount();
}
@Override
public long getNettyDmUsage() {
if (!isServerStarted() || this.server.getScheduler() == null) {
return 0L;
}
return DirectMemoryUtils.getNettyDirectMemoryUsage();
}
}

View File

@ -37,6 +37,10 @@ import org.apache.yetus.audience.InterfaceStability;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.hbase.thirdparty.com.google.common.base.Preconditions;
import org.apache.hbase.thirdparty.io.netty.buffer.ByteBufAllocatorMetric;
import org.apache.hbase.thirdparty.io.netty.buffer.ByteBufAllocatorMetricProvider;
import org.apache.hbase.thirdparty.io.netty.buffer.PooledByteBufAllocator;
/**
* Utilities for interacting with and monitoring DirectByteBuffer allocations.
@ -124,6 +128,16 @@ public class DirectMemoryUtils {
}
}
/**
* @return the current amount of direct memory used by netty module.
*/
public static long getNettyDirectMemoryUsage() {
ByteBufAllocatorMetric metric = ((ByteBufAllocatorMetricProvider)
PooledByteBufAllocator.DEFAULT).metric();
return metric.usedDirectMemory();
}
/**
* DirectByteBuffers are garbage collected by using a phantom reference and a
* reference queue. Every once a while, the JVM checks the reference queue and

View File

@ -103,4 +103,9 @@ public class MetricsHBaseServerWrapperStub implements MetricsHBaseServerWrapper{
public int getActiveScanRpcHandlerCount() {
return 6;
}
@Override
public long getNettyDmUsage() {
return 100L;
}
}