Java Code Examples for org.apache.hadoop.metrics2.MetricsCollector

The following examples show how to use org.apache.hadoop.metrics2.MetricsCollector. These examples are extracted from open source projects. 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 Project: hadoop-ozone   Source File: SCMPipelineMetrics.java    License: Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("SuspiciousMethodCalls")
public void getMetrics(MetricsCollector collector, boolean all) {
  MetricsRecordBuilder recordBuilder = collector.addRecord(SOURCE_NAME);
  numPipelineAllocated.snapshot(recordBuilder, true);
  numPipelineCreated.snapshot(recordBuilder, true);
  numPipelineCreationFailed.snapshot(recordBuilder, true);
  numPipelineDestroyed.snapshot(recordBuilder, true);
  numPipelineDestroyFailed.snapshot(recordBuilder, true);
  numPipelineReportProcessed.snapshot(recordBuilder, true);
  numPipelineReportProcessingFailed.snapshot(recordBuilder, true);
  numPipelineContainSameDatanodes.snapshot(recordBuilder, true);
  numBytesWritten
      .forEach((pid, metric) -> metric.snapshot(recordBuilder, true));
  numBlocksAllocated
      .forEach((pid, metric) -> metric.snapshot(recordBuilder, true));
}
 
Example 2
Source Project: hadoop-ozone   Source File: SCMContainerMetrics.java    License: Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("SuspiciousMethodCalls")
public void getMetrics(MetricsCollector collector, boolean all) {
  Map<String, Integer> stateCount = scmmxBean.getContainerStateCount();

  collector.addRecord(SOURCE)
      .addGauge(Interns.info("OpenContainers",
          "Number of open containers"),
          stateCount.get(OPEN.toString()))
      .addGauge(Interns.info("ClosingContainers",
          "Number of containers in closing state"),
          stateCount.get(CLOSING.toString()))
      .addGauge(Interns.info("QuasiClosedContainers",
          "Number of containers in quasi closed state"),
          stateCount.get(QUASI_CLOSED.toString()))
      .addGauge(Interns.info("ClosedContainers",
          "Number of containers in closed state"),
          stateCount.get(CLOSED.toString()))
      .addGauge(Interns.info("DeletingContainers",
          "Number of containers in deleting state"),
          stateCount.get(DELETING.toString()))
      .addGauge(Interns.info("DeletedContainers",
          "Number of containers in deleted state"),
          stateCount.get(DELETED.toString()));
}
 
Example 3
Source Project: hadoop-ozone   Source File: ProtocolMessageMetrics.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void getMetrics(MetricsCollector collector, boolean all) {
  counters.forEach((key, value) -> {
    MetricsRecordBuilder builder =
        collector.addRecord(name);
    builder.add(
        new MetricsTag(Interns.info("type", "Message type"), key.toString()));
    builder.addCounter(new MetricName("counter", "Number of distinct calls"),
        value.longValue());
    builder.addCounter(
        new MetricName("time", "Sum of the duration of the calls"),
        elapsedTimes.get(key).longValue());
    builder.endRecord();

  });
}
 
Example 4
@Test
public void testCounterReporting() {
    final Counter counter = new Counter();

    TreeMap<String, Counter> counters = new TreeMap<>();
    counters.put("my_counter", counter);
    // Add the metrics objects to the internal "queues" by hand
    metrics2Reporter.setDropwizardCounters(counters);

    // Set some values
    counter.inc(5L);

    MetricsCollector collector = mock(MetricsCollector.class);
    MetricsRecordBuilder recordBuilder = mock(MetricsRecordBuilder.class);

    Mockito.when(collector.addRecord(recordName)).thenReturn(recordBuilder);

    metrics2Reporter.getMetrics(collector, true);

    verify(recordBuilder).addCounter(Interns.info("my_counter", ""), 5L);
    verifyRecordBuilderUnits(recordBuilder);

    // Should not be the same instance we gave before. Our map should have gotten swapped out.
    assertTrue("Should not be the same map instance after collection",
            counters != metrics2Reporter.getDropwizardCounters());
}
 
