Search in sources :

Example 6 with MetricRegistry

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());
}
Also used : Table(org.apache.hadoop.hbase.client.Table) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) CoprocessorRpcChannel(org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel) MultiRowMutationService(org.apache.hadoop.hbase.protobuf.generated.MultiRowMutationProtos.MultiRowMutationService) MetricRegistry(org.apache.hadoop.hbase.metrics.MetricRegistry) Connection(org.apache.hadoop.hbase.client.Connection) Admin(org.apache.hadoop.hbase.client.Admin) Put(org.apache.hadoop.hbase.client.Put) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) TableName(org.apache.hadoop.hbase.TableName) MutateRowsRequest(org.apache.hadoop.hbase.protobuf.generated.MultiRowMutationProtos.MutateRowsRequest) Timer(org.apache.hadoop.hbase.metrics.Timer) Metric(org.apache.hadoop.hbase.metrics.Metric) Mutation(org.apache.hadoop.hbase.client.Mutation) MetricRegistryInfo(org.apache.hadoop.hbase.metrics.MetricRegistryInfo) Test(org.junit.Test)

Example 7 with MetricRegistry

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);
    }
}
Also used : Timer(org.apache.hadoop.hbase.metrics.Timer) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) MetricRegistry(org.apache.hadoop.hbase.metrics.MetricRegistry) Connection(org.apache.hadoop.hbase.client.Connection) Metric(org.apache.hadoop.hbase.metrics.Metric) Admin(org.apache.hadoop.hbase.client.Admin) MetricRegistryInfo(org.apache.hadoop.hbase.metrics.MetricRegistryInfo) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) Test(org.junit.Test)

Example 8 with MetricRegistry

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();
    }
}
Also used : Entry(java.util.Map.Entry) MetricRegistry(org.apache.hadoop.hbase.metrics.MetricRegistry) MetricRegistryInfo(org.apache.hadoop.hbase.metrics.MetricRegistryInfo)

Aggregations

MetricRegistry (org.apache.hadoop.hbase.metrics.MetricRegistry)8 MetricRegistryInfo (org.apache.hadoop.hbase.metrics.MetricRegistryInfo)7 Admin (org.apache.hadoop.hbase.client.Admin)5 Connection (org.apache.hadoop.hbase.client.Connection)5 Metric (org.apache.hadoop.hbase.metrics.Metric)5 Test (org.junit.Test)5 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)4 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)4 Table (org.apache.hadoop.hbase.client.Table)3 Counter (org.apache.hadoop.hbase.metrics.Counter)3 TableName (org.apache.hadoop.hbase.TableName)2 Put (org.apache.hadoop.hbase.client.Put)2 Timer (org.apache.hadoop.hbase.metrics.Timer)2 Entry (java.util.Map.Entry)1 HRegionLocation (org.apache.hadoop.hbase.HRegionLocation)1 Get (org.apache.hadoop.hbase.client.Get)1 Mutation (org.apache.hadoop.hbase.client.Mutation)1 RegionLocator (org.apache.hadoop.hbase.client.RegionLocator)1 MasterCoprocessorEnvironment (org.apache.hadoop.hbase.coprocessor.MasterCoprocessorEnvironment)1 CoprocessorRpcChannel (org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel)1