Search in sources :

Example 11 with AbstractMetric

use of org.apache.hadoop.metrics2.AbstractMetric in project hadoop by apache.

the class MetricsSourceAdapter method updateAttrCache.

private int updateAttrCache(Iterable<MetricsRecordImpl> lastRecs) {
    Preconditions.checkNotNull(lastRecs, "LastRecs should not be null");
    LOG.debug("Updating attr cache...");
    int recNo = 0;
    int numMetrics = 0;
    for (MetricsRecordImpl record : lastRecs) {
        for (MetricsTag t : record.tags()) {
            setAttrCacheTag(t, recNo);
            ++numMetrics;
        }
        for (AbstractMetric m : record.metrics()) {
            setAttrCacheMetric(m, recNo);
            ++numMetrics;
        }
        ++recNo;
    }
    LOG.debug("Done. # tags & metrics=" + numMetrics);
    return numMetrics;
}
Also used : AbstractMetric(org.apache.hadoop.metrics2.AbstractMetric) MetricsTag(org.apache.hadoop.metrics2.MetricsTag)

Example 12 with AbstractMetric

use of org.apache.hadoop.metrics2.AbstractMetric in project hadoop by apache.

the class RollingFileSystemSink method putMetrics.

@Override
public void putMetrics(MetricsRecord record) {
    synchronized (lock) {
        rollLogDirIfNeeded();
        if (currentOutStream != null) {
            currentOutStream.printf("%d %s.%s", record.timestamp(), record.context(), record.name());
            String separator = ": ";
            for (MetricsTag tag : record.tags()) {
                currentOutStream.printf("%s%s=%s", separator, tag.name(), tag.value());
                separator = ", ";
            }
            for (AbstractMetric metric : record.metrics()) {
                currentOutStream.printf("%s%s=%s", separator, metric.name(), metric.value());
            }
            currentOutStream.println();
            // is complete at the end of the interval.
            try {
                currentFSOutStream.hflush();
            } catch (IOException ex) {
                throwMetricsException("Failed flushing the stream", ex);
            }
            checkForErrors("Unable to write to log file");
        } else if (!ignoreError) {
            throwMetricsException("Unable to write to log file");
        }
    }
}
Also used : AbstractMetric(org.apache.hadoop.metrics2.AbstractMetric) IOException(java.io.IOException) MetricsTag(org.apache.hadoop.metrics2.MetricsTag)

Example 13 with AbstractMetric

use of org.apache.hadoop.metrics2.AbstractMetric in project hadoop by apache.

the class GraphiteSink method putMetrics.

@Override
public void putMetrics(MetricsRecord record) {
    StringBuilder lines = new StringBuilder();
    StringBuilder metricsPathPrefix = new StringBuilder();
    // Configure the hierarchical place to display the graph.
    metricsPathPrefix.append(metricsPrefix).append(".").append(record.context()).append(".").append(record.name());
    for (MetricsTag tag : record.tags()) {
        if (tag.value() != null) {
            metricsPathPrefix.append(".");
            metricsPathPrefix.append(tag.name());
            metricsPathPrefix.append("=");
            metricsPathPrefix.append(tag.value());
        }
    }
    // The record timestamp is in milliseconds while Graphite expects an epoc time in seconds.
    long timestamp = record.timestamp() / 1000L;
    // Collect datapoints.
    for (AbstractMetric metric : record.metrics()) {
        lines.append(metricsPathPrefix.toString() + "." + metric.name().replace(' ', '.')).append(" ").append(metric.value()).append(" ").append(timestamp).append("\n");
    }
    try {
        graphite.write(lines.toString());
    } catch (Exception e) {
        LOG.warn("Error sending metrics to Graphite", e);
        try {
            graphite.close();
        } catch (Exception e1) {
            throw new MetricsException("Error closing connection to Graphite", e1);
        }
    }
}
Also used : AbstractMetric(org.apache.hadoop.metrics2.AbstractMetric) MetricsException(org.apache.hadoop.metrics2.MetricsException) MetricsTag(org.apache.hadoop.metrics2.MetricsTag) IOException(java.io.IOException) MetricsException(org.apache.hadoop.metrics2.MetricsException)

Example 14 with AbstractMetric

