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"));
}
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());
}
}
}
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);
}
Aggregations