Search in sources :

Example 6 with Query

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

the class InterestingInfo method main.

// this is an example, no need to make IP addresses configurable
@SuppressWarnings("squid:S1313")
public static void main(String[] args) throws Exception {
    Server.Builder serverBuilder = Server.builder().setHost("w2").setPort("1099").setNumQueryThreads(2);
    Map<String, Object> settings = newHashMap();
    settings.put(GraphiteWriter.HOST, "192.168.192.133");
    settings.put(GraphiteWriter.PORT, 2003);
    GraphiteWriter gw = GraphiteWriter.builder().setHost("192.168.192.133").setPort(2003).build();
    StdOutWriter sw = new StdOutWriter(ImmutableList.<String>of(), false, false, Collections.<String, Object>emptyMap());
    Query q = Query.builder().setObj("java.lang:type=Memory").addAttr("HeapMemoryUsage").addAttr("NonHeapMemoryUsage").addOutputWriterFactories(gw, sw).build();
    serverBuilder.addQuery(q);
    Query q2 = Query.builder().setObj("java.lang:type=Threading").addAttr("DaemonThreadCount").addAttr("PeakThreadCount").addAttr("ThreadCount").addOutputWriterFactories(gw, sw).build();
    serverBuilder.addQuery(q2);
    Query q3 = Query.builder().setObj("java.lang:name=ConcurrentMarkSweep,type=GarbageCollector").addAttr("LastGcInfo").addOutputWriterFactories(gw, sw).build();
    serverBuilder.addQuery(q3);
    Query q4 = Query.builder().setObj("java.lang:name=ParNew,type=GarbageCollector").addAttr("LastGcInfo").addOutputWriterFactories(gw, sw).build();
    serverBuilder.addQuery(q4);
    JmxProcess process = new JmxProcess(serverBuilder.build());
    printer.prettyPrint(process);
    Injector injector = JmxTransModule.createInjector(new JmxTransConfiguration());
    JmxTransformer transformer = injector.getInstance(JmxTransformer.class);
    transformer.executeStandalone(process);
}
Also used : JmxTransConfiguration(com.googlecode.jmxtrans.cli.JmxTransConfiguration) JmxTransformer(com.googlecode.jmxtrans.JmxTransformer) GraphiteWriter(com.googlecode.jmxtrans.model.output.GraphiteWriter) Server(com.googlecode.jmxtrans.model.Server) Query(com.googlecode.jmxtrans.model.Query) Injector(com.google.inject.Injector) JmxProcess(com.googlecode.jmxtrans.model.JmxProcess) StdOutWriter(com.googlecode.jmxtrans.model.output.StdOutWriter)

Example 7 with Query

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

the class TreeWalker3 method walkTree.

public void walkTree(MBeanServerConnection connection, Server server) throws Exception {
    // key here is null, null returns everything!
    Set<ObjectName> mbeans = connection.queryNames(null, null);
    Map<String, String> output = newHashMap();
    for (ObjectName name : mbeans) {
        MBeanInfo info = connection.getMBeanInfo(name);
        MBeanAttributeInfo[] attrs = info.getAttributes();
        Query.Builder queryBuilder = Query.builder().setObj(name.getCanonicalName());
        ResultCapture resultCapture = new ResultCapture();
        queryBuilder.addOutputWriterFactory(resultCapture);
        for (MBeanAttributeInfo attrInfo : attrs) {
            queryBuilder.addAttr(attrInfo.getName());
        }
        Query query = queryBuilder.build();
        try {
            Iterable<Result> results = server.execute(query);
            query.runOutputWritersForQuery(server, results);
        } catch (AttributeNotFoundException anfe) {
            log.error("Error", anfe);
        }
        for (Result result : resultCapture.results) {
            output.put(result.getTypeName(), query.getAttr().toString());
        }
    }
    for (Entry<String, String> entry : output.entrySet()) {
        log.debug(entry.getKey());
        log.debug(entry.getValue());
        log.debug("-----------------------------------------");
    }
}
Also used : AttributeNotFoundException(javax.management.AttributeNotFoundException) MBeanInfo(javax.management.MBeanInfo) Query(com.googlecode.jmxtrans.model.Query) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName) Result(com.googlecode.jmxtrans.model.Result)

Example 8 with Query

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

the class JmxProcessingTests method querySimpleAttribute.

@Test
public void querySimpleAttribute() throws Exception {
    OutputWriterFactory outputWriterFactory = mock(OutputWriterFactory.class);
    OutputWriter outputWriter = mock(OutputWriter.class);
    when(outputWriterFactory.create()).thenReturn(outputWriter);
    Query query = Query.builder().setObj(MBEAN_NAME).addAttr("DummyValue").addOutputWriterFactory(outputWriterFactory).build();
    Server server = localServer();
    Iterable<Result> results1 = server.execute(query);
    query.runOutputWritersForQuery(server, results1);
    verify(outputWriter).doWrite(any(Server.class), queryCaptor.capture(), resultsCaptor.capture());
    assertThat(queryCaptor.getValue()).isEqualTo(query);
    List<Result> results = resultsCaptor.getValue();
    assertThat(results).hasSize(1);
    Result result = results.get(0);
    assertThat(result.getValues().get("DummyValue")).isEqualTo(123);
}
Also used : OutputWriterFactory(com.googlecode.jmxtrans.model.OutputWriterFactory) Query(com.googlecode.jmxtrans.model.Query) MBeanServer(javax.management.MBeanServer) ServerFixtures.localServer(com.googlecode.jmxtrans.model.ServerFixtures.localServer) Server(com.googlecode.jmxtrans.model.Server) OutputWriter(com.googlecode.jmxtrans.model.OutputWriter) Result(com.googlecode.jmxtrans.model.Result) Test(org.junit.Test)

Example 9 with Query

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

the class TreeWalker2 method walkTree.

public void walkTree(MBeanServerConnection connection, Server server) throws Exception {
    // key here is null, null returns everything!
    Set<ObjectName> mbeans = connection.queryNames(null, null);
    for (ObjectName name : mbeans) {
        MBeanInfo info = connection.getMBeanInfo(name);
        MBeanAttributeInfo[] attrs = info.getAttributes();
        Query.Builder queryBuilder = Query.builder().setObj(name.getCanonicalName()).addOutputWriterFactory(new StdOutWriter(ImmutableList.<String>of(), false, false, Collections.<String, Object>emptyMap()));
        for (MBeanAttributeInfo attrInfo : attrs) {
            queryBuilder.addAttr(attrInfo.getName());
        }
        Query query = queryBuilder.build();
        try {
            Iterable<Result> results = server.execute(query);
            query.runOutputWritersForQuery(server, results);
        } catch (AttributeNotFoundException anfe) {
            log.error("Error", anfe);
        }
    }
}
Also used : AttributeNotFoundException(javax.management.AttributeNotFoundException) MBeanInfo(javax.management.MBeanInfo) Query(com.googlecode.jmxtrans.model.Query) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName) StdOutWriter(com.googlecode.jmxtrans.model.output.StdOutWriter) Result(com.googlecode.jmxtrans.model.Result)

Example 10 with Query

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

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