use of org.apache.hadoop.metrics2.MetricsCollector in project hadoop by apache.
the class JvmMetrics method getMetrics.
@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);
}
use of org.apache.hadoop.metrics2.MetricsCollector in project hadoop by apache.
the class MetricsAsserts method mockMetricsRecordBuilder.
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;
}
use of org.apache.hadoop.metrics2.MetricsCollector in project hadoop by apache.
the class StartupProgressMetrics method getMetrics.
@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));
}
}
use of org.apache.hadoop.metrics2.MetricsCollector in project hadoop by apache.
the class DataNodeMetricHelper method getMetrics.
/**
* Get metrics helper provides Helper function for
* metrics2 interface to act as a Metric source
*
* @param collector Metrics Collector that is passed in
* @param beanClass The Class that currently impliments the metric functions
* @param context A string that idenitifies the context
*
* @throws IOException
*/
public static void getMetrics(MetricsCollector collector, FSDatasetMBean beanClass, String context) throws IOException {
if (beanClass == null) {
throw new IOException("beanClass cannot be null");
}
String className = beanClass.getClass().getName();
collector.addRecord(className).setContext(context).addGauge(Interns.info("Capacity", "Total storage capacity"), beanClass.getCapacity()).addGauge(Interns.info("DfsUsed", "Total bytes used by dfs datanode"), beanClass.getDfsUsed()).addGauge(Interns.info("Remaining", "Total bytes of free storage"), beanClass.getRemaining()).add(new MetricsTag(Interns.info("StorageInfo", "Storage ID"), beanClass.getStorageInfo())).addGauge(Interns.info("NumFailedVolumes", "Number of failed Volumes" + " in the data Node"), beanClass.getNumFailedVolumes()).addGauge(Interns.info("LastVolumeFailureDate", "Last Volume failure in" + " milliseconds from epoch"), beanClass.getLastVolumeFailureDate()).addGauge(Interns.info("EstimatedCapacityLostTotal", "Total capacity lost" + " due to volume failure"), beanClass.getEstimatedCapacityLostTotal()).addGauge(Interns.info("CacheUsed", "Datanode cache used in bytes"), beanClass.getCacheUsed()).addGauge(Interns.info("CacheCapacity", "Datanode cache capacity"), beanClass.getCacheCapacity()).addGauge(Interns.info("NumBlocksCached", "Datanode number" + " of blocks cached"), beanClass.getNumBlocksCached()).addGauge(Interns.info("NumBlocksFailedToCache", "Datanode number of " + "blocks failed to cache"), beanClass.getNumBlocksFailedToCache()).addGauge(Interns.info("NumBlocksFailedToUnCache", "Datanode number of" + " blocks failed in cache eviction"), beanClass.getNumBlocksFailedToUncache());
}
use of org.apache.hadoop.metrics2.MetricsCollector in project hadoop by apache.
the class TestMetricsAnnotations method testHybrid.
@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);
}
Aggregations