Search in sources :

Example 1 with GangliaSink30

use of org.apache.hadoop.metrics2.sink.ganglia.GangliaSink30 in project hadoop by apache.

the class TestGangliaSink method testShouldCreateDatagramSocketByDefault.

@Test
public void testShouldCreateDatagramSocketByDefault() throws Exception {
    SubsetConfiguration conf = new ConfigBuilder().subset("test.sink.ganglia");
    GangliaSink30 gangliaSink = new GangliaSink30();
    gangliaSink.init(conf);
    DatagramSocket socket = gangliaSink.getDatagramSocket();
    assertFalse("Did not create DatagramSocket", socket == null || socket instanceof MulticastSocket);
}
Also used : MulticastSocket(java.net.MulticastSocket) DatagramSocket(java.net.DatagramSocket) ConfigBuilder(org.apache.hadoop.metrics2.impl.ConfigBuilder) SubsetConfiguration(org.apache.commons.configuration2.SubsetConfiguration) Test(org.junit.Test)

Example 2 with GangliaSink30

use of org.apache.hadoop.metrics2.sink.ganglia.GangliaSink30 in project hadoop by apache.

the class TestGangliaSink method testShouldCreateDatagramSocketIfMulticastIsDisabled.

@Test
public void testShouldCreateDatagramSocketIfMulticastIsDisabled() throws Exception {
    SubsetConfiguration conf = new ConfigBuilder().add("test.sink.ganglia.multicast", false).subset("test.sink.ganglia");
    GangliaSink30 gangliaSink = new GangliaSink30();
    gangliaSink.init(conf);
    DatagramSocket socket = gangliaSink.getDatagramSocket();
    assertFalse("Did not create DatagramSocket", socket == null || socket instanceof MulticastSocket);
}
Also used : MulticastSocket(java.net.MulticastSocket) DatagramSocket(java.net.DatagramSocket) ConfigBuilder(org.apache.hadoop.metrics2.impl.ConfigBuilder) SubsetConfiguration(org.apache.commons.configuration2.SubsetConfiguration) Test(org.junit.Test)

Example 3 with GangliaSink30

use of org.apache.hadoop.metrics2.sink.ganglia.GangliaSink30 in project hadoop by apache.

the class TestGangliaSink method testShouldCreateMulticastSocket.

@Test
public void testShouldCreateMulticastSocket() throws Exception {
    SubsetConfiguration conf = new ConfigBuilder().add("test.sink.ganglia.multicast", true).subset("test.sink.ganglia");
    GangliaSink30 gangliaSink = new GangliaSink30();
    gangliaSink.init(conf);
    DatagramSocket socket = gangliaSink.getDatagramSocket();
    assertTrue("Did not create MulticastSocket", socket != null && socket instanceof MulticastSocket);
    int ttl = ((MulticastSocket) socket).getTimeToLive();
    assertEquals("Did not set default TTL", 1, ttl);
}
Also used : MulticastSocket(java.net.MulticastSocket) DatagramSocket(java.net.DatagramSocket) ConfigBuilder(org.apache.hadoop.metrics2.impl.ConfigBuilder) SubsetConfiguration(org.apache.commons.configuration2.SubsetConfiguration) Test(org.junit.Test)

Example 4 with GangliaSink30

use of org.apache.hadoop.metrics2.sink.ganglia.GangliaSink30 in project hadoop by apache.

the class TestGangliaSink method testShouldSetMulticastSocketTtl.

@Test
public void testShouldSetMulticastSocketTtl() throws Exception {
    SubsetConfiguration conf = new ConfigBuilder().add("test.sink.ganglia.multicast", true).add("test.sink.ganglia.multicast.ttl", 3).subset("test.sink.ganglia");
    GangliaSink30 gangliaSink = new GangliaSink30();
    gangliaSink.init(conf);
    DatagramSocket socket = gangliaSink.getDatagramSocket();
    assertTrue("Did not create MulticastSocket", socket != null && socket instanceof MulticastSocket);
    int ttl = ((MulticastSocket) socket).getTimeToLive();
    assertEquals("Did not set TTL", 3, ttl);
}
Also used : MulticastSocket(java.net.MulticastSocket) DatagramSocket(java.net.DatagramSocket) ConfigBuilder(org.apache.hadoop.metrics2.impl.ConfigBuilder) SubsetConfiguration(org.apache.commons.configuration2.SubsetConfiguration) Test(org.junit.Test)