Example 5
@SuppressWarnings("rawtypes")
@Test
public void metrics2CycleIsNonDestructive() {
    metrics2Reporter.setDropwizardCounters(Collections.unmodifiableSortedMap(new TreeMap<String, Counter>()));
    metrics2Reporter.setDropwizardGauges(Collections.unmodifiableSortedMap(new TreeMap<String, Gauge>()));
    metrics2Reporter.setDropwizardHistograms(Collections.unmodifiableSortedMap(new TreeMap<String, Histogram>()));
    metrics2Reporter.setDropwizardMeters(Collections.unmodifiableSortedMap(new TreeMap<String, Meter>()));
    metrics2Reporter.setDropwizardTimers(Collections.unmodifiableSortedMap(new TreeMap<String, Timer>()));

    MetricsCollector collector = mock(MetricsCollector.class);
    MetricsRecordBuilder recordBuilder = mock(MetricsRecordBuilder.class);

    Mockito.when(collector.addRecord(recordName)).thenReturn(recordBuilder);

    metrics2Reporter.getMetrics(collector, true);
}
 
Example 6
Source Project: hadoop   Source File: ContainerMetrics.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public synchronized void getMetrics(MetricsCollector collector, boolean all) {
  //Container goes through registered -> finished -> unregistered.
  if (unregister) {
    metricsSystem.unregisterSource(recordInfo.name());
    usageMetrics.remove(containerId);
    return;
  }

  if (finished || flushOnPeriod) {
    registry.snapshot(collector.addRecord(registry.info()), all);
  }

  if (finished) {
    this.unregister = true;
  } else if (flushOnPeriod) {
    flushOnPeriod = false;
    scheduleTimerTaskIfRequired();
  }
}
 
Example 7
Source Project: hadoop   Source File: StartupProgressMetrics.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void getMetrics(MetricsCollector collector, boolean all) {
  StartupProgressView prog = startupProgress.createView();
  MetricsRecordBuilder builder = collector.addRecord(
    STARTUP_PROGRESS_METRICS_INFO);

  builder.addCounter(info("ElapsedTime", "overall elapsed time"),
    prog.getElapsedTime());
  builder.addGauge(info("PercentComplete", "overall percent complete"),
    prog.getPercentComplete());

  for (Phase phase: prog.getPhases()) {
    addCounter(builder, phase, "Count", " count", prog.getCount(phase));
    addCounter(builder, phase, "ElapsedTime", " elapsed time",
      prog.getElapsedTime(phase));
    addCounter(builder, phase, "Total", " total", prog.getTotal(phase));
    addGauge(builder, phase, "PercentComplete", " percent complete",
      prog.getPercentComplete(phase));
  }
}
 
Example 8
Source Project: hadoop   Source File: MetricsSourceBuilder.java    License: Apache License 2.0 6 votes vote down vote up
public MetricsSource build() {
  if (source instanceof MetricsSource) {
    if (hasAtMetric && !hasRegistry) {
      throw new MetricsException("Hybrid metrics: registry required.");
    }
    return (MetricsSource) source;
  }
  else if (!hasAtMetric) {
    throw new MetricsException("No valid @Metric annotation found.");
  }
  return new MetricsSource() {
    @Override
    public void getMetrics(MetricsCollector builder, boolean all) {
      registry.snapshot(builder.addRecord(registry.info()), all);
    }
  };
}
 
Example 9
Source Project: hadoop   Source File: MetricsAsserts.java    License: Apache License 2.0 6 votes vote down vote up
public static MetricsRecordBuilder mockMetricsRecordBuilder() {
  final MetricsCollector mc = mock(MetricsCollector.class);
  MetricsRecordBuilder rb = mock(MetricsRecordBuilder.class,
      new Answer<Object>() {
    @Override
    public Object answer(InvocationOnMock invocation) {
      Object[] args = invocation.getArguments();
      StringBuilder sb = new StringBuilder();
      for (Object o : args) {
        if (sb.length() > 0) sb.append(", ");
        sb.append(String.valueOf(o));
      }
      String methodName = invocation.getMethod().getName();
      LOG.debug(methodName +": "+ sb);
      return methodName.equals("parent") || methodName.equals("endRecord") ?
             mc : invocation.getMock();
    }
  });
  when(mc.addRecord(anyString())).thenReturn(rb);
  when(mc.addRecord(anyInfo())).thenReturn(rb);
  return rb;
}
 
