Search in sources :

Example 1 with MetricsCollector

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);
}
Also used : MetricsRecordBuilder(org.apache.hadoop.metrics2.MetricsRecordBuilder)

Example 2 with MetricsCollector

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;
}
Also used : MetricsCollector(org.apache.hadoop.metrics2.MetricsCollector) InvocationOnMock(org.mockito.invocation.InvocationOnMock) MetricsRecordBuilder(org.apache.hadoop.metrics2.MetricsRecordBuilder)

Example 3 with MetricsCollector

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));
    }
}
Also used : Phase(org.apache.hadoop.hdfs.server.namenode.startupprogress.Phase) StartupProgressView(org.apache.hadoop.hdfs.server.namenode.startupprogress.StartupProgressView) MetricsRecordBuilder(org.apache.hadoop.metrics2.MetricsRecordBuilder)

Example 4 with MetricsCollector

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());
}
Also used : IOException(java.io.IOException) MetricsTag(org.apache.hadoop.metrics2.MetricsTag)

Example 5 with MetricsCollector

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);
}
Also used : MetricsCollector(org.apache.hadoop.metrics2.MetricsCollector) MetricsSource(org.apache.hadoop.metrics2.MetricsSource) MetricsRecordBuilder(org.apache.hadoop.metrics2.MetricsRecordBuilder) Test(org.junit.Test)

Aggregations

MetricsRecordBuilder (org.apache.hadoop.metrics2.MetricsRecordBuilder)36 MetricsCollector (org.apache.hadoop.metrics2.MetricsCollector)6 Test (org.junit.Test)4 Configuration (org.apache.hadoop.conf.Configuration)2 IOException (java.io.IOException)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 MetricRegistryInfo (org.apache.hadoop.hbase.metrics.MetricRegistryInfo)1 Phase (org.apache.hadoop.hdfs.server.namenode.startupprogress.Phase)1 StartupProgressView (org.apache.hadoop.hdfs.server.namenode.startupprogress.StartupProgressView)1 TopConf (org.apache.hadoop.hdfs.server.namenode.top.TopConf)1 TopMetrics (org.apache.hadoop.hdfs.server.namenode.top.metrics.TopMetrics)1 MetricsSource (org.apache.hadoop.metrics2.MetricsSource)1 MetricsTag (org.apache.hadoop.metrics2.MetricsTag)1 JvmMetricsInfo (org.apache.hadoop.metrics2.source.JvmMetricsInfo)1 JvmPauseMonitor (org.apache.hadoop.util.JvmPauseMonitor)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1