Search in sources :

Example 11 with Query

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

the class BaseOutputWriterTests method booleanValuesAreTransformedToNumber.

@Test
public void booleanValuesAreTransformedToNumber() throws Exception {
    final ArrayList<Result> processedResults = Lists.newArrayList();
    BaseOutputWriter outputWriter = new BaseOutputWriter(ImmutableList.<String>of(), true, false, Maps.<String, Object>newHashMap()) {

        @Override
        protected void internalWrite(Server server, Query query, ImmutableList<Result> results) throws Exception {
            processedResults.addAll(results);
        }

        @Override
        public void validateSetup(Server server, Query query) throws ValidationException {
        }
    };
    Result result = new Result(0, "", "", "", "", "", ImmutableMap.<String, Object>of("true", true, "false", false));
    outputWriter.doWrite(null, null, ImmutableList.of(result));
    assertThat(processedResults).hasSize(1);
    Result processedResult = processedResults.get(0);
    assertThat(processedResult.getValues().get("true")).isEqualTo(1);
    assertThat(processedResult.getValues().get("false")).isEqualTo(0);
}
Also used : Server(com.googlecode.jmxtrans.model.Server) Query(com.googlecode.jmxtrans.model.Query) ImmutableList(com.google.common.collect.ImmutableList) Result(com.googlecode.jmxtrans.model.Result) Test(org.junit.Test)

Example 12 with Query

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

the class JmxTransformer method processServersIntoJobs.

/**
	 * Processes all the Servers into Job's
	 * <p/>
	 * Needs to be called after processFiles()
	 */
private void processServersIntoJobs() throws LifecycleException {
    for (Server server : this.masterServersList) {
        try {
            // need to inject the poolMap
            for (Query query : server.getQueries()) {
                for (OutputWriter writer : query.getOutputWriterInstances()) {
                    writer.start();
                }
            }
            // Now validate the setup of each of the OutputWriter's per
            // query.
            this.validateSetup(server, server.getQueries());
            // Now schedule the jobs for execution.
            this.scheduleJob(server);
        } catch (ParseException ex) {
            throw new LifecycleException("Error parsing cron expression: " + server.getCronExpression(), ex);
        } catch (SchedulerException ex) {
            throw new LifecycleException("Error scheduling job for server: " + server, ex);
        } catch (ValidationException ex) {
            throw new LifecycleException("Error validating json setup for query", ex);
        }
    }
}
Also used : LifecycleException(com.googlecode.jmxtrans.exceptions.LifecycleException) SchedulerException(org.quartz.SchedulerException) ValidationException(com.googlecode.jmxtrans.model.ValidationException) MBeanServer(javax.management.MBeanServer) Server(com.googlecode.jmxtrans.model.Server) Query(com.googlecode.jmxtrans.model.Query) ParseException(java.text.ParseException) OutputWriter(com.googlecode.jmxtrans.model.OutputWriter)

Example 13 with Query

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

the class ServerListBuilderTest method outputWritersAreReusedOnQueries.

@Test
public void outputWritersAreReusedOnQueries() {
    Query q1 = Query.builder(dummyQuery()).addOutputWriterFactory(new DummyOutputWriterFactory("output1")).build();
    Query q2 = Query.builder(queryWithAllTypeNames()).addOutputWriterFactory(new DummyOutputWriterFactory("output1")).build();
    Server server = Server.builder(serverWithNoQuery()).addQuery(q1).addQuery(q2).build();
    ImmutableList<Server> servers = new ServerListBuilder().add(singletonList(server)).build();
    assertThat(servers).hasSize(1);
    Server createdServer = servers.iterator().next();
    assertThat(createdServer.getQueries()).hasSize(2);
    Iterator<Query> queryIterator = createdServer.getQueries().iterator();
    Query query1 = queryIterator.next();
    Query query2 = queryIterator.next();
    assertThat(query1.getOutputWriterInstances()).hasSize(1);
    assertThat(query2.getOutputWriterInstances()).hasSize(1);
    assertThat(query1.getOutputWriterInstances().iterator().next()).isSameAs(query2.getOutputWriterInstances().iterator().next());
}
Also used : QueryFixtures.dummyQuery(com.googlecode.jmxtrans.model.QueryFixtures.dummyQuery) Query(com.googlecode.jmxtrans.model.Query) ServerFixtures.serverWithNoQuery(com.googlecode.jmxtrans.model.ServerFixtures.serverWithNoQuery) ServerFixtures.dummyServer(com.googlecode.jmxtrans.model.ServerFixtures.dummyServer) Server(com.googlecode.jmxtrans.model.Server) Test(org.junit.Test)