use of org.apache.hadoop.metrics2.AbstractMetric in project hadoop by apache.

the class MBeanInfoBuilder method get.

MBeanInfo get() {
    curRecNo = 0;
    for (MetricsRecordImpl rec : recs) {
        for (MetricsTag t : rec.tags()) {
            attrs.add(newAttrInfo("tag." + t.name(), t.description(), "java.lang.String"));
        }
        for (AbstractMetric m : rec.metrics()) {
            m.visit(this);
        }
        ++curRecNo;
    }
    MetricsSystemImpl.LOG.debug(attrs);
    MBeanAttributeInfo[] attrsArray = new MBeanAttributeInfo[attrs.size()];
    return new MBeanInfo(name, description, attrs.toArray(attrsArray), null, null, // no ops/ctors/notifications
    null);
}
Also used : MBeanInfo(javax.management.MBeanInfo) AbstractMetric(org.apache.hadoop.metrics2.AbstractMetric) MetricsTag(org.apache.hadoop.metrics2.MetricsTag) MBeanAttributeInfo(javax.management.MBeanAttributeInfo)

Example 15 with AbstractMetric

use of org.apache.hadoop.metrics2.AbstractMetric in project hadoop by apache.

the class TestSchedulingUpdate method verifyExpectedCalls.

private void verifyExpectedCalls(long expectedCalls, int memory, int vcores) throws InterruptedException {
    boolean verified = false;
    int count = 0;
    while (count < 100) {
        if (scheduler.fsOpDurations.hasUpdateThreadRunChanged()) {
            break;
        }
        count++;
        Thread.sleep(10);
    }
    assertTrue("Update Thread has not run based on its metrics", scheduler.fsOpDurations.hasUpdateThreadRunChanged());
    assertEquals("Root queue metrics memory does not have expected value", memory, scheduler.getRootQueueMetrics().getAvailableMB());
    assertEquals("Root queue metrics cpu does not have expected value", vcores, scheduler.getRootQueueMetrics().getAvailableVirtualCores());
    MetricsCollectorImpl collector = new MetricsCollectorImpl();
    scheduler.fsOpDurations.getMetrics(collector, true);
    MetricsRecord record = collector.getRecords().get(0);
    for (AbstractMetric abstractMetric : record.metrics()) {
        if (abstractMetric.name().contains("UpdateThreadRunNumOps")) {
            assertEquals("Update Thread did not run expected number of times " + "based on metric record count", expectedCalls, abstractMetric.value());
            verified = true;
        }
    }
    assertTrue("Did not find metric for UpdateThreadRunNumOps", verified);
}
Also used : MetricsRecord(org.apache.hadoop.metrics2.MetricsRecord) AbstractMetric(org.apache.hadoop.metrics2.AbstractMetric) MetricsCollectorImpl(org.apache.hadoop.metrics2.impl.MetricsCollectorImpl)

Aggregations

AbstractMetric (org.apache.hadoop.metrics2.AbstractMetric)32 MetricsTag (org.apache.hadoop.metrics2.MetricsTag)19 MetricsRecord (org.apache.hadoop.metrics2.MetricsRecord)17 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)8 HashSet (java.util.HashSet)8 IOException (java.io.IOException)7 GraphiteSink (org.apache.hadoop.metrics2.sink.GraphiteSink)4 MetricsException (org.apache.hadoop.metrics2.MetricsException)3 Matchers.anyString (org.mockito.Matchers.anyString)3 DatagramPacket (java.net.DatagramPacket)2 DatagramSocket (java.net.DatagramSocket)2 HashMap (java.util.HashMap)2 MetricsVisitor (org.apache.hadoop.metrics2.MetricsVisitor)2 MetricsCollectorImpl (org.apache.hadoop.metrics2.impl.MetricsCollectorImpl)2 StatsDSink (org.apache.hadoop.metrics2.sink.StatsDSink)2 StatsD (org.apache.hadoop.metrics2.sink.StatsDSink.StatsD)2 ProducerRecord (org.apache.kafka.clients.producer.ProducerRecord)2 RecordMetadata (org.apache.kafka.clients.producer.RecordMetadata)2 Predicate (com.google.common.base.Predicate)1