Example 10
Source Project: big-c   Source File: ContainerMetrics.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public synchronized void getMetrics(MetricsCollector collector, boolean all) {
  //Container goes through registered -> finished -> unregistered.
  if (unregister) {
    metricsSystem.unregisterSource(recordInfo.name());
    usageMetrics.remove(containerId);
    return;
  }

  if (finished || flushOnPeriod) {
    registry.snapshot(collector.addRecord(registry.info()), all);
  }

  if (finished) {
    this.unregister = true;
  } else if (flushOnPeriod) {
    flushOnPeriod = false;
    scheduleTimerTaskIfRequired();
  }
}
 
Example 11
Source Project: big-c   Source File: StartupProgressMetrics.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void getMetrics(MetricsCollector collector, boolean all) {
  StartupProgressView prog = startupProgress.createView();
  MetricsRecordBuilder builder = collector.addRecord(
    STARTUP_PROGRESS_METRICS_INFO);

  builder.addCounter(info("ElapsedTime", "overall elapsed time"),
    prog.getElapsedTime());
  builder.addGauge(info("PercentComplete", "overall percent complete"),
    prog.getPercentComplete());

  for (Phase phase: prog.getPhases()) {
    addCounter(builder, phase, "Count", " count", prog.getCount(phase));
    addCounter(builder, phase, "ElapsedTime", " elapsed time",
      prog.getElapsedTime(phase));
    addCounter(builder, phase, "Total", " total", prog.getTotal(phase));
    addGauge(builder, phase, "PercentComplete", " percent complete",
      prog.getPercentComplete(phase));
  }
}
 
Example 12
Source Project: big-c   Source File: MetricsSourceBuilder.java    License: Apache License 2.0 6 votes vote down vote up
public MetricsSource build() {
  if (source instanceof MetricsSource) {
    if (hasAtMetric && !hasRegistry) {
      throw new MetricsException("Hybrid metrics: registry required.");
    }
    return (MetricsSource) source;
  }
  else if (!hasAtMetric) {
    throw new MetricsException("No valid @Metric annotation found.");
  }
  return new MetricsSource() {
    @Override
    public void getMetrics(MetricsCollector builder, boolean all) {
      registry.snapshot(builder.addRecord(registry.info()), all);
    }
  };
}
 
Example 13
Source Project: big-c   Source File: TestJvmMetrics.java    License: 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 14
Source Project: big-c   Source File: TestMetricsAnnotations.java    License: 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 15
Source Project: big-c   Source File: MetricsAsserts.java    License: Apache License 2.0 6 votes vote down vote up
public static MetricsRecordBuilder mockMetricsRecordBuilder() {
  final MetricsCollector mc = mock(MetricsCollector.class);
  MetricsRecordBuilder rb = mock(MetricsRecordBuilder.class,
      new Answer<Object>() {
    @Override
    public Object answer(InvocationOnMock invocation) {
      Object[] args = invocation.getArguments();
      StringBuilder sb = new StringBuilder();
      for (Object o : args) {
        if (sb.length() > 0) sb.append(", ");
        sb.append(String.valueOf(o));
      }
      String methodName = invocation.getMethod().getName();
      LOG.debug(methodName +": "+ sb);
      return methodName.equals("parent") || methodName.equals("endRecord") ?
             mc : invocation.getMock();
    }
  });
  when(mc.addRecord(anyString())).thenReturn(rb);
  when(mc.addRecord(anyInfo())).thenReturn(rb);
  return rb;
}
 
Example 16
Source Project: kylin   Source File: HadoopMetrics2ReporterTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCounterReporting() {
    final Counter counter = new Counter();

    TreeMap<String, Counter> counters = new TreeMap<>();
    counters.put("my_counter", counter);
    // Add the metrics objects to the internal "queues" by hand
    metrics2Reporter.setDropwizardCounters(counters);

    // Set some values
    counter.inc(5L);

    MetricsCollector collector = mock(MetricsCollector.class);
    MetricsRecordBuilder recordBuilder = mock(MetricsRecordBuilder.class);

    Mockito.when(collector.addRecord(recordName)).thenReturn(recordBuilder);

    metrics2Reporter.getMetrics(collector, true);

    verify(recordBuilder).addCounter(Interns.info("my_counter", ""), 5L);
    verifyRecordBuilderUnits(recordBuilder);

    // Should not be the same instance we gave before. Our map should have gotten swapped out.
    assertTrue("Should not be the same map instance after collection",
            counters != metrics2Reporter.getDropwizardCounters());
}
 
