Search in sources :

Example 1 with Timer

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

the class TestMetricRegistryImpl method testGetMetrics.

@Test
public void testGetMetrics() {
    CounterImpl counter = new CounterImpl();
    registry.register("mycounter", counter);
    Gauge gauge = registry.register("mygauge", () -> 42L);
    Timer timer = registry.timer("mytimer");
    Map<String, Metric> metrics = registry.getMetrics();
    assertEquals(3, metrics.size());
    assertEquals(counter, metrics.get("mycounter"));
    assertEquals(gauge, metrics.get("mygauge"));
    assertEquals(timer, metrics.get("mytimer"));
}
Also used : Timer(org.apache.hadoop.hbase.metrics.Timer) Metric(org.apache.hadoop.hbase.metrics.Metric) Gauge(org.apache.hadoop.hbase.metrics.Gauge) Test(org.junit.Test)

Example 2 with Timer

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

the class TestMetricRegistryImpl method testTimer.

@Test
public void testTimer() {
    Timer timer = registry.timer("mytimer");
    assertNotNull(timer);
    timer.updateNanos(100);
}
Also used : Timer(org.apache.hadoop.hbase.metrics.Timer) Test(org.junit.Test)

Example 3 with Timer

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

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

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

Aggregations

Timer (org.apache.hadoop.hbase.metrics.Timer)5 Metric (org.apache.hadoop.hbase.metrics.Metric)4 Test (org.junit.Test)4 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)2 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)2 Admin (org.apache.hadoop.hbase.client.Admin)2 Connection (org.apache.hadoop.hbase.client.Connection)2 Gauge (org.apache.hadoop.hbase.metrics.Gauge)2 MetricRegistry (org.apache.hadoop.hbase.metrics.MetricRegistry)2 MetricRegistryInfo (org.apache.hadoop.hbase.metrics.MetricRegistryInfo)2 Map (java.util.Map)1 TableName (org.apache.hadoop.hbase.TableName)1 Mutation (org.apache.hadoop.hbase.client.Mutation)1 Put (org.apache.hadoop.hbase.client.Put)1 Table (org.apache.hadoop.hbase.client.Table)1 CoprocessorRpcChannel (org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel)1 Counter (org.apache.hadoop.hbase.metrics.Counter)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