Example 5 with GangliaSink30

use of org.apache.hadoop.metrics2.sink.ganglia.GangliaSink30 in project hadoop by apache.

the class TestGangliaMetrics method testGangliaMetrics2.

@Test
public void testGangliaMetrics2() throws Exception {
    // Setting long interval to avoid periodic publishing.
    // We manually publish metrics by MeticsSystem#publishMetricsNow here.
    ConfigBuilder cb = new ConfigBuilder().add("*.period", 120).add(testNamePrefix + ".sink.gsink30.context", // filter out only "test"
    testNamePrefix).add(testNamePrefix + ".sink.gsink31.context", // filter out only "test"
    testNamePrefix).save(TestMetricsConfig.getTestFilename("hadoop-metrics2-" + testNamePrefix));
    MetricsSystemImpl ms = new MetricsSystemImpl(testNamePrefix);
    ms.start();
    TestSource s1 = ms.register("s1", "s1 desc", new TestSource("s1rec"));
    s1.c1.incr();
    s1.xxx.incr();
    s1.g1.set(2);
    s1.yyy.incr(2);
    s1.s1.add(0);
    final int expectedCountFromGanglia30 = expectedMetrics.length;
    final int expectedCountFromGanglia31 = 2 * expectedMetrics.length;
    // Setup test for GangliaSink30
    AbstractGangliaSink gsink30 = new GangliaSink30();
    gsink30.init(cb.subset(testNamePrefix));
    MockDatagramSocket mockds30 = new MockDatagramSocket();
    GangliaMetricsTestHelper.setDatagramSocket(gsink30, mockds30);
    // Setup test for GangliaSink31
    AbstractGangliaSink gsink31 = new GangliaSink31();
    gsink31.init(cb.subset(testNamePrefix));
    MockDatagramSocket mockds31 = new MockDatagramSocket();
    GangliaMetricsTestHelper.setDatagramSocket(gsink31, mockds31);
    // register the sinks
    ms.register("gsink30", "gsink30 desc", gsink30);
    ms.register("gsink31", "gsink31 desc", gsink31);
    // publish the metrics
    ms.publishMetricsNow();
    ms.stop();
    // check GanfliaSink30 data
    checkMetrics(mockds30.getCapturedSend(), expectedCountFromGanglia30);
    // check GanfliaSink31 data
    checkMetrics(mockds31.getCapturedSend(), expectedCountFromGanglia31);
}
Also used : AbstractGangliaSink(org.apache.hadoop.metrics2.sink.ganglia.AbstractGangliaSink) GangliaSink31(org.apache.hadoop.metrics2.sink.ganglia.GangliaSink31) GangliaSink30(org.apache.hadoop.metrics2.sink.ganglia.GangliaSink30) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 DatagramSocket (java.net.DatagramSocket)4 MulticastSocket (java.net.MulticastSocket)4 SubsetConfiguration (org.apache.commons.configuration2.SubsetConfiguration)4 ConfigBuilder (org.apache.hadoop.metrics2.impl.ConfigBuilder)4 GangliaSink30 (org.apache.hadoop.metrics2.sink.ganglia.GangliaSink30)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 AbstractMetric (org.apache.hadoop.metrics2.AbstractMetric)1 MetricsRecord (org.apache.hadoop.metrics2.MetricsRecord)1 MetricsTag (org.apache.hadoop.metrics2.MetricsTag)1 AbstractGangliaSink (org.apache.hadoop.metrics2.sink.ganglia.AbstractGangliaSink)1 GangliaSink31 (org.apache.hadoop.metrics2.sink.ganglia.GangliaSink31)1