HBASE-15671 Add per-table metrics on memstore, storefile and regionsize (Alicia Ying Shu)

This commit is contained in:
Enis Soztutar 2016-04-21 13:33:26 -07:00
parent 9ba9cdeb47
commit 4c0587134a
7 changed files with 129 additions and 5 deletions

View File

@ -30,6 +30,12 @@ public interface MetricsTableSource extends Comparable<MetricsTableSource> {
String WRITE_REQUEST_COUNT_DESC = "Number fo write requests";
String TOTAL_REQUEST_COUNT = "totalRequestCount";
String TOTAL_REQUEST_COUNT_DESC = "Number fo total requests";
String MEMSTORE_SIZE = "memstoreSize";
String MEMSTORE_SIZE_DESC = "The size of memory stores";
String STORE_FILE_SIZE = "storeFileSize";
String STORE_FILE_SIZE_DESC = "The size of store files size";
String TABLE_SIZE = "tableSize";
String TABLE_SIZE_DESC = "Total size of the table in the region server";
String getTableName();

View File

@ -39,4 +39,19 @@ public interface MetricsTableWrapperAggregate {
* Get the total number of requests that have been issued against this table
*/
long getTotalRequestsCount(String table);
/**
* Get the memory store size against this table
*/
long getMemstoresSize(String table);
/**
* Get the store file size against this table
*/
long getStoreFilesSize(String table);
/**
* Get the table region size against this table
*/
long getTableSize(String table);
}

View File

@ -131,6 +131,15 @@ public class MetricsTableSourceImpl implements MetricsTableSource {
mrb.addCounter(Interns.info(tableNamePrefix + MetricsTableSource.TOTAL_REQUEST_COUNT,
MetricsTableSource.TOTAL_REQUEST_COUNT_DESC),
tableWrapperAgg.getTotalRequestsCount(tableName.getNameAsString()));
mrb.addGauge(Interns.info(tableNamePrefix + MetricsTableSource.MEMSTORE_SIZE,
MetricsTableSource.MEMSTORE_SIZE_DESC),
tableWrapperAgg.getMemstoresSize(tableName.getNameAsString()));
mrb.addGauge(Interns.info(tableNamePrefix + MetricsTableSource.STORE_FILE_SIZE,
MetricsTableSource.STORE_FILE_SIZE_DESC),
tableWrapperAgg.getStoreFilesSize(tableName.getNameAsString()));
mrb.addGauge(Interns.info(tableNamePrefix + MetricsTableSource.TABLE_SIZE,
MetricsTableSource.TABLE_SIZE_DESC),
tableWrapperAgg.getTableSize(tableName.getNameAsString()));
}
}
}

View File

@ -91,6 +91,21 @@ public class TestMetricsTableSourceImpl {
return 30;
}
@Override
public long getMemstoresSize(String table) {
return 1000;
}
@Override
public long getStoreFilesSize(String table) {
return 2000;
}
@Override
public long getTableSize(String table) {
return 3000;
}
public String getTableName() {
return tableName;
}

View File

