本文整理汇总了Java中org.apache.hadoop.metrics2.MetricsCollector类的典型用法代码示例。如果您正苦于以下问题:Java MetricsCollector类的具体用法?Java MetricsCollector怎么用?Java MetricsCollector使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MetricsCollector类属于org.apache.hadoop.metrics2包,在下文中一共展示了MetricsCollector类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: build
import org.apache.hadoop.metrics2.MetricsCollector; //导入依赖的package包/类
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);
}
};
}
示例2: testPresence
import org.apache.hadoop.metrics2.MetricsCollector; //导入依赖的package包/类
@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());
}
}
示例3: testHybrid
import org.apache.hadoop.metrics2.MetricsCollector; //导入依赖的package包/类
@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);
}
示例4: mockMetricsRecordBuilder
import org.apache.hadoop.metrics2.MetricsCollector; //导入依赖的package包/类
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;
}
示例5: getMetrics
import org.apache.hadoop.metrics2.MetricsCollector; //导入依赖的package包/类
@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();
}
}
示例6: getMetrics
import org.apache.hadoop.metrics2.MetricsCollector; //导入依赖的package包/类
@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));
}
}
示例7: testPresence
import org.apache.hadoop.metrics2.MetricsCollector; //导入依赖的package包/类
@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());
}
}
示例8: getMetrics
import org.apache.hadoop.metrics2.MetricsCollector; //导入依赖的package包/类
@Override
public void getMetrics(MetricsCollector metricsCollector, boolean all) {
MetricsRecordBuilder mrb = metricsCollector.addRecord(metricsName);
if (wrapper != null) {
mrb.addGauge(Interns.info(QUEUE_SIZE_NAME, QUEUE_SIZE_DESC), wrapper.getTotalQueueSize())
.addGauge(Interns.info(GENERAL_QUEUE_NAME, GENERAL_QUEUE_DESC),
wrapper.getGeneralQueueLength())
.addGauge(Interns.info(REPLICATION_QUEUE_NAME,
REPLICATION_QUEUE_DESC), wrapper.getReplicationQueueLength())
.addGauge(Interns.info(PRIORITY_QUEUE_NAME, PRIORITY_QUEUE_DESC),
wrapper.getPriorityQueueLength())
.addGauge(Interns.info(NUM_OPEN_CONNECTIONS_NAME,
NUM_OPEN_CONNECTIONS_DESC), wrapper.getNumOpenConnections())
.addGauge(Interns.info(NUM_ACTIVE_HANDLER_NAME,
NUM_ACTIVE_HANDLER_DESC), wrapper.getActiveRpcHandlerCount());
}
metricsRegistry.snapshot(mrb, all);
}
示例9: getMetrics
import org.apache.hadoop.metrics2.MetricsCollector; //导入依赖的package包/类
@Override
public synchronized void getMetrics(MetricsCollector collector, boolean all) {
//Container goes through registered -> finished -> unregistered.
if (unregister) {
return;
}
if (finished || flushOnPeriod) {
registry.snapshot(collector.addRecord(registry.info()), all);
}
if (finished) {
this.unregister = true;
} else if (flushOnPeriod) {
flushOnPeriod = false;
scheduleTimerTaskIfRequired();
}
}
示例10: testCounterReporting
import org.apache.hadoop.metrics2.MetricsCollector; //导入依赖的package包/类
@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());
}
示例11: metrics2CycleIsNonDestructive
import org.apache.hadoop.metrics2.MetricsCollector; //导入依赖的package包/类
@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);
}
示例12: testPresence
import org.apache.hadoop.metrics2.MetricsCollector; //导入依赖的package包/类
@Test public void testPresence() {
MetricsRecordBuilder rb = getMetrics(new JvmMetrics("test", "test"));
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());
}
}
示例13: getMetrics
import org.apache.hadoop.metrics2.MetricsCollector; //导入依赖的package包/类
/**
* Yes this is a get function that doesn't return anything. Thanks Hadoop for breaking all
* expectations of java programmers. Instead of returning anything Hadoop metrics expects
* getMetrics to push the metrics into the collector.
*
* @param collector the collector
* @param all get all the metrics regardless of when they last changed.
*/
@Override
public void getMetrics(MetricsCollector collector, boolean all) {
MetricsRecordBuilder mrb = collector.addRecord(metricsName)
.setContext(metricsContext);
if (regionSources != null) {
lock.readLock().lock();
try {
for (MetricsRegionSourceImpl regionMetricSource : regionSources) {
regionMetricSource.snapshot(mrb, all);
}
} finally {
lock.readLock().unlock();
}
}
metricsRegistry.snapshot(mrb, all);
}
示例14: getMetrics
import org.apache.hadoop.metrics2.MetricsCollector; //导入依赖的package包/类
@Override
public void getMetrics(MetricsCollector metricsCollector, boolean all) {
MetricsRecordBuilder mrb = metricsCollector.addRecord(metricsName)
.setContext(metricsContext);
if (wrapper != null) {
mrb.addGauge(Interns.info(QUEUE_SIZE_NAME, QUEUE_SIZE_DESC), wrapper.getTotalQueueSize())
.addGauge(Interns.info(GENERAL_QUEUE_NAME, GENERAL_QUEUE_DESC),
wrapper.getGeneralQueueLength())
.addGauge(Interns.info(REPLICATION_QUEUE_NAME,
REPLICATION_QUEUE_DESC), wrapper.getReplicationQueueLength())
.addGauge(Interns.info(PRIORITY_QUEUE_NAME, PRIORITY_QUEUE_DESC),
wrapper.getPriorityQueueLength())
.addGauge(Interns.info(NUM_OPEN_CONNECTIONS_NAME,
NUM_OPEN_CONNECTIONS_DESC), wrapper.getNumOpenConnections())
.addGauge(Interns.info(NUM_ACTIVE_HANDLER_NAME,
NUM_ACTIVE_HANDLER_DESC), wrapper.getActiveRpcHandlerCount());
}
metricsRegistry.snapshot(mrb, all);
}