use of org.apache.hadoop.metrics2.MetricsRecordBuilder in project hadoop by apache.
the class TestMutableMetrics method testMutableRatesWithAggregationSingleThread.
@Test
public void testMutableRatesWithAggregationSingleThread() {
MutableRatesWithAggregation rates = new MutableRatesWithAggregation();
rates.add("foo", 1);
rates.add("bar", 5);
MetricsRecordBuilder rb = mockMetricsRecordBuilder();
rates.snapshot(rb, false);
assertCounter("FooNumOps", 1L, rb);
assertGauge("FooAvgTime", 1.0, rb);
assertCounter("BarNumOps", 1L, rb);
assertGauge("BarAvgTime", 5.0, rb);
rates.add("foo", 1);
rates.add("foo", 3);
rates.add("bar", 6);
rb = mockMetricsRecordBuilder();
rates.snapshot(rb, false);
assertCounter("FooNumOps", 3L, rb);
assertGauge("FooAvgTime", 2.0, rb);
assertCounter("BarNumOps", 2L, rb);
assertGauge("BarAvgTime", 6.0, rb);
}
use of org.apache.hadoop.metrics2.MetricsRecordBuilder in project hadoop by apache.
the class TestMutableMetrics method testSnapshot.
/**
* Test the snapshot method
*/
@Test
public void testSnapshot() {
MetricsRecordBuilder mb = mockMetricsRecordBuilder();
MetricsRegistry registry = new MetricsRegistry("test");
registry.newCounter("c1", "int counter", 1);
registry.newCounter("c2", "long counter", 2L);
registry.newGauge("g1", "int gauge", 3);
registry.newGauge("g2", "long gauge", 4L);
registry.newStat("s1", "stat", "Ops", "Time", true).add(0);
registry.newRate("s2", "stat", false).add(0);
registry.snapshot(mb, true);
MutableStat s2 = (MutableStat) registry.get("s2");
// should get the same back.
s2.snapshot(mb, true);
s2.add(1);
// should get new interval values back
s2.snapshot(mb, true);
verify(mb).addCounter(info("c1", "int counter"), 1);
verify(mb).addCounter(info("c2", "long counter"), 2L);
verify(mb).addGauge(info("g1", "int gauge"), 3);
verify(mb).addGauge(info("g2", "long gauge"), 4L);
verify(mb).addCounter(info("S1NumOps", "Number of ops for stat"), 1L);
verify(mb).addGauge(eq(info("S1AvgTime", "Average time for stat")), eq(0.0, EPSILON));
verify(mb).addGauge(eq(info("S1StdevTime", "Standard deviation of time for stat")), eq(0.0, EPSILON));
verify(mb).addGauge(eq(info("S1IMinTime", "Interval min time for stat")), eq(0.0, EPSILON));
verify(mb).addGauge(eq(info("S1IMaxTime", "Interval max time for stat")), eq(0.0, EPSILON));
verify(mb).addGauge(eq(info("S1MinTime", "Min time for stat")), eq(0.0, EPSILON));
verify(mb).addGauge(eq(info("S1MaxTime", "Max time for stat")), eq(0.0, EPSILON));
verify(mb).addGauge(eq(info("S1INumOps", "Interval number of ops for stat")), eq(1L));
verify(mb, times(2)).addCounter(info("S2NumOps", "Number of ops for stat"), 1L);
verify(mb, times(2)).addGauge(eq(info("S2AvgTime", "Average time for stat")), eq(0.0, EPSILON));
verify(mb).addCounter(info("S2NumOps", "Number of ops for stat"), 2L);
verify(mb).addGauge(eq(info("S2AvgTime", "Average time for stat")), eq(1.0, EPSILON));
// Add one more sample to s1 and verify that total number of ops
// has increased to 2, but interval number is 1 for both intervals.
MutableStat s1 = (MutableStat) registry.get("s1");
s1.add(0);
registry.snapshot(mb, true);
verify(mb).addCounter(info("S1NumOps", "Number of ops for stat"), 2L);
verify(mb, times(2)).addGauge(eq(info("S1INumOps", "Interval number of ops for stat")), eq(1L));
}
use of org.apache.hadoop.metrics2.MetricsRecordBuilder in project hadoop by apache.
the class TestRollingAverages method testRollingAveragesEmptyRollover.
/**
* Tests if the results are correct if no samples are inserted, dry run of
* empty roll over.
*/
@Test(timeout = 30000)
public void testRollingAveragesEmptyRollover() throws Exception {
final MetricsRecordBuilder rb = mockMetricsRecordBuilder();
/* 5s interval and 2 windows */
try (final RollingAverages rollingAverages = new RollingAverages(5000, 2)) {
/* Check it initially */
rollingAverages.snapshot(rb, true);
verify(rb, never()).addGauge(info("FooRollingAvgTime", "Rolling average time for foo"), (long) 0);
verify(rb, never()).addGauge(info("BarAvgTime", "Rolling average time for bar"), (long) 0);
/* sleep 6s longer than 5s interval to wait for rollover done */
Thread.sleep(6000);
rollingAverages.snapshot(rb, false);
verify(rb, never()).addGauge(info("FooRollingAvgTime", "Rolling average time for foo"), (long) 0);
verify(rb, never()).addGauge(info("BarAvgTime", "Rolling average time for bar"), (long) 0);
}
}
use of org.apache.hadoop.metrics2.MetricsRecordBuilder in project hadoop by apache.
the class TestJvmMetrics method testPresence.
@Test
public void testPresence() {
pauseMonitor = new JvmPauseMonitor();
pauseMonitor.init(new Configuration());
pauseMonitor.start();
JvmMetrics jvmMetrics = new JvmMetrics("test", "test");
jvmMetrics.setPauseMonitor(pauseMonitor);
MetricsRecordBuilder rb = getMetrics(jvmMetrics);
MetricsCollector mc = rb.parent();
verify(mc).addRecord(JvmMetrics);
verify(rb).tag(ProcessName, "test");
verify(rb).tag(SessionId, "test");
for (JvmMetricsInfo info : JvmMetricsInfo.values()) {
if (info.name().startsWith("Mem"))
verify(rb).addGauge(eq(info), anyFloat());
else if (info.name().startsWith("Gc"))
verify(rb).addCounter(eq(info), anyLong());
else if (info.name().startsWith("Threads"))
verify(rb).addGauge(eq(info), anyInt());
else if (info.name().startsWith("Log"))
verify(rb).addCounter(eq(info), anyLong());
}
}
use of org.apache.hadoop.metrics2.MetricsRecordBuilder in project hadoop by apache.
the class MetricsAsserts method getMetrics.
/**
* Call getMetrics on source and get a record builder mock to verify
* @param source the metrics source
* @param all if true, return all metrics even if not changed
* @return the record builder mock to verifyÏ
*/
public static MetricsRecordBuilder getMetrics(MetricsSource source, boolean all) {
MetricsRecordBuilder rb = mockMetricsRecordBuilder();
MetricsCollector mc = rb.parent();
source.getMetrics(mc, all);
return rb;
}
Aggregations