Java Code Examples for org.apache.hadoop.metrics2.MetricsRecordBuilder#parent()

The following examples show how to use org.apache.hadoop.metrics2.MetricsRecordBuilder#parent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestJvmMetrics.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Test public void testPresence() {
  JvmPauseMonitor pauseMonitor = new JvmPauseMonitor(new Configuration());
  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());
  }
}
 
Example 2
Source File: TestMetricsAnnotations.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Test public void testHybrid() {
  HybridMetrics metrics = new HybridMetrics();
  MetricsSource source = MetricsAnnotations.makeSource(metrics);

  assertSame(metrics, source);
  metrics.C0.incr();
  MetricsRecordBuilder rb = getMetrics(source);
  MetricsCollector collector = rb.parent();

  verify(collector).addRecord("foo");
  verify(collector).addRecord("bar");
  verify(collector).addRecord(info("HybridMetrics", "HybridMetrics"));
  verify(rb).setContext("foocontext");
  verify(rb).addCounter(info("C1", "C1 desc"), 1);
  verify(rb).setContext("barcontext");
  verify(rb).addGauge(info("G1", "G1 desc"), 1);
  verify(rb).add(tag(MsInfo.Context, "hybrid"));
  verify(rb).addCounter(info("C0", "C0 desc"), 1);
  verify(rb).addGauge(info("G0", "G0"), 0);
}
 
Example 3
Source File: TestJvmMetrics.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test public void testPresence() {
  JvmPauseMonitor pauseMonitor = new JvmPauseMonitor(new Configuration());
  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());
  }
}
 
Example 4
Source File: TestMetricsAnnotations.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test public void testHybrid() {
  HybridMetrics metrics = new HybridMetrics();
  MetricsSource source = MetricsAnnotations.makeSource(metrics);

  assertSame(metrics, source);
  metrics.C0.incr();
  MetricsRecordBuilder rb = getMetrics(source);
  MetricsCollector collector = rb.parent();

  verify(collector).addRecord("foo");
  verify(collector).addRecord("bar");
  verify(collector).addRecord(info("HybridMetrics", "HybridMetrics"));
  verify(rb).setContext("foocontext");
  verify(rb).addCounter(info("C1", "C1 desc"), 1);
  verify(rb).setContext("barcontext");
  verify(rb).addGauge(info("G1", "G1 desc"), 1);
  verify(rb).add(tag(MsInfo.Context, "hybrid"));
  verify(rb).addCounter(info("C0", "C0 desc"), 1);
  verify(rb).addGauge(info("G0", "G0"), 0);
}
 
Example 5
Source File: TestMetricsAnnotations.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test public void testClasses() {
  MetricsRecordBuilder rb = getMetrics(
      MetricsAnnotations.makeSource(new MyMetrics3()));
  MetricsCollector collector = rb.parent();

  verify(collector).addRecord(info("MyMetrics3", "My metrics"));
  verify(rb).add(tag(MsInfo.Context, "foo"));
}
 
Example 6
Source File: MetricsAsserts.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 7
Source File: TestMetricsAnnotations.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test public void testClasses() {
  MetricsRecordBuilder rb = getMetrics(
      MetricsAnnotations.makeSource(new MyMetrics3()));
  MetricsCollector collector = rb.parent();

  verify(collector).addRecord(info("MyMetrics3", "My metrics"));
  verify(rb).add(tag(MsInfo.Context, "foo"));
}
 
Example 8
Source File: MetricsAsserts.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}