Example 17
Source Project: kylin   Source File: HadoopMetrics2ReporterTest.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("rawtypes")
@Test
public void metrics2CycleIsNonDestructive() {
    metrics2Reporter.setDropwizardCounters(Collections.unmodifiableSortedMap(new TreeMap<String, Counter>()));
    metrics2Reporter.setDropwizardGauges(Collections.unmodifiableSortedMap(new TreeMap<String, Gauge>()));
    metrics2Reporter.setDropwizardHistograms(Collections.unmodifiableSortedMap(new TreeMap<String, Histogram>()));
    metrics2Reporter.setDropwizardMeters(Collections.unmodifiableSortedMap(new TreeMap<String, Meter>()));
    metrics2Reporter.setDropwizardTimers(Collections.unmodifiableSortedMap(new TreeMap<String, Timer>()));

    MetricsCollector collector = mock(MetricsCollector.class);
    MetricsRecordBuilder recordBuilder = mock(MetricsRecordBuilder.class);

    Mockito.when(collector.addRecord(recordName)).thenReturn(recordBuilder);

    metrics2Reporter.getMetrics(collector, true);
}
 
Example 18
Source Project: hbase   Source File: MetricsStochasticBalancerSourceImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void getMetrics(MetricsCollector metricsCollector, boolean all) {
  MetricsRecordBuilder metricsRecordBuilder = metricsCollector.addRecord(metricsName);

  if (stochasticCosts != null) {
    synchronized (stochasticCosts) {
      for (Map.Entry<String, Map<String, Double>> tableEntry : stochasticCosts.entrySet()) {
        for (Map.Entry<String, Double> costEntry : tableEntry.getValue().entrySet()) {
          String attrName = tableEntry.getKey() + TABLE_FUNCTION_SEP + costEntry.getKey();
          Double cost = costEntry.getValue();
          String functionDesc = costFunctionDescs.get(costEntry.getKey());

          if (functionDesc == null) {
            functionDesc = costEntry.getKey();
          }

          metricsRecordBuilder.addGauge(Interns.info(attrName, functionDesc), cost);
        }
      }
    }
  }
  metricsRegistry.snapshot(metricsRecordBuilder, all);
}
 
Example 19
Source Project: hbase   Source File: MetricsMasterProcSourceImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void getMetrics(MetricsCollector metricsCollector, boolean all) {
  MetricsRecordBuilder metricsRecordBuilder = metricsCollector.addRecord(metricsName);

  // masterWrapper can be null because this function is called inside of init.
  if (masterWrapper != null) {
    metricsRecordBuilder
        .addGauge(Interns.info(NUM_MASTER_WALS_NAME, NUM_MASTER_WALS_DESC),
            masterWrapper.getNumWALFiles());
  }

  metricsRegistry.snapshot(metricsRecordBuilder, all);
  if(metricsAdapter != null) {
    metricsAdapter.snapshotAllMetrics(registry, metricsRecordBuilder);
  }
}
 
Example 20
Source Project: hbase   Source File: MetricsMasterQuotaSourceImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void getMetrics(MetricsCollector metricsCollector, boolean all) {
  MetricsRecordBuilder record = metricsCollector.addRecord(metricsRegistry.info());
  if (wrapper != null) {
    // Summarize the tables
    Map<String,Entry<Long,Long>> tableUsages = wrapper.getTableSpaceUtilization();
    String tableSummary = "[]";
    if (tableUsages != null && !tableUsages.isEmpty()) {
      tableSummary = generateJsonQuotaSummary(tableUsages.entrySet(), "table");
    }
    record.tag(Interns.info(TABLE_QUOTA_USAGE_NAME, TABLE_QUOTA_USAGE_DESC), tableSummary);

    // Summarize the namespaces
    String nsSummary = "[]";
    Map<String,Entry<Long,Long>> namespaceUsages = wrapper.getNamespaceSpaceUtilization();
    if (namespaceUsages != null && !namespaceUsages.isEmpty()) {
      nsSummary = generateJsonQuotaSummary(namespaceUsages.entrySet(), "namespace");
    }
    record.tag(Interns.info(NS_QUOTA_USAGE_NAME, NS_QUOTA_USAGE_DESC), nsSummary);
  }
  metricsRegistry.snapshot(record, all);
}
 
