Search in sources :

Example 6 with Metric

use of org.apache.hadoop.hbase.metrics.Metric 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 Metric

use of org.apache.hadoop.hbase.metrics.Metric 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 Metric

use of org.apache.hadoop.hbase.metrics.Metric in project hbase by apache.

the class HBaseMetrics2HadoopMetricsAdapter method snapshotAllMetrics.

/**
   * Iterates over the MetricRegistry and adds them to the {@code builder}.
   *
   * @param builder A record builder
   */
public void snapshotAllMetrics(MetricRegistry metricRegistry, MetricsRecordBuilder builder) {
    Map<String, Metric> metrics = metricRegistry.getMetrics();
    for (Map.Entry<String, Metric> e : metrics.entrySet()) {
        // Always capitalize the name
        String name = StringUtils.capitalize(e.getKey());
        Metric metric = e.getValue();
        if (metric instanceof Gauge) {
            addGauge(name, (Gauge<?>) metric, builder);
        } else if (metric instanceof Counter) {
            addCounter(name, (Counter) metric, builder);
        } else if (metric instanceof Histogram) {
            addHistogram(name, (Histogram) metric, builder);
        } else if (metric instanceof Meter) {
            addMeter(name, (Meter) metric, builder);
        } else if (metric instanceof Timer) {
            addTimer(name, (Timer) metric, builder);
        } else {
            LOG.info("Ignoring unknown Metric class " + metric.getClass().getName());
        }
    }
}
Also used : MutableHistogram(org.apache.hadoop.metrics2.lib.MutableHistogram) Histogram(org.apache.hadoop.hbase.metrics.Histogram) Counter(org.apache.hadoop.hbase.metrics.Counter) Timer(org.apache.hadoop.hbase.metrics.Timer) Meter(org.apache.hadoop.hbase.metrics.Meter) Metric(org.apache.hadoop.hbase.metrics.Metric) Map(java.util.Map) Gauge(org.apache.hadoop.hbase.metrics.Gauge)

Example 9 with Metric

use of org.apache.hadoop.hbase.metrics.Metric in project hbase by apache.

the class TestMetricRegistryImpl method testDoubleRegister.

@Test
public void testDoubleRegister() {
    Gauge g1 = registry.register("mygauge", () -> 42L);
    Gauge g2 = registry.register("mygauge", () -> 52L);
    // second gauge is ignored if it exists
    assertEquals(g1, g2);
    Optional<Metric> metric = registry.get("mygauge");
    assertTrue(metric.isPresent());
    assertEquals(42L, (long) ((Gauge<Long>) metric.get()).getValue());
    Counter c1 = registry.counter("mycounter");
    Counter c2 = registry.counter("mycounter");
    assertEquals(c1, c2);
}
Also used : Counter(org.apache.hadoop.hbase.metrics.Counter) Metric(org.apache.hadoop.hbase.metrics.Metric) Gauge(org.apache.hadoop.hbase.metrics.Gauge) Test(org.junit.Test)

Aggregations

Metric (org.apache.hadoop.hbase.metrics.Metric)9 Test (org.junit.Test)7 Counter (org.apache.hadoop.hbase.metrics.Counter)6 MetricRegistry (org.apache.hadoop.hbase.metrics.MetricRegistry)5 MetricRegistryInfo (org.apache.hadoop.hbase.metrics.MetricRegistryInfo)5 Admin (org.apache.hadoop.hbase.client.Admin)4 Connection (org.apache.hadoop.hbase.client.Connection)4 Timer (org.apache.hadoop.hbase.metrics.Timer)4 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)3 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)3 Gauge (org.apache.hadoop.hbase.metrics.Gauge)3 Put (org.apache.hadoop.hbase.client.Put)2 Table (org.apache.hadoop.hbase.client.Table)2 Map (java.util.Map)1 TableName (org.apache.hadoop.hbase.TableName)1 Mutation (org.apache.hadoop.hbase.client.Mutation)1 CoprocessorRpcChannel (org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel)1 Histogram (org.apache.hadoop.hbase.metrics.Histogram)1 Meter (org.apache.hadoop.hbase.metrics.Meter)1 MultiRowMutationService (org.apache.hadoop.hbase.protobuf.generated.MultiRowMutationProtos.MultiRowMutationService)1