Example 14 with Query

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

the class ServerListBuilderTest method outputWritersAreReusedOnServersAndQueries.

@Test
public void outputWritersAreReusedOnServersAndQueries() {
    Server server = Server.builder(serverWithNoQuery()).addOutputWriterFactory(new DummyOutputWriterFactory("output1")).addQuery(Query.builder(dummyQuery()).addOutputWriterFactory(new DummyOutputWriterFactory("output1")).build()).build();
    ImmutableList<Server> servers = new ServerListBuilder().add(singletonList(server)).build();
    Server createdServer = servers.iterator().next();
    Query createdQuery = createdServer.getQueries().iterator().next();
    assertThat(createdQuery.getOutputWriterInstances()).hasSize(1);
    assertThat(createdServer.getOutputWriters().iterator().next()).isSameAs(createdQuery.getOutputWriterInstances().iterator().next());
}
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) ServerFixtures.serverWithNoQuery(com.googlecode.jmxtrans.model.ServerFixtures.serverWithNoQuery) Test(org.junit.Test)

Example 15 with Query

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

the class JmxTransformer method stopWriterAndClearMasterServerList.

/**
	 * Shut down the output writers and clear the master server list
	 * Used both during shutdown and when re-reading config files
	 */
private void stopWriterAndClearMasterServerList() {
    for (Server server : this.masterServersList) {
        for (OutputWriter writer : server.getOutputWriters()) {
            try {
                writer.close();
            } catch (LifecycleException ex) {
                log.error("Eror stopping writer: {}", writer);
            }
        }
        for (Query query : server.getQueries()) {
            for (OutputWriter writer : query.getOutputWriterInstances()) {
                try {
                    writer.close();
                    log.debug("Stopped writer: {} for query: {}", writer, query);
                } catch (LifecycleException ex) {
                    log.error("Error stopping writer: {} for query: {}", writer, query, ex);
                }
            }
        }
    }
    this.masterServersList = ImmutableList.of();
}
Also used : LifecycleException(com.googlecode.jmxtrans.exceptions.LifecycleException) MBeanServer(javax.management.MBeanServer) Server(com.googlecode.jmxtrans.model.Server) Query(com.googlecode.jmxtrans.model.Query) OutputWriter(com.googlecode.jmxtrans.model.OutputWriter)

Aggregations

Query (com.googlecode.jmxtrans.model.Query)15 Server (com.googlecode.jmxtrans.model.Server)13 Test (org.junit.Test)8 Result (com.googlecode.jmxtrans.model.Result)6 OutputWriter (com.googlecode.jmxtrans.model.OutputWriter)4 ServerFixtures.dummyServer (com.googlecode.jmxtrans.model.ServerFixtures.dummyServer)4 JmxProcess (com.googlecode.jmxtrans.model.JmxProcess)3 QueryFixtures.dummyQuery (com.googlecode.jmxtrans.model.QueryFixtures.dummyQuery)3 ServerFixtures.serverWithNoQuery (com.googlecode.jmxtrans.model.ServerFixtures.serverWithNoQuery)3 MBeanServer (javax.management.MBeanServer)3 ImmutableList (com.google.common.collect.ImmutableList)2 Injector (com.google.inject.Injector)2 JmxTransformer (com.googlecode.jmxtrans.JmxTransformer)2 JmxTransConfiguration (com.googlecode.jmxtrans.cli.JmxTransConfiguration)2 LifecycleException (com.googlecode.jmxtrans.exceptions.LifecycleException)2 GraphiteWriter (com.googlecode.jmxtrans.model.output.GraphiteWriter)2 StdOutWriter (com.googlecode.jmxtrans.model.output.StdOutWriter)2 ArrayList (java.util.ArrayList)2 AttributeNotFoundException (javax.management.AttributeNotFoundException)2 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)2