Search in sources :

Example 1 with Gauge

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

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

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

Gauge (org.apache.hadoop.hbase.metrics.Gauge)3 Metric (org.apache.hadoop.hbase.metrics.Metric)3 Counter (org.apache.hadoop.hbase.metrics.Counter)2 Timer (org.apache.hadoop.hbase.metrics.Timer)2 Test (org.junit.Test)2 Map (java.util.Map)1 Histogram (org.apache.hadoop.hbase.metrics.Histogram)1 Meter (org.apache.hadoop.hbase.metrics.Meter)1 MutableHistogram (org.apache.hadoop.metrics2.lib.MutableHistogram)1