Search in sources :

Example 26 with Record

use of org.apache.hadoop.metrics2.util.MetricsCache.Record in project hadoop by apache.

the class TestGraphiteMetrics method testPutMetrics2.

@Test
public void testPutMetrics2() {
    GraphiteSink sink = new GraphiteSink();
    List<MetricsTag> tags = new ArrayList<MetricsTag>();
    tags.add(new MetricsTag(MsInfo.Context, "all"));
    tags.add(new MetricsTag(MsInfo.Hostname, null));
    Set<AbstractMetric> metrics = new HashSet<AbstractMetric>();
    metrics.add(makeMetric("foo1", 1));
    metrics.add(makeMetric("foo2", 2));
    MetricsRecord record = new MetricsRecordImpl(MsInfo.Context, (long) 10000, tags, metrics);
    ArgumentCaptor<String> argument = ArgumentCaptor.forClass(String.class);
    final GraphiteSink.Graphite mockGraphite = makeGraphite();
    Whitebox.setInternalState(sink, "graphite", mockGraphite);
    sink.putMetrics(record);
    try {
        verify(mockGraphite).write(argument.capture());
    } catch (IOException e) {
        e.printStackTrace();
    }
    String result = argument.getValue();
    assertEquals(true, result.equals("null.all.Context.Context=all.foo1 1 10\n" + "null.all.Context.Context=all.foo2 2 10\n") || result.equals("null.all.Context.Context=all.foo2 2 10\n" + "null.all.Context.Context=all.foo1 1 10\n"));
}
Also used : MetricsRecord(org.apache.hadoop.metrics2.MetricsRecord) ArrayList(java.util.ArrayList) AbstractMetric(org.apache.hadoop.metrics2.AbstractMetric) Matchers.anyString(org.mockito.Matchers.anyString) IOException(java.io.IOException) MetricsTag(org.apache.hadoop.metrics2.MetricsTag) GraphiteSink(org.apache.hadoop.metrics2.sink.GraphiteSink) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 27 with Record

use of org.apache.hadoop.metrics2.util.MetricsCache.Record in project hadoop by apache.

the class MetricsRecords method assertTag.

public static void assertTag(MetricsRecord record, String tagName, String expectedValue) {
    MetricsTag processIdTag = getFirstTagByName(record, tagName);
    assertNotNull(processIdTag);
    assertEquals(expectedValue, processIdTag.value());
}
Also used : MetricsTag(org.apache.hadoop.metrics2.MetricsTag)

Example 28 with Record

use of org.apache.hadoop.metrics2.util.MetricsCache.Record in project hadoop by apache.

the class MetricsRecords method assertMetric.

public static void assertMetric(MetricsRecord record, String metricName, Number expectedValue) {
    AbstractMetric resourceLimitMetric = getFirstMetricByName(record, metricName);
    assertNotNull(resourceLimitMetric);
    assertEquals(expectedValue, resourceLimitMetric.value());
}
Also used : AbstractMetric(org.apache.hadoop.metrics2.AbstractMetric)

Example 29 with Record

use of org.apache.hadoop.metrics2.util.MetricsCache.Record in project hadoop by apache.

the class MetricsRecords method getMetricValueByName.

public static Number getMetricValueByName(MetricsRecord record, String metricName) {
    AbstractMetric resourceLimitMetric = getFirstMetricByName(record, metricName);
    assertNotNull(resourceLimitMetric);
    return resourceLimitMetric.value();
}
Also used : AbstractMetric(org.apache.hadoop.metrics2.AbstractMetric)

Example 30 with Record

use of org.apache.hadoop.metrics2.util.MetricsCache.Record in project hadoop by apache.

the class TestNameNodeMetrics method waitForDnMetricValue.

/**
   * Wait for the named gauge value from the metrics source to reach the
   * desired value.
   *
   * There's an initial delay then a spin cycle of sleep and poll. Because
   * all the tests use a shared FS instance, these tests are not independent;
   * that's why the initial sleep is in there.
   *
   * @param source metrics source
   * @param name gauge name
   * @param expected expected value
   * @return the last metrics record polled
   * @throws Exception if something went wrong.
   */
private MetricsRecordBuilder waitForDnMetricValue(String source, String name, long expected) throws Exception {
    MetricsRecordBuilder rb;
    long gauge;
    //initial wait.
    waitForDeletion();
    //lots of retries are allowed for slow systems; fast ones will still
    //exit early
    int retries = (DATANODE_COUNT + 1) * WAIT_GAUGE_VALUE_RETRIES;
    rb = getMetrics(source);
    gauge = MetricsAsserts.getLongGauge(name, rb);
    while (gauge != expected && (--retries > 0)) {
        Thread.sleep(DFS_REDUNDANCY_INTERVAL * 500);
        rb = getMetrics(source);
        gauge = MetricsAsserts.getLongGauge(name, rb);
    }
    //at this point the assertion is valid or the retry count ran out
    assertGauge(name, expected, rb);
    return rb;
}
Also used : MetricsRecordBuilder(org.apache.hadoop.metrics2.MetricsRecordBuilder)

Aggregations

AbstractMetric (org.apache.hadoop.metrics2.AbstractMetric)25 MetricsTag (org.apache.hadoop.metrics2.MetricsTag)19 MetricsRecord (org.apache.hadoop.metrics2.MetricsRecord)17 Test (org.junit.Test)14 ArrayList (java.util.ArrayList)8 HashSet (java.util.HashSet)7 IOException (java.io.IOException)6 MetricsCollectorImpl (org.apache.hadoop.metrics2.impl.MetricsCollectorImpl)4 MetricsException (org.apache.hadoop.metrics2.MetricsException)3 MetricsRecordBuilder (org.apache.hadoop.metrics2.MetricsRecordBuilder)3 GraphiteSink (org.apache.hadoop.metrics2.sink.GraphiteSink)3 Matchers.anyString (org.mockito.Matchers.anyString)3 DatagramPacket (java.net.DatagramPacket)2 DatagramSocket (java.net.DatagramSocket)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Configuration (org.apache.hadoop.conf.Configuration)2 StatsDSink (org.apache.hadoop.metrics2.sink.StatsDSink)2 StatsD (org.apache.hadoop.metrics2.sink.StatsDSink.StatsD)2 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)2