HBASE-14082 Add replica id to JMX metrics names (Lei Chen)

This commit is contained in:
Enis Soztutar 2015-09-16 17:29:37 -07:00
parent c1ac4bb860
commit 17bdf9fa8c
7 changed files with 78 additions and 3 deletions

View File

@ -37,6 +37,8 @@ public interface MetricsRegionSource extends Comparable<MetricsRegionSource> {
"Number of files that were input for finished, successful or aborted, compactions";
String COPROCESSOR_EXECUTION_STATISTICS = "coprocessorExecutionStatistics";
String COPROCESSOR_EXECUTION_STATISTICS_DESC = "Statistics for coprocessor execution times";
String REPLICA_ID = "replicaid";
String REPLICA_ID_DESC = "The replica ID of a region. 0 is primary, otherwise is secondary";
/**
* Close the region's metrics as this region is closing.

View File

@ -90,4 +90,9 @@ public interface MetricsRegionWrapper {
* Get the time spent by coprocessors in this region.
*/
Map<String, DescriptiveStatistics> getCoprocessorExecutionStatistics();
/**
* Get the replica id of this region.
*/
int getReplicaId();
}

View File

@ -242,6 +242,9 @@ public class MetricsRegionSourceImpl implements MetricsRegionSource {
regionNamePrefix + MetricsRegionServerSource.WRITE_REQUEST_COUNT,
MetricsRegionServerSource.WRITE_REQUEST_COUNT_DESC),
this.regionWrapper.getWriteRequestCount());
mrb.addCounter(Interns.info(regionNamePrefix + MetricsRegionSource.REPLICA_ID,
MetricsRegionSource.REPLICA_ID_DESC),
this.regionWrapper.getReplicaId());
for (Map.Entry<String, DescriptiveStatistics> entry : this.regionWrapper
.getCoprocessorExecutionStatistics()

View File

@ -133,5 +133,13 @@ public class TestMetricsRegionSourceImpl {
public Map<String, DescriptiveStatistics> getCoprocessorExecutionStatistics() {
return null;
}
/**
* Always return 0 for testing
*/
@Override
public int getReplicaId() {
return 0;
}
}
}

View File

@ -174,4 +174,12 @@ public class MetricsRegionWrapperImpl implements MetricsRegionWrapper, Closeable
return coprocessorTimes;
}
/**
* Get the replica id of this region.
*/
@Override
public int getReplicaId() {
return region.getRegionInfo().getReplicaId();
}
}

View File

@ -24,6 +24,21 @@ import java.util.Map;
import org.apache.commons.math.stat.descriptive.DescriptiveStatistics;
public class MetricsRegionWrapperStub implements MetricsRegionWrapper {
int replicaid = 0;
/**
* Replica ID set to 0
*/
public MetricsRegionWrapperStub() {
this.replicaid = 0;
}
/**
* Pass in replica ID
*/
public MetricsRegionWrapperStub(int replicaid) {
this.replicaid = replicaid;
}
@Override
public String getTableName() {
@ -94,4 +109,12 @@ public class MetricsRegionWrapperStub implements MetricsRegionWrapper {
public Map<String, DescriptiveStatistics> getCoprocessorExecutionStatistics() {
return new HashMap<String, DescriptiveStatistics>();
}
/**
* Get the replica id of this region.
*/
@Override
public int getReplicaId() {
return replicaid;
}
}

View File

@ -36,9 +36,35 @@ public class TestMetricsRegion {
MetricsRegion mr = new MetricsRegion(new MetricsRegionWrapperStub());
MetricsRegionAggregateSource agg = mr.getSource().getAggregateSource();
HELPER.assertGauge("namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_storeCount", 101, agg);
HELPER.assertGauge("namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_storeFileCount", 102, agg);
HELPER.assertGauge("namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_memstoreSize", 103, agg);
HELPER.assertGauge(
"namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_storeCount",
101, agg);
HELPER.assertGauge(
"namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_storeFileCount",
102, agg);
HELPER.assertGauge(
"namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_memstoreSize",
103, agg);
HELPER.assertCounter(
"namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_replicaid",
0, agg);
mr.close();
// test region with replica id > 0
mr = new MetricsRegion(new MetricsRegionWrapperStub(1));
agg = mr.getSource().getAggregateSource();
HELPER.assertGauge(
"namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_storeCount",
101, agg);
HELPER.assertGauge(
"namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_storeFileCount",
102, agg);
HELPER.assertGauge(
"namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_memstoreSize",
103, agg);
HELPER.assertCounter(
"namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_replicaid",
1, agg);
mr.close();
}
}