Search in sources :

Example 11 with MetricsRecord

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

the class TestGraphiteMetrics method testPutMetrics.

@Test
public void testPutMetrics() {
    GraphiteSink sink = new GraphiteSink();
    List<MetricsTag> tags = new ArrayList<MetricsTag>();
    tags.add(new MetricsTag(MsInfo.Context, "all"));
    tags.add(new MetricsTag(MsInfo.Hostname, "host"));
    Set<AbstractMetric> metrics = new HashSet<AbstractMetric>();
    metrics.add(makeMetric("foo1", 1.25));
    metrics.add(makeMetric("foo2", 2.25));
    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.Hostname=host.foo1 1.25 10\n" + "null.all.Context.Context=all.Hostname=host.foo2 2.25 10\n") || result.equals("null.all.Context.Context=all.Hostname=host.foo2 2.25 10\n" + "null.all.Context.Context=all.Hostname=host.foo1 1.25 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 12 with MetricsRecord

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

the class TestGraphiteMetrics method testFailureAndPutMetrics.

@Test
public void testFailureAndPutMetrics() throws IOException {
    GraphiteSink sink = new GraphiteSink();
    List<MetricsTag> tags = new ArrayList<MetricsTag>();
    tags.add(new MetricsTag(MsInfo.Context, "all"));
    tags.add(new MetricsTag(MsInfo.Hostname, "host"));
    Set<AbstractMetric> metrics = new HashSet<AbstractMetric>();
    metrics.add(makeMetric("foo1", 1.25));
    metrics.add(makeMetric("foo2", 2.25));
    MetricsRecord record = new MetricsRecordImpl(MsInfo.Context, (long) 10000, tags, metrics);
    final GraphiteSink.Graphite mockGraphite = makeGraphite();
    Whitebox.setInternalState(sink, "graphite", mockGraphite);
    // throw exception when first try
    doThrow(new IOException("IO exception")).when(mockGraphite).write(anyString());
    sink.putMetrics(record);
    verify(mockGraphite).write(anyString());
    verify(mockGraphite).close();
    // reset mock and try again
    reset(mockGraphite);
    when(mockGraphite.isConnected()).thenReturn(false);
    ArgumentCaptor<String> argument = ArgumentCaptor.forClass(String.class);
    sink.putMetrics(record);
    verify(mockGraphite).write(argument.capture());
    String result = argument.getValue();
    assertEquals(true, result.equals("null.all.Context.Context=all.Hostname=host.foo1 1.25 10\n" + "null.all.Context.Context=all.Hostname=host.foo2 2.25 10\n") || result.equals("null.all.Context.Context=all.Hostname=host.foo2 2.25 10\n" + "null.all.Context.Context=all.Hostname=host.foo1 1.25 10\n"));
}
Also used : MetricsRecord(org.apache.hadoop.metrics2.MetricsRecord) ArrayList(java.util.ArrayList) AbstractMetric(org.apache.hadoop.metrics2.AbstractMetric) IOException(java.io.IOException) Matchers.anyString(org.mockito.Matchers.anyString) MetricsTag(org.apache.hadoop.metrics2.MetricsTag) GraphiteSink(org.apache.hadoop.metrics2.sink.GraphiteSink) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 13 with MetricsRecord

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

the class TestPatternFilter method mockMetricsRecord.

/**
   * Creates a mock MetricsRecord with the given name and tags.
   * 
   * @param name String name
   * @param tags List<MetricsTag> tags
   * @return MetricsRecord newly created mock
   */
private static MetricsRecord mockMetricsRecord(String name, List<MetricsTag> tags) {
    MetricsRecord record = mock(MetricsRecord.class);
    when(record.name()).thenReturn(name);
    when(record.tags()).thenReturn(tags);
    return record;
}
Also used : MetricsRecord(org.apache.hadoop.metrics2.MetricsRecord)

Example 14 with MetricsRecord

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

the class MetricsRecords method assertMetricNotNull.

public static void assertMetricNotNull(MetricsRecord record, String metricName) {
    AbstractMetric resourceLimitMetric = getFirstMetricByName(record, metricName);
    assertNotNull("Metric " + metricName + " doesn't exist", resourceLimitMetric);
}
Also used : AbstractMetric(org.apache.hadoop.metrics2.AbstractMetric)

Example 15 with MetricsRecord

use of org.apache.hadoop.metrics2.MetricsRecord 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)27 MetricsRecord (org.apache.hadoop.metrics2.MetricsRecord)25 MetricsTag (org.apache.hadoop.metrics2.MetricsTag)20 Test (org.junit.Test)18 ArrayList (java.util.ArrayList)10 HashSet (java.util.HashSet)8 IOException (java.io.IOException)7 MetricsCollectorImpl (org.apache.hadoop.metrics2.impl.MetricsCollectorImpl)4 GraphiteSink (org.apache.hadoop.metrics2.sink.GraphiteSink)4 MetricsException (org.apache.hadoop.metrics2.MetricsException)3 MetricsSink (org.apache.hadoop.metrics2.MetricsSink)3 Matchers.anyString (org.mockito.Matchers.anyString)3 DatagramPacket (java.net.DatagramPacket)2 DatagramSocket (java.net.DatagramSocket)2 HashMap (java.util.HashMap)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 ProducerRecord (org.apache.kafka.clients.producer.ProducerRecord)2 RecordMetadata (org.apache.kafka.clients.producer.RecordMetadata)2