@ -21,7 +21,6 @@ package org.apache.hadoop.hbase.regionserver;
import java.io.Closeable;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
@ -69,6 +68,13 @@ public class MetricsTableWrapperAggregateImpl implements MetricsTableWrapperAggr
metricsTable = new MetricsTableValues();
localMetricsTableMap.put(tbl, metricsTable);
}
long tempStorefilesSize = 0;
for (Store store : r.getStores()) {
tempStorefilesSize += store.getStorefilesSize();
}
metricsTable.setMemstoresSize(metricsTable.getMemstoresSize() + r.getMemstoreSize());
metricsTable.setStoreFilesSize(metricsTable.getStoreFilesSize() + tempStorefilesSize);
metricsTable.setTableSize(metricsTable.getMemstoresSize() + metricsTable.getStoreFilesSize());
metricsTable.setReadRequestsCount(metricsTable.getReadRequestsCount() + r.getReadRequestsCount());
metricsTable.setWriteRequestsCount(metricsTable.getWriteRequestsCount() + r.getWriteRequestsCount());
metricsTable.setTotalRequestsCount(metricsTable.getReadRequestsCount() + metricsTable.getWriteRequestsCount());
@ -126,6 +132,33 @@ public class MetricsTableWrapperAggregateImpl implements MetricsTableWrapperAggr
return metricsTable.getTotalRequestsCount();
}
@Override
public long getMemstoresSize(String table) {
MetricsTableValues metricsTable = metricsTableMap.get(TableName.valueOf(table));
if (metricsTable == null)
return 0;
else
return metricsTable.getMemstoresSize();
}
@Override
public long getStoreFilesSize(String table) {
MetricsTableValues metricsTable = metricsTableMap.get(TableName.valueOf(table));
if (metricsTable == null)
return 0;
else
return metricsTable.getStoreFilesSize();
}
@Override
public long getTableSize(String table) {
MetricsTableValues metricsTable = metricsTableMap.get(TableName.valueOf(table));
if (metricsTable == null)
return 0;
else
return metricsTable.getTableSize();
}
@Override
public void close() throws IOException {
tableMetricsUpdateTask.cancel(true);
@ -136,6 +169,9 @@ public class MetricsTableWrapperAggregateImpl implements MetricsTableWrapperAggr
private long totalRequestsCount;
private long readRequestsCount;
private long writeRequestsCount;
private long memstoresSize;
private long storeFilesSize;
private long tableSize;
public long getTotalRequestsCount() {
return totalRequestsCount;
@ -160,6 +196,30 @@ public class MetricsTableWrapperAggregateImpl implements MetricsTableWrapperAggr
public void setWriteRequestsCount(long writeRequestsCount) {
this.writeRequestsCount = writeRequestsCount;
}
public long getMemstoresSize() {
return memstoresSize;
}
public void setMemstoresSize(long memstoresSize) {
this.memstoresSize = memstoresSize;
}
public long getStoreFilesSize() {
return storeFilesSize;
}
public void setStoreFilesSize(long storeFilesSize) {
this.storeFilesSize = storeFilesSize;
}
public long getTableSize() {
return tableSize;
}
public void setTableSize(long tableSize) {
this.tableSize = tableSize;
}
}
}

View File

@ -41,6 +41,21 @@ public class MetricsTableWrapperStub implements MetricsTableWrapperAggregate {
return 30;
}
@Override
public long getMemstoresSize(String table) {
return 1000;
}
@Override
public long getStoreFilesSize(String table) {
return 2000;
}
@Override
public long getTableSize(String table) {
return 3000;
}
public String getTableName() {
return tableName;
}

View File

@ -34,15 +34,19 @@ public class TestMetricsTableAggregate {
@Test
public void testTableWrapperAggregateMetrics() throws IOException {
String tableName = "testRequestCount";
String tableName = "testTableMetrics";
MetricsTableWrapperStub tableWrapper = new MetricsTableWrapperStub(tableName);
CompatibilitySingletonFactory.getInstance(MetricsRegionServerSourceFactory.class)
.createTable(tableName, tableWrapper);
MetricsTableAggregateSource agg = CompatibilitySingletonFactory
.getInstance(MetricsRegionServerSourceFactory.class).getTableAggregate();
HELPER.assertCounter("Namespace_default_table_testRequestCount_metric_readRequestCount", 10, agg);
HELPER.assertCounter("Namespace_default_table_testRequestCount_metric_writeRequestCount", 20, agg);
HELPER.assertCounter("Namespace_default_table_testRequestCount_metric_totalRequestCount", 30, agg);
HELPER.assertCounter("Namespace_default_table_testTableMetrics_metric_readRequestCount", 10, agg);
HELPER.assertCounter("Namespace_default_table_testTableMetrics_metric_writeRequestCount", 20, agg);
HELPER.assertCounter("Namespace_default_table_testTableMetrics_metric_totalRequestCount", 30, agg);
HELPER.assertGauge("Namespace_default_table_testTableMetrics_metric_memstoreSize", 1000, agg);
HELPER.assertGauge("Namespace_default_table_testTableMetrics_metric_storeFileSize", 2000, agg);
HELPER.assertGauge("Namespace_default_table_testTableMetrics_metric_tableSize", 3000, agg);
}
}