Search in sources :

Example 26 with Server

use of com.googlecode.jmxtrans.model.Server in project jmxtrans by jmxtrans.

the class GraphiteWriterFactoryTest method canParseConfigurationFileWithCustomParameters.

@Test
public void canParseConfigurationFileWithCustomParameters() throws LifecycleException, URISyntaxException {
    ImmutableList<Server> servers = configurationParser.parseServers(ImmutableList.of(file("/graphite-writer-factory-example2.json")), false);
    assertThat(servers).hasSize(1);
    Server server = servers.get(0);
    assertThat(server.getQueries()).hasSize(1);
    Query query = server.getQueries().iterator().next();
    assertThat(query.getOutputWriterInstances()).hasSize(1);
    OutputWriter outputWriter = query.getOutputWriterInstances().iterator().next();
    assertThat(outputWriter).isInstanceOf(ResultTransformerOutputWriter.class);
    ResultTransformerOutputWriter resultTransformerOutputWriter = (ResultTransformerOutputWriter) outputWriter;
    OutputWriter target = resultTransformerOutputWriter.getTarget();
    assertThat(target).isInstanceOf(WriterPoolOutputWriter.class);
    WriterPoolOutputWriter writerPoolOutputWriter = (WriterPoolOutputWriter) target;
    assertThat(writerPoolOutputWriter.getSocketTimeoutMs()).isEqualTo(1000);
    assertThat(writerPoolOutputWriter.getPoolClaimTimeout().getTimeout()).isEqualTo(2);
}
Also used : Server(com.googlecode.jmxtrans.model.Server) Query(com.googlecode.jmxtrans.model.Query) OutputWriter(com.googlecode.jmxtrans.model.OutputWriter) IntegrationTest(com.googlecode.jmxtrans.test.IntegrationTest) Test(org.junit.Test)

Example 27 with Server

use of com.googlecode.jmxtrans.model.Server in project jmxtrans by jmxtrans.

the class GraphiteWriterFactoryTest method writer_using_udp_protocol.

@Test
public void writer_using_udp_protocol() throws LifecycleException, URISyntaxException {
    ImmutableList<Server> servers = configurationParser.parseServers(ImmutableList.of(file("/graphite-writer-factory-example-with-udp.json")), false);
    assertThat(servers).hasSize(1);
    Server server = servers.get(0);
    assertThat(server.getQueries()).hasSize(1);
    Query query = server.getQueries().iterator().next();
    assertThat(query.getOutputWriterInstances()).hasSize(1);
    OutputWriter outputWriter = query.getOutputWriterInstances().iterator().next();
    assertThat(outputWriter).isInstanceOf(ResultTransformerOutputWriter.class);
    ResultTransformerOutputWriter resultTransformerOutputWriter = (ResultTransformerOutputWriter) outputWriter;
    OutputWriter target = resultTransformerOutputWriter.getTarget();
    assertThat(target).isInstanceOf(WriterPoolOutputWriter.class);
    LifecycledPool writerPool = ((WriterPoolOutputWriter) target).getWriterPool();
    assertThat(writerPool).isInstanceOf(BlazePool.class);
    BlazePool blazePool = (BlazePool) writerPool;
    // using UdpOutputWriterBuilder
    try {
        // first level allocator
        Field allocator = blazePool.getClass().getDeclaredField("allocator");
        allocator.setAccessible(true);
        Object insideAllocator = allocator.get(blazePool);
        // second level allocator
        Field allocatorLv2 = insideAllocator.getClass().getDeclaredField("allocator");
        allocatorLv2.setAccessible(true);
        Object level2Allocator = allocatorLv2.get(insideAllocator);
        // third level
        Field allocatorLv3 = level2Allocator.getClass().getDeclaredField("allocator");
        allocatorLv3.setAccessible(true);
        Object level3Allocator = allocatorLv3.get(level2Allocator);
        assertThat(level3Allocator).isInstanceOf(DatagramChannelAllocator.class);
    } catch (IllegalAccessException | NoSuchFieldException e) {
        fail();
    }
}
Also used : Server(com.googlecode.jmxtrans.model.Server) Query(com.googlecode.jmxtrans.model.Query) OutputWriter(com.googlecode.jmxtrans.model.OutputWriter) Field(java.lang.reflect.Field) BlazePool(stormpot.BlazePool) LifecycledPool(stormpot.LifecycledPool) IntegrationTest(com.googlecode.jmxtrans.test.IntegrationTest) Test(org.junit.Test)

Example 28 with Server

