use of org.apache.hadoop.hbase.metrics.MetricRegistry in project hbase by apache.
the class TestCoprocessorMetrics method testRegionObserverEndpoint.
@Test
public void testRegionObserverEndpoint() throws IOException, ServiceException {
final TableName tableName = TableName.valueOf(name.getMethodName());
try (Connection connection = ConnectionFactory.createConnection(UTIL.getConfiguration());
Admin admin = connection.getAdmin()) {
admin.createTable(new HTableDescriptor(tableName).addFamily(new HColumnDescriptor(foo)).addCoprocessor(CustomRegionEndpoint.class.getName()));
try (Table table = connection.getTable(tableName)) {
List<Mutation> mutations = Lists.newArrayList(new Put(foo), new Put(bar));
MutateRowsRequest.Builder mrmBuilder = MutateRowsRequest.newBuilder();
for (Mutation mutation : mutations) {
mrmBuilder.addMutationRequest(ProtobufUtil.toMutation(ClientProtos.MutationProto.MutationType.PUT, mutation));
}
CoprocessorRpcChannel channel = table.coprocessorService(bar);
MultiRowMutationService.BlockingInterface service = MultiRowMutationService.newBlockingStub(channel);
MutateRowsRequest mrm = mrmBuilder.build();
service.mutateRows(null, mrm);
}
}
// Find out the MetricRegistry used by the CP using the global registries
MetricRegistryInfo info = MetricsCoprocessor.createRegistryInfoForRegionCoprocessor(CustomRegionEndpoint.class.getName());
Optional<MetricRegistry> registry = MetricRegistries.global().get(info);
assertTrue(registry.isPresent());
Optional<Metric> metric = registry.get().get("EndpointExecution");
assertTrue(metric.isPresent());
Timer endpointExecutions = (Timer) metric.get();
assertEquals(1, endpointExecutions.getHistogram().getCount());
}
use of org.apache.hadoop.hbase.metrics.MetricRegistry in project hbase by apache.
the class TestCoprocessorMetrics method testMasterObserver.
@Test
public void testMasterObserver() throws IOException {
// Find out the MetricRegistry used by the CP using the global registries
MetricRegistryInfo info = MetricsCoprocessor.createRegistryInfoForMasterCoprocessor(CustomMasterObserver.class.getName());
Optional<MetricRegistry> registry = MetricRegistries.global().get(info);
assertTrue(registry.isPresent());
Optional<Metric> metric = registry.get().get("CreateTable");
assertTrue(metric.isPresent());
try (Connection connection = ConnectionFactory.createConnection(UTIL.getConfiguration());
Admin admin = connection.getAdmin()) {
Timer createTableTimer = (Timer) metric.get();
long prevCount = createTableTimer.getHistogram().getCount();
LOG.info("Creating table");
admin.createTable(new HTableDescriptor(TableName.valueOf(name.getMethodName())).addFamily(new HColumnDescriptor("foo")));
assertEquals(1, createTableTimer.getHistogram().getCount() - prevCount);
}
}
use of org.apache.hadoop.hbase.metrics.MetricRegistry in project hbase by apache.
the class GlobalMetricRegistriesAdapter method doRun.
private void doRun() {
if (stopped.get()) {
executor.stop();
return;
}
if (LOG.isTraceEnabled()) {
LOG.trace("doRun called: " + registeredSources);
}
Collection<MetricRegistry> registries = MetricRegistries.global().getMetricRegistries();
for (MetricRegistry registry : registries) {
MetricRegistryInfo info = registry.getMetricRegistryInfo();
if (info.isExistingSource()) {
// MetricRecordBuilder there (see MetricsRegionServerSourceImpl).
continue;
}
if (!registeredSources.containsKey(info)) {
if (LOG.isDebugEnabled()) {
LOG.debug("Registering adapter for the MetricRegistry: " + info.getMetricsJmxContext());
}
// register this as a MetricSource under different JMX Context'es.
MetricsSourceAdapter adapter = new MetricsSourceAdapter(registry);
LOG.info("Registering " + info.getMetricsJmxContext() + " " + info.getMetricsDescription());
DefaultMetricsSystem.instance().register(info.getMetricsJmxContext(), info.getMetricsDescription(), adapter);
registeredSources.put(info, adapter);
// next collection will collect the newly registered MetricSource. Doing this here leads to
// ConcurrentModificationException.
}
}
boolean removed = false;
// Remove registered sources if it is removed from the global registry
for (Iterator<Entry<MetricRegistryInfo, MetricsSourceAdapter>> it = registeredSources.entrySet().iterator(); it.hasNext(); ) {
Entry<MetricRegistryInfo, MetricsSourceAdapter> entry = it.next();
MetricRegistryInfo info = entry.getKey();
Optional<MetricRegistry> found = MetricRegistries.global().get(info);
if (!found.isPresent()) {
if (LOG.isDebugEnabled()) {
LOG.debug("Removing adapter for the MetricRegistry: " + info.getMetricsJmxContext());
}
synchronized (DefaultMetricsSystem.instance()) {
DefaultMetricsSystem.instance().unregisterSource(info.getMetricsJmxContext());
helper.removeSourceName(info.getMetricsJmxContext());
helper.removeObjectName(info.getMetricsJmxContext());
it.remove();
removed = true;
}
}
}
if (removed) {
JmxCacheBuster.clearJmxCache();
}
}
Aggregations