Example 21
Source Project: hadoop-ozone   Source File: ReplicationManager.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void getMetrics(MetricsCollector collector, boolean all) {
  collector.addRecord(ReplicationManager.class.getSimpleName())
      .addGauge(ReplicationManagerMetrics.INFLIGHT_REPLICATION,
          inflightReplication.size())
      .addGauge(ReplicationManagerMetrics.INFLIGHT_DELETION,
          inflightDeletion.size())
      .endRecord();
}
 
Example 22
Source Project: hadoop-ozone   Source File: TestSCMContainerMetrics.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testSCMContainerMetrics() {
  SCMMXBean scmmxBean = mock(SCMMXBean.class);

  Map<String, Integer> stateInfo = new HashMap<String, Integer>() {{
      put(HddsProtos.LifeCycleState.OPEN.toString(), 2);
      put(HddsProtos.LifeCycleState.CLOSING.toString(), 3);
      put(HddsProtos.LifeCycleState.QUASI_CLOSED.toString(), 4);
      put(HddsProtos.LifeCycleState.CLOSED.toString(), 5);
      put(HddsProtos.LifeCycleState.DELETING.toString(), 6);
      put(HddsProtos.LifeCycleState.DELETED.toString(), 7);
    }};


  when(scmmxBean.getContainerStateCount()).thenReturn(stateInfo);

  MetricsRecordBuilder mb = mock(MetricsRecordBuilder.class);
  when(mb.addGauge(any(MetricsInfo.class), anyInt())).thenReturn(mb);

  MetricsCollector metricsCollector = mock(MetricsCollector.class);
  when(metricsCollector.addRecord(anyString())).thenReturn(mb);

  SCMContainerMetrics containerMetrics = new SCMContainerMetrics(scmmxBean);

  containerMetrics.getMetrics(metricsCollector, true);

  verify(mb, times(1)).addGauge(Interns.info("OpenContainers",
      "Number of open containers"), 2);
  verify(mb, times(1)).addGauge(Interns.info("ClosingContainers",
      "Number of containers in closing state"), 3);
  verify(mb, times(1)).addGauge(Interns.info("QuasiClosedContainers",
      "Number of containers in quasi closed state"), 4);
  verify(mb, times(1)).addGauge(Interns.info("ClosedContainers",
      "Number of containers in closed state"), 5);
  verify(mb, times(1)).addGauge(Interns.info("DeletingContainers",
      "Number of containers in deleting state"), 6);
  verify(mb, times(1)).addGauge(Interns.info("DeletedContainers",
      "Number of containers in deleted state"), 7);
}
 
Example 23
@Override
public void getMetrics(MetricsCollector collector, boolean all) {
    MetricsRecordBuilder builder = collector.addRecord(recordName);
    if (null != context) {
        builder.setContext(context);
    }

    // Synchronizing here ensures that the dropwizard metrics collection side is excluded from executing
    // at the same time we are pulling elements from the queues.
    synchronized (this) {
        snapshotAllMetrics(builder);
    }

    metrics2Registry.snapshot(builder, all);
}
 
Example 24
@Test
public void testGaugeReporting() {
    final AtomicLong gaugeValue = new AtomicLong(0L);
    @SuppressWarnings("rawtypes")
    final Gauge gauge = new Gauge<Long>() {
        @Override
        public Long getValue() {
            return gaugeValue.get();
        }
    };

    @SuppressWarnings("rawtypes")
    TreeMap<String, Gauge> gauges = new TreeMap<>();
    gauges.put("my_gauge", gauge);
    // Add the metrics objects to the internal "queues" by hand
    metrics2Reporter.setDropwizardGauges(gauges);

    // Set some values
    gaugeValue.set(5L);

    MetricsCollector collector = mock(MetricsCollector.class);
    MetricsRecordBuilder recordBuilder = mock(MetricsRecordBuilder.class);

    Mockito.when(collector.addRecord(recordName)).thenReturn(recordBuilder);

    // Make sure a value of 5 gets reported
    metrics2Reporter.getMetrics(collector, true);

    verify(recordBuilder).addGauge(Interns.info("my_gauge", ""), gaugeValue.get());
    verifyRecordBuilderUnits(recordBuilder);

    // Should not be the same instance we gave before. Our map should have gotten swapped out.
    assertTrue("Should not be the same map instance after collection",
            gauges != metrics2Reporter.getDropwizardGauges());
}
 