use of com.googlecode.jmxtrans.model.Server in project jmxtrans by jmxtrans.

the class NagiosWriterTest method testWrite.

@Test
public void testWrite() throws Exception {
    // Given
    File logFile = temporaryFolder.newFile("keyout.log");
    NagiosWriter writer = new NagiosWriter(ImmutableList.<String>of(), true, false, ImmutableList.<String>of("ObjectPendingFinalizationCount"), ImmutableList.<String>of("5"), "nagiost", logFile.getAbsolutePath(), null, null, ImmutableMap.<String, Object>of());
    Server server = dummyServer();
    Query query = dummyQuery();
    // When
    writer.validateSetup(server, query);
    writer.doWrite(server, query, singleNumericResult());
    // Then
    String log = Files.toString(logFile, Charset.forName("UTF-8"));
    assertThat(log.trim()).isEqualTo("[0] PROCESS_SERVICE_CHECK_RESULT;nagiost;ObjectPendingFinalizationCount;2;");
}
Also used : ServerFixtures.dummyServer(com.googlecode.jmxtrans.model.ServerFixtures.dummyServer) Server(com.googlecode.jmxtrans.model.Server) QueryFixtures.dummyQuery(com.googlecode.jmxtrans.model.QueryFixtures.dummyQuery) Query(com.googlecode.jmxtrans.model.Query) File(java.io.File) Test(org.junit.Test)

Example 29 with Server

use of com.googlecode.jmxtrans.model.Server in project jmxtrans by jmxtrans.

the class ConfigurationParserTest method mixJsonAndYamlFormats.

@Test
public void mixJsonAndYamlFormats() throws URISyntaxException, LifecycleException {
    File jsonInput = new File(ConfigurationParserTest.class.getResource("/example.json").toURI());
    File yamlInput = new File(ConfigurationParserTest.class.getResource("/example2.yml").toURI());
    ImmutableList<Server> servers = configurationParser.parseServers(of(jsonInput, yamlInput), false);
    assertThat(servers).hasSize(2);
}
Also used : ServerFixtures.dummyServer(com.googlecode.jmxtrans.model.ServerFixtures.dummyServer) Server(com.googlecode.jmxtrans.model.Server) File(java.io.File) Test(org.junit.Test)

Example 30 with Server

use of com.googlecode.jmxtrans.model.Server in project jmxtrans by jmxtrans.

the class ConfigurationParserTest method mergeAlreadyExistingServerDoesNotModifyList.

@Test
public void mergeAlreadyExistingServerDoesNotModifyList() throws ValidationException {
    List<Server> existingServers = new ArrayList<Server>();
    existingServers.add(dummyServer());
    List<Server> newServers = new ArrayList<Server>();
    newServers.add(dummyServer());
    List<Server> merged = configurationParser.mergeServerLists(existingServers, newServers);
    assertThat(merged).hasSize(1);
    Server mergedServer = merged.get(0);
    assertThat(mergedServer.getQueries()).hasSize(1);
}
Also used : ServerFixtures.dummyServer(com.googlecode.jmxtrans.model.ServerFixtures.dummyServer) Server(com.googlecode.jmxtrans.model.Server) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

Server (com.googlecode.jmxtrans.model.Server)38 Test (org.junit.Test)26 Query (com.googlecode.jmxtrans.model.Query)21 ServerFixtures.dummyServer (com.googlecode.jmxtrans.model.ServerFixtures.dummyServer)13 OutputWriter (com.googlecode.jmxtrans.model.OutputWriter)9 QueryFixtures.dummyQuery (com.googlecode.jmxtrans.model.QueryFixtures.dummyQuery)6 Result (com.googlecode.jmxtrans.model.Result)6 IntegrationTest (com.googlecode.jmxtrans.test.IntegrationTest)6 File (java.io.File)6 ArrayList (java.util.ArrayList)5 MBeanServer (javax.management.MBeanServer)5 Field (java.lang.reflect.Field)4 BlazePool (stormpot.BlazePool)4 LifecycledPool (stormpot.LifecycledPool)4 ImmutableList (com.google.common.collect.ImmutableList)3 JmxProcess (com.googlecode.jmxtrans.model.JmxProcess)3 ServerFixtures.serverWithNoQuery (com.googlecode.jmxtrans.model.ServerFixtures.serverWithNoQuery)3 ManagedThreadPoolExecutor (com.googlecode.jmxtrans.monitoring.ManagedThreadPoolExecutor)3 IOException (java.io.IOException)3 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)3