HBASE-9650 Per region metrics are not showing up for system tables.

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1526309 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
eclark 2013-09-25 21:41:05 +00:00
parent e08500578c
commit e0768e0814
11 changed files with 107 additions and 70 deletions

View File

@ -31,6 +31,12 @@ public interface MetricsRegionWrapper {
*/ */
String getTableName(); String getTableName();
/**
* Get the name of the namespace this table is in.
* @return String version of the namespace. Can't be empty.
*/
String getNamespace();
/** /**
* Get the name of the region. * Get the name of the region.
* *

View File

@ -24,7 +24,7 @@ import org.apache.hadoop.metrics2.MetricsRecordBuilder;
import org.apache.hadoop.metrics2.impl.JmxCacheBuster; import org.apache.hadoop.metrics2.impl.JmxCacheBuster;
import org.apache.hadoop.metrics2.lib.DynamicMetricsRegistry; import org.apache.hadoop.metrics2.lib.DynamicMetricsRegistry;
import org.apache.hadoop.metrics2.lib.MetricMutableCounterLong; import org.apache.hadoop.metrics2.lib.MetricMutableCounterLong;
import org.apache.hadoop.metrics2.lib.MetricMutableStat; import org.apache.hadoop.metrics2.lib.MetricMutableHistogram;
public class MetricsRegionSourceImpl implements MetricsRegionSource { public class MetricsRegionSourceImpl implements MetricsRegionSource {
@ -46,8 +46,8 @@ public class MetricsRegionSourceImpl implements MetricsRegionSource {
private MetricMutableCounterLong regionIncrement; private MetricMutableCounterLong regionIncrement;
private MetricMutableCounterLong regionAppend; private MetricMutableCounterLong regionAppend;
private MetricMutableStat regionGet; private MetricMutableHistogram regionGet;
private MetricMutableStat regionScanNext; private MetricMutableHistogram regionScanNext;
public MetricsRegionSourceImpl(MetricsRegionWrapper regionWrapper, public MetricsRegionSourceImpl(MetricsRegionWrapper regionWrapper,
MetricsRegionAggregateSourceImpl aggregate) { MetricsRegionAggregateSourceImpl aggregate) {
@ -56,14 +56,14 @@ public class MetricsRegionSourceImpl implements MetricsRegionSource {
agg.register(this); agg.register(this);
LOG.debug("Creating new MetricsRegionSourceImpl for table " + LOG.debug("Creating new MetricsRegionSourceImpl for table " +
regionWrapper.getTableName() + regionWrapper.getTableName() + " " + regionWrapper.getRegionName());
" " +
regionWrapper.getRegionName());
registry = agg.getMetricsRegistry(); registry = agg.getMetricsRegistry();
regionNamePrefix = "table." + regionWrapper.getTableName() + "." regionNamePrefix = "namespace_" + regionWrapper.getNamespace() +
+ "region." + regionWrapper.getRegionName() + "."; "_table_" + regionWrapper.getTableName() +
"_region_" + regionWrapper.getRegionName() +
"_metric_";
String suffix = "Count"; String suffix = "Count";
@ -81,10 +81,10 @@ public class MetricsRegionSourceImpl implements MetricsRegionSource {
regionAppend = registry.getLongCounter(regionAppendKey, 0l); regionAppend = registry.getLongCounter(regionAppendKey, 0l);
regionGetKey = regionNamePrefix + MetricsRegionServerSource.GET_KEY; regionGetKey = regionNamePrefix + MetricsRegionServerSource.GET_KEY;
regionGet = registry.newStat(regionGetKey, "", OPS_SAMPLE_NAME, SIZE_VALUE_NAME); regionGet = registry.newHistogram(regionGetKey);
regionScanNextKey = regionNamePrefix + MetricsRegionServerSource.SCAN_NEXT_KEY; regionScanNextKey = regionNamePrefix + MetricsRegionServerSource.SCAN_NEXT_KEY;
regionScanNext = registry.newStat(regionScanNextKey, "", OPS_SAMPLE_NAME, SIZE_VALUE_NAME); regionScanNext = registry.newHistogram(regionScanNextKey);
} }
@Override @Override

View File

@ -20,6 +20,7 @@ package org.apache.hadoop.hbase.thrift;
import org.apache.hadoop.hbase.metrics.BaseSourceImpl; import org.apache.hadoop.hbase.metrics.BaseSourceImpl;
import org.apache.hadoop.metrics2.lib.MetricMutableGaugeLong; import org.apache.hadoop.metrics2.lib.MetricMutableGaugeLong;
import org.apache.hadoop.metrics2.lib.MetricMutableHistogram;
import org.apache.hadoop.metrics2.lib.MetricMutableStat; import org.apache.hadoop.metrics2.lib.MetricMutableStat;
/** /**
@ -31,12 +32,12 @@ public class MetricsThriftServerSourceImpl extends BaseSourceImpl implements
MetricsThriftServerSource { MetricsThriftServerSource {
private MetricMutableStat batchGetStat; private MetricMutableHistogram batchGetStat;
private MetricMutableStat batchMutateStat; private MetricMutableHistogram batchMutateStat;
private MetricMutableStat queueTimeStat; private MetricMutableHistogram queueTimeStat;
private MetricMutableStat thriftCallStat; private MetricMutableHistogram thriftCallStat;
private MetricMutableStat thriftSlowCallStat; private MetricMutableHistogram thriftSlowCallStat;
private MetricMutableGaugeLong callQueueLenGauge; private MetricMutableGaugeLong callQueueLenGauge;
@ -51,11 +52,11 @@ public class MetricsThriftServerSourceImpl extends BaseSourceImpl implements
@Override @Override
public void init() { public void init() {
super.init(); super.init();
batchGetStat = getMetricsRegistry().newStat(BATCH_GET_KEY, "", "Keys", "Ops"); batchGetStat = getMetricsRegistry().newHistogram(BATCH_GET_KEY);
batchMutateStat = getMetricsRegistry().newStat(BATCH_MUTATE_KEY, "", "Keys", "Ops"); batchMutateStat = getMetricsRegistry().newHistogram(BATCH_MUTATE_KEY);
queueTimeStat = getMetricsRegistry().newStat(TIME_IN_QUEUE_KEY); queueTimeStat = getMetricsRegistry().newHistogram(TIME_IN_QUEUE_KEY);
thriftCallStat = getMetricsRegistry().newStat(THRIFT_CALL_KEY); thriftCallStat = getMetricsRegistry().newHistogram(THRIFT_CALL_KEY);
thriftSlowCallStat = getMetricsRegistry().newStat(SLOW_THRIFT_CALL_KEY); thriftSlowCallStat = getMetricsRegistry().newHistogram(SLOW_THRIFT_CALL_KEY);
callQueueLenGauge = getMetricsRegistry().getLongGauge(CALL_QUEUE_LEN_KEY, 0); callQueueLenGauge = getMetricsRegistry().getLongGauge(CALL_QUEUE_LEN_KEY, 0);
} }
@ -81,7 +82,7 @@ public class MetricsThriftServerSourceImpl extends BaseSourceImpl implements
@Override @Override
public void incMethodTime(String name, long time) { public void incMethodTime(String name, long time) {
MetricMutableStat s = getMetricsRegistry().newStat(name); MetricMutableHistogram s = getMetricsRegistry().getHistogram(name);
s.add(time); s.add(time);
} }

View File

@ -60,7 +60,12 @@ public class TestMetricsRegionSourceImpl {
@Override @Override
public String getTableName() { public String getTableName() {
return null; //To change body of implemented methods use File | Settings | File Templates. return null;
}
@Override
public String getNamespace() {
return null;
} }
@Override @Override
@ -70,32 +75,32 @@ public class TestMetricsRegionSourceImpl {
@Override @Override
public long getNumStores() { public long getNumStores() {
return 0; //To change body of implemented methods use File | Settings | File Templates. return 0;
} }
@Override @Override
public long getNumStoreFiles() { public long getNumStoreFiles() {
return 0; //To change body of implemented methods use File | Settings | File Templates. return 0;
} }
@Override @Override
public long getMemstoreSize() { public long getMemstoreSize() {
return 0; //To change body of implemented methods use File | Settings | File Templates. return 0;
} }
@Override @Override
public long getStoreFileSize() { public long getStoreFileSize() {
return 0; //To change body of implemented methods use File | Settings | File Templates. return 0;
} }
@Override @Override
public long getReadRequestCount() { public long getReadRequestCount() {
return 0; //To change body of implemented methods use File | Settings | File Templates. return 0;
} }
@Override @Override
public long getWriteRequestCount() { public long getWriteRequestCount() {
return 0; //To change body of implemented methods use File | Settings | File Templates. return 0;
} }
} }
} }

View File

@ -26,7 +26,7 @@ import org.apache.hadoop.metrics2.impl.JmxCacheBuster;
import org.apache.hadoop.metrics2.lib.DynamicMetricsRegistry; import org.apache.hadoop.metrics2.lib.DynamicMetricsRegistry;
import org.apache.hadoop.metrics2.lib.Interns; import org.apache.hadoop.metrics2.lib.Interns;
import org.apache.hadoop.metrics2.lib.MutableCounterLong; import org.apache.hadoop.metrics2.lib.MutableCounterLong;
import org.apache.hadoop.metrics2.lib.MutableStat; import org.apache.hadoop.metrics2.lib.MutableHistogram;
@InterfaceAudience.Private @InterfaceAudience.Private
public class MetricsRegionSourceImpl implements MetricsRegionSource { public class MetricsRegionSourceImpl implements MetricsRegionSource {
@ -52,8 +52,8 @@ public class MetricsRegionSourceImpl implements MetricsRegionSource {
private MutableCounterLong regionIncrement; private MutableCounterLong regionIncrement;
private MutableCounterLong regionAppend; private MutableCounterLong regionAppend;
private MutableStat regionGet; private MutableHistogram regionGet;
private MutableStat regionScanNext; private MutableHistogram regionScanNext;
public MetricsRegionSourceImpl(MetricsRegionWrapper regionWrapper, public MetricsRegionSourceImpl(MetricsRegionWrapper regionWrapper,
MetricsRegionAggregateSourceImpl aggregate) { MetricsRegionAggregateSourceImpl aggregate) {
@ -62,14 +62,14 @@ public class MetricsRegionSourceImpl implements MetricsRegionSource {
agg.register(this); agg.register(this);
LOG.debug("Creating new MetricsRegionSourceImpl for table " + LOG.debug("Creating new MetricsRegionSourceImpl for table " +
regionWrapper.getTableName() + regionWrapper.getTableName() + " " + regionWrapper.getRegionName());
" " +
regionWrapper.getRegionName());
registry = agg.getMetricsRegistry(); registry = agg.getMetricsRegistry();
regionNamePrefix = "table." + regionWrapper.getTableName() + "." regionNamePrefix = "namespace_" + regionWrapper.getNamespace() +
+ "region." + regionWrapper.getRegionName() + "."; "_table_" + regionWrapper.getTableName() +
"_region_" + regionWrapper.getRegionName() +
"_metric_";
String suffix = "Count"; String suffix = "Count";
@ -86,10 +86,10 @@ public class MetricsRegionSourceImpl implements MetricsRegionSource {
regionAppend = registry.getLongCounter(regionAppendKey, 0l); regionAppend = registry.getLongCounter(regionAppendKey, 0l);
regionGetKey = regionNamePrefix + MetricsRegionServerSource.GET_KEY; regionGetKey = regionNamePrefix + MetricsRegionServerSource.GET_KEY;
regionGet = registry.newStat(regionGetKey, "", OPS_SAMPLE_NAME, SIZE_VALUE_NAME); regionGet = registry.newHistogram(regionGetKey);
regionScanNextKey = regionNamePrefix + MetricsRegionServerSource.SCAN_NEXT_KEY; regionScanNextKey = regionNamePrefix + MetricsRegionServerSource.SCAN_NEXT_KEY;
regionScanNext = registry.newStat(regionScanNextKey, "", OPS_SAMPLE_NAME, SIZE_VALUE_NAME); regionScanNext = registry.newHistogram(regionScanNextKey);
} }
@Override @Override

View File

@ -21,7 +21,7 @@ package org.apache.hadoop.hbase.thrift;
import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.hbase.metrics.BaseSourceImpl; import org.apache.hadoop.hbase.metrics.BaseSourceImpl;
import org.apache.hadoop.metrics2.lib.MutableGaugeLong; import org.apache.hadoop.metrics2.lib.MutableGaugeLong;
import org.apache.hadoop.metrics2.lib.MutableStat; import org.apache.hadoop.metrics2.lib.MutableHistogram;
/** /**
* Hadoop 2 version of MetricsThriftServerSource{@link org.apache.hadoop.hbase.thrift.MetricsThriftServerSource} * Hadoop 2 version of MetricsThriftServerSource{@link org.apache.hadoop.hbase.thrift.MetricsThriftServerSource}
@ -32,12 +32,12 @@ import org.apache.hadoop.metrics2.lib.MutableStat;
public class MetricsThriftServerSourceImpl extends BaseSourceImpl implements public class MetricsThriftServerSourceImpl extends BaseSourceImpl implements
MetricsThriftServerSource { MetricsThriftServerSource {
private MutableStat batchGetStat; private MutableHistogram batchGetStat;
private MutableStat batchMutateStat; private MutableHistogram batchMutateStat;
private MutableStat queueTimeStat; private MutableHistogram queueTimeStat;
private MutableStat thriftCallStat; private MutableHistogram thriftCallStat;
private MutableStat thriftSlowCallStat; private MutableHistogram thriftSlowCallStat;
private MutableGaugeLong callQueueLenGauge; private MutableGaugeLong callQueueLenGauge;
@ -51,13 +51,11 @@ public class MetricsThriftServerSourceImpl extends BaseSourceImpl implements
@Override @Override
public void init() { public void init() {
super.init(); super.init();
batchGetStat = getMetricsRegistry().newStat(BATCH_GET_KEY, "", "Keys", "Ops"); batchGetStat = getMetricsRegistry().newHistogram(BATCH_GET_KEY);
batchMutateStat = getMetricsRegistry().newStat(BATCH_MUTATE_KEY, "", "Keys", "Ops"); batchMutateStat = getMetricsRegistry().newHistogram(BATCH_MUTATE_KEY);
queueTimeStat = getMetricsRegistry().newRate(TIME_IN_QUEUE_KEY); queueTimeStat = getMetricsRegistry().newHistogram(TIME_IN_QUEUE_KEY);
thriftCallStat = getMetricsRegistry().newHistogram(THRIFT_CALL_KEY);
thriftCallStat = getMetricsRegistry().newRate(THRIFT_CALL_KEY); thriftSlowCallStat = getMetricsRegistry().newHistogram(SLOW_THRIFT_CALL_KEY);
thriftSlowCallStat = getMetricsRegistry().newRate(SLOW_THRIFT_CALL_KEY);
callQueueLenGauge = getMetricsRegistry().getLongGauge(CALL_QUEUE_LEN_KEY, 0); callQueueLenGauge = getMetricsRegistry().getLongGauge(CALL_QUEUE_LEN_KEY, 0);
} }
@ -84,7 +82,7 @@ public class MetricsThriftServerSourceImpl extends BaseSourceImpl implements
@Override @Override
public void incMethodTime(String name, long time) { public void incMethodTime(String name, long time) {
MutableStat s = getMetricsRegistry().newRate(name); MutableHistogram s = getMetricsRegistry().getHistogram(name);
s.add(time); s.add(time);
} }

View File

@ -60,7 +60,12 @@ public class TestMetricsRegionSourceImpl {
@Override @Override
public String getTableName() { public String getTableName() {
return null; //To change body of implemented methods use File | Settings | File Templates. return null;
}
@Override
public String getNamespace() {
return null;
} }
@Override @Override
@ -70,32 +75,32 @@ public class TestMetricsRegionSourceImpl {
@Override @Override
public long getNumStores() { public long getNumStores() {
return 0; //To change body of implemented methods use File | Settings | File Templates. return 0;
} }
@Override @Override
public long getNumStoreFiles() { public long getNumStoreFiles() {
return 0; //To change body of implemented methods use File | Settings | File Templates. return 0;
} }
@Override @Override
public long getMemstoreSize() { public long getMemstoreSize() {
return 0; //To change body of implemented methods use File | Settings | File Templates. return 0;
} }
@Override @Override
public long getStoreFileSize() { public long getStoreFileSize() {
return 0; //To change body of implemented methods use File | Settings | File Templates. return 0;
} }
@Override @Override
public long getReadRequestCount() { public long getReadRequestCount() {
return 0; //To change body of implemented methods use File | Settings | File Templates. return 0;
} }
@Override @Override
public long getWriteRequestCount() { public long getWriteRequestCount() {
return 0; //To change body of implemented methods use File | Settings | File Templates. return 0;
} }
} }
} }

View File

@ -33,6 +33,7 @@ import java.util.concurrent.TimeUnit;
public class MetricsRegionWrapperImpl implements MetricsRegionWrapper, Closeable { public class MetricsRegionWrapperImpl implements MetricsRegionWrapper, Closeable {
public static final int PERIOD = 45; public static final int PERIOD = 45;
public static final String UNKNOWN = "unknown";
private final HRegion region; private final HRegion region;
private ScheduledExecutorService executor; private ScheduledExecutorService executor;
@ -55,16 +56,26 @@ public class MetricsRegionWrapperImpl implements MetricsRegionWrapper, Closeable
public String getTableName() { public String getTableName() {
HTableDescriptor tableDesc = this.region.getTableDesc(); HTableDescriptor tableDesc = this.region.getTableDesc();
if (tableDesc == null) { if (tableDesc == null) {
return ""; return UNKNOWN;
} }
return tableDesc.getTableName().getNameAsString(); return tableDesc.getTableName().getQualifierAsString();
} }
@Override
public String getNamespace() {
HTableDescriptor tableDesc = this.region.getTableDesc();
if (tableDesc == null) {
return UNKNOWN;
}
return tableDesc.getTableName().getNamespaceAsString();
}
@Override @Override
public String getRegionName() { public String getRegionName() {
HRegionInfo regionInfo = this.region.getRegionInfo(); HRegionInfo regionInfo = this.region.getRegionInfo();
if (regionInfo == null) { if (regionInfo == null) {
return ""; return UNKNOWN;
} }
return regionInfo.getEncodedName(); return regionInfo.getEncodedName();
} }

View File

@ -25,6 +25,11 @@ public class MetricsRegionWrapperStub implements MetricsRegionWrapper {
return "MetricsRegionWrapperStub"; return "MetricsRegionWrapperStub";
} }
@Override
public String getNamespace() {
return "TestNS";
}
@Override @Override
public String getRegionName() { public String getRegionName() {
return "DEADBEEF001"; return "DEADBEEF001";

View File

@ -35,9 +35,9 @@ public class TestMetricsRegion {
MetricsRegion mr = new MetricsRegion(new MetricsRegionWrapperStub()); MetricsRegion mr = new MetricsRegion(new MetricsRegionWrapperStub());
MetricsRegionAggregateSource agg = mr.getSource().getAggregateSource(); MetricsRegionAggregateSource agg = mr.getSource().getAggregateSource();
HELPER.assertGauge("table.MetricsRegionWrapperStub.region.DEADBEEF001.storeCount", 101, agg); HELPER.assertGauge("namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_storeCount", 101, agg);
HELPER.assertGauge("table.MetricsRegionWrapperStub.region.DEADBEEF001.storeFileCount", 102, agg); HELPER.assertGauge("namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_storeFileCount", 102, agg);
HELPER.assertGauge("table.MetricsRegionWrapperStub.region.DEADBEEF001.memstoreSize", 103, agg); HELPER.assertGauge("namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_memstoreSize", 103, agg);
mr.close(); mr.close();
} }
} }

View File

@ -141,9 +141,12 @@ public class TestRegionServerMetrics {
.getMetrics() .getMetrics()
.getSource() .getSource()
.getAggregateSource(); .getAggregateSource();
String prefix = "table."+tableNameString + ".region." + i.getEncodedName(); String prefix = "namespace_"+NamespaceDescriptor.DEFAULT_NAMESPACE_NAME_STR+
metricsHelper.assertCounter(prefix + ".getNumOps", 10, agg); "_table_"+tableNameString +
metricsHelper.assertCounter(prefix + ".mutateCount", 30, agg); "_region_" + i.getEncodedName()+
"_metric";
metricsHelper.assertCounter(prefix + "_getNumOps", 10, agg);
metricsHelper.assertCounter(prefix + "_mutateCount", 30, agg);
} }
@ -347,8 +350,11 @@ public class TestRegionServerMetrics {
.getMetrics() .getMetrics()
.getSource() .getSource()
.getAggregateSource(); .getAggregateSource();
String prefix = "table."+tableNameString + ".region." + i.getEncodedName(); String prefix = "namespace_"+NamespaceDescriptor.DEFAULT_NAMESPACE_NAME_STR+
metricsHelper.assertCounter(prefix + ".scanNextNumOps", 30, agg); "_table_"+tableNameString +
"_region_" + i.getEncodedName()+
"_metric";
metricsHelper.assertCounter(prefix + "_scanNextNumOps", 30, agg);
} }
} }
} }