Search in sources :

Example 11 with Server

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

the class TreeWalker method main.

public static void main(String[] args) throws Exception {
    Server server = Server.builder().setHost("localhost").setPort("1099").build();
    JMXConnector conn = null;
    try {
        conn = server.getServerConnection();
        MBeanServerConnection mbeanServer = conn.getMBeanServerConnection();
        TreeWalker tw = new TreeWalker();
        tw.walkTree(mbeanServer);
    } catch (IOException e) {
        log.error("Problem processing queries for server: " + server.getHost() + ":" + server.getPort(), e);
    } finally {
        if (conn != null) {
            conn.close();
        }
    }
}
Also used : Server(com.googlecode.jmxtrans.model.Server) JMXConnector(javax.management.remote.JMXConnector) IOException(java.io.IOException) MBeanServerConnection(javax.management.MBeanServerConnection)

Example 12 with Server

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

the class TreeWalker2 method main.

/** */
public static void main(String[] args) throws Exception {
    Server server = Server.builder().setHost("localhost").setPort("1099").build();
    JMXConnector conn = null;
    try {
        conn = server.getServerConnection();
        MBeanServerConnection mbeanServer = conn.getMBeanServerConnection();
        TreeWalker2 tw = new TreeWalker2();
        tw.walkTree(mbeanServer, server);
    } catch (IOException e) {
        log.error("Problem processing queries for server: " + server.getHost() + ":" + server.getPort(), e);
    } finally {
        if (conn != null) {
            conn.close();
        }
    }
}
Also used : Server(com.googlecode.jmxtrans.model.Server) JMXConnector(javax.management.remote.JMXConnector) IOException(java.io.IOException) MBeanServerConnection(javax.management.MBeanServerConnection)

Example 13 with Server

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

the class TreeWalker3 method main.

/** */
public static void main(String[] args) throws Exception {
    Server server = Server.builder().setHost("w2").setPort("1105").build();
    JMXConnector conn = null;
    try {
        conn = server.getServerConnection();
        MBeanServerConnection mbeanServer = conn.getMBeanServerConnection();
        TreeWalker3 tw = new TreeWalker3();
        tw.walkTree(mbeanServer, server);
    } catch (IOException e) {
        log.error("Problem processing queries for server: " + server.getHost() + ":" + server.getPort(), e);
    } finally {
        if (conn != null) {
            conn.close();
        }
    }
}
Also used : Server(com.googlecode.jmxtrans.model.Server) JMXConnector(javax.management.remote.JMXConnector) IOException(java.io.IOException) MBeanServerConnection(javax.management.MBeanServerConnection)

Example 14 with Server

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

the class GraphiteWriterFactoryIT method canParseConfigurationFile.

@Test
public void canParseConfigurationFile() throws LifecycleException, URISyntaxException {
    ImmutableList<Server> servers = configurationParser.parseServers(ImmutableList.of(file("/graphite-writer-factory-example.json")), false);
    assertThat(servers).hasSize(1);
    Server server = servers.get(0);
    assertThat(server.getNumQueryThreads()).isEqualTo(2);
    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);
}
Also used : Server(com.googlecode.jmxtrans.model.Server) Query(com.googlecode.jmxtrans.model.Query) OutputWriter(com.googlecode.jmxtrans.model.OutputWriter) ResultTransformerOutputWriter(com.googlecode.jmxtrans.model.output.support.ResultTransformerOutputWriter) IntegrationTest(com.googlecode.jmxtrans.test.IntegrationTest) Test(org.junit.Test)

Example 15 with Server

use of com.googlecode.jmxtrans.model.Server 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)

Aggregations

Server (com.googlecode.jmxtrans.model.Server)22 Test (org.junit.Test)12 Query (com.googlecode.jmxtrans.model.Query)11 ServerFixtures.dummyServer (com.googlecode.jmxtrans.model.ServerFixtures.dummyServer)8 Result (com.googlecode.jmxtrans.model.Result)5 ArrayList (java.util.ArrayList)5 OutputWriter (com.googlecode.jmxtrans.model.OutputWriter)4 MBeanServer (javax.management.MBeanServer)4 ImmutableList (com.google.common.collect.ImmutableList)3 QueryFixtures.dummyQuery (com.googlecode.jmxtrans.model.QueryFixtures.dummyQuery)3 ServerFixtures.serverWithNoQuery (com.googlecode.jmxtrans.model.ServerFixtures.serverWithNoQuery)3 IOException (java.io.IOException)3 MBeanServerConnection (javax.management.MBeanServerConnection)3 JMXConnector (javax.management.remote.JMXConnector)3 LifecycleException (com.googlecode.jmxtrans.exceptions.LifecycleException)2 JmxProcess (com.googlecode.jmxtrans.model.JmxProcess)2 JobDataMap (org.quartz.JobDataMap)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Gson (com.google.gson.Gson)1 Injector (com.google.inject.Injector)1