Search in sources :

Example 1 with Counter

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

the class TestMetricRegistryImpl method testCounter.

@Test
public void testCounter() {
    Counter counter = registry.counter("mycounter");
    assertNotNull(counter);
    counter.increment(42L);
    Optional<Metric> metric = registry.get("mycounter");
    assertTrue(metric.isPresent());
    assertEquals(42L, (long) ((Counter) metric.get()).getCount());
}
Also used : Counter(org.apache.hadoop.hbase.metrics.Counter) Metric(org.apache.hadoop.hbase.metrics.Metric) Test(org.junit.Test)

Example 2 with Counter

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

the class TestCoprocessorMetrics method assertPreGetRequestsCounter.

/**
   * Helper for below tests
   */
private void assertPreGetRequestsCounter(Class<?> coprocClass) {
    // Find out the MetricRegistry used by the CP using the global registries
    MetricRegistryInfo info = MetricsCoprocessor.createRegistryInfoForRegionCoprocessor(coprocClass.getName());
    Optional<MetricRegistry> registry = MetricRegistries.global().get(info);
    assertTrue(registry.isPresent());
    Optional<Metric> metric = registry.get().get("preGetRequests");
    assertTrue(metric.isPresent());
    Counter preGetRequests = (Counter) metric.get();
    assertEquals(2, preGetRequests.getCount());
}
Also used : Counter(org.apache.hadoop.hbase.metrics.Counter) MetricRegistry(org.apache.hadoop.hbase.metrics.MetricRegistry) Metric(org.apache.hadoop.hbase.metrics.Metric) MetricRegistryInfo(org.apache.hadoop.hbase.metrics.MetricRegistryInfo)

Example 3 with Counter

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

the class TestCoprocessorMetrics method testRegionServerObserver.

@Test
public void testRegionServerObserver() throws IOException {
    try (Connection connection = ConnectionFactory.createConnection(UTIL.getConfiguration());
        Admin admin = connection.getAdmin()) {
        LOG.info("Rolling WALs");
        admin.rollWALWriter(UTIL.getMiniHBaseCluster().getServerHoldingMeta());
    }
    // Find out the MetricRegistry used by the CP using the global registries
    MetricRegistryInfo info = MetricsCoprocessor.createRegistryInfoForRSCoprocessor(CustomRegionServerObserver.class.getName());
    Optional<MetricRegistry> registry = MetricRegistries.global().get(info);
    assertTrue(registry.isPresent());
    Optional<Metric> metric = registry.get().get("rollWALRequests");
    assertTrue(metric.isPresent());
    Counter rollWalRequests = (Counter) metric.get();
    assertEquals(1, rollWalRequests.getCount());
}
Also used : Counter(org.apache.hadoop.hbase.metrics.Counter) 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) Test(org.junit.Test)

Example 4 with Counter

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

the class TestCoprocessorMetrics method testWALObserver.

@Test
public void testWALObserver() throws IOException {
    // Find out the MetricRegistry used by the CP using the global registries
    MetricRegistryInfo info = MetricsCoprocessor.createRegistryInfoForWALCoprocessor(CustomWALObserver.class.getName());
    Optional<MetricRegistry> registry = MetricRegistries.global().get(info);
    assertTrue(registry.isPresent());
    Optional<Metric> metric = registry.get().get("walEditsCount");
    assertTrue(metric.isPresent());
    try (Connection connection = ConnectionFactory.createConnection(UTIL.getConfiguration());
        Admin admin = connection.getAdmin()) {
        admin.createTable(new HTableDescriptor(TableName.valueOf(name.getMethodName())).addFamily(new HColumnDescriptor("foo")));
        Counter rollWalRequests = (Counter) metric.get();
        long prevCount = rollWalRequests.getCount();
        assertTrue(prevCount > 0);
        try (Table table = connection.getTable(TableName.valueOf(name.getMethodName()))) {
            table.put(new Put(foo).addColumn(foo, foo, foo));
        }
        assertEquals(1, rollWalRequests.getCount() - prevCount);
    }
}
Also used : Table(org.apache.hadoop.hbase.client.Table) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) 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) Counter(org.apache.hadoop.hbase.metrics.Counter) Metric(org.apache.hadoop.hbase.metrics.Metric) MetricRegistryInfo(org.apache.hadoop.hbase.metrics.MetricRegistryInfo) Test(org.junit.Test)

Example 5 with Counter

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

Counter (org.apache.hadoop.hbase.metrics.Counter)6 Metric (org.apache.hadoop.hbase.metrics.Metric)6 Test (org.junit.Test)4 MetricRegistry (org.apache.hadoop.hbase.metrics.MetricRegistry)3 MetricRegistryInfo (org.apache.hadoop.hbase.metrics.MetricRegistryInfo)3 Admin (org.apache.hadoop.hbase.client.Admin)2 Connection (org.apache.hadoop.hbase.client.Connection)2 Gauge (org.apache.hadoop.hbase.metrics.Gauge)2 Map (java.util.Map)1 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)1 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)1 Put (org.apache.hadoop.hbase.client.Put)1 Table (org.apache.hadoop.hbase.client.Table)1 Histogram (org.apache.hadoop.hbase.metrics.Histogram)1 Meter (org.apache.hadoop.hbase.metrics.Meter)1 Timer (org.apache.hadoop.hbase.metrics.Timer)1 MutableHistogram (org.apache.hadoop.metrics2.lib.MutableHistogram)1