Example 25
@SuppressWarnings("rawtypes")
@Test
public void cachedMetricsAreClearedAfterCycle() {
    // After we perform a metrics2 reporting cycle, the maps should be reset to avoid double-reporting
    TreeMap<String, Counter> counters = new TreeMap<>();
    TreeMap<String, Gauge> gauges = new TreeMap<>();
    TreeMap<String, Histogram> histograms = new TreeMap<>();
    TreeMap<String, Meter> meters = new TreeMap<>();
    TreeMap<String, Timer> timers = new TreeMap<>();

    metrics2Reporter.setDropwizardCounters(counters);
    metrics2Reporter.setDropwizardGauges(gauges);
    metrics2Reporter.setDropwizardHistograms(histograms);
    metrics2Reporter.setDropwizardMeters(meters);
    metrics2Reporter.setDropwizardTimers(timers);

    MetricsCollector collector = mock(MetricsCollector.class);
    MetricsRecordBuilder recordBuilder = mock(MetricsRecordBuilder.class);

    Mockito.when(collector.addRecord(recordName)).thenReturn(recordBuilder);

    metrics2Reporter.getMetrics(collector, true);

    assertTrue(counters != metrics2Reporter.getDropwizardCounters());
    assertEquals(0, metrics2Reporter.getDropwizardCounters().size());
    assertTrue(gauges != metrics2Reporter.getDropwizardGauges());
    assertEquals(0, metrics2Reporter.getDropwizardGauges().size());
    assertTrue(histograms != metrics2Reporter.getDropwizardHistograms());
    assertEquals(0, metrics2Reporter.getDropwizardHistograms().size());
    assertTrue(meters != metrics2Reporter.getDropwizardMeters());
    assertEquals(0, metrics2Reporter.getDropwizardMeters().size());
    assertTrue(timers != metrics2Reporter.getDropwizardTimers());
    assertEquals(0, metrics2Reporter.getDropwizardTimers().size());
}
 
Example 26
Source Project: hadoop   Source File: AzureFileSystemInstrumentation.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void getMetrics(MetricsCollector builder, boolean all) {
  averageBlockDownloadLatencyMs.set(
      currentBlockDownloadLatency.getCurrentAverage());
  averageBlockUploadLatencyMs.set(
      currentBlockUploadLatency.getCurrentAverage());
  registry.snapshot(builder.addRecord(registry.info().name()), true);
}
 
Example 27
Source Project: hadoop   Source File: JvmMetrics.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void getMetrics(MetricsCollector collector, boolean all) {
  MetricsRecordBuilder rb = collector.addRecord(JvmMetrics)
      .setContext("jvm").tag(ProcessName, processName)
      .tag(SessionId, sessionId);
  getMemoryUsage(rb);
  getGcUsage(rb);
  getThreadUsage(rb);
  getEventCounters(rb);
}
 
Example 28
Source Project: hadoop   Source File: MetricsSystemImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void getMetrics(MetricsCollector builder, boolean all) {
  MetricsRecordBuilder rb = builder.addRecord(MS_NAME)
      .addGauge(MsInfo.NumActiveSources, sources.size())
      .addGauge(MsInfo.NumAllSources, allSources.size())
      .addGauge(MsInfo.NumActiveSinks, sinks.size())
      .addGauge(MsInfo.NumAllSinks, allSinks.size());

  for (MetricsSinkAdapter sa : sinks.values()) {
    sa.snapshot(rb, all);
  }
  registry.snapshot(rb, all);
}
 
Example 29
Source Project: hadoop   Source File: MetricsRecordBuilderImpl.java    License: Apache License 2.0 5 votes vote down vote up
MetricsRecordBuilderImpl(MetricsCollector parent, MetricsInfo info,
                         MetricsFilter rf, MetricsFilter mf,
                         boolean acceptable) {
  this.parent = parent;
  timestamp = Time.now();
  recInfo = info;
  metrics = Lists.newArrayList();
  tags = Lists.newArrayList();
  recordFilter = rf;
  metricFilter = mf;
  this.acceptable = acceptable;
}
 
Example 30
Source Project: hadoop   Source File: TestMetricsAnnotations.java    License: 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"));
}