Search in sources :

Example 6 with Server

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

the class ServerListBuilderTest method outputWritersAreReusedOnServers.

@Test
public void outputWritersAreReusedOnServers() {
    Server server1 = Server.builder(dummyServer()).addOutputWriterFactory(new DummyOutputWriterFactory("output 1")).addOutputWriterFactory(new DummyOutputWriterFactory("output 2")).build();
    Server server2 = Server.builder(dummyServer()).addOutputWriterFactory(new DummyOutputWriterFactory("output 1")).addOutputWriterFactory(new DummyOutputWriterFactory("output 3")).build();
    ImmutableList<Server> serverList = new ServerListBuilder().add(ImmutableList.of(server1, server2)).build();
    assertThat(serverList).hasSize(1);
    Server createdServer = serverList.iterator().next();
    assertThat(createdServer.getOutputWriters()).hasSize(3);
}
Also used : ServerFixtures.dummyServer(com.googlecode.jmxtrans.model.ServerFixtures.dummyServer) Server(com.googlecode.jmxtrans.model.Server) Test(org.junit.Test)

Example 7 with Server

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

the class GraphiteWriterTests method checkEmptyTypeNamesAreIgnored.

@Test
public void checkEmptyTypeNamesAreIgnored() throws Exception {
    Server server = serverWithNoQuery();
    // Set useObjDomain to true
    Query query = Query.builder().setUseObjDomainAsKey(true).setAllowDottedKeys(true).setObj("\"yammer.metrics\":name=\"uniqueName\",type=\"\"").build();
    Result result = new Result(System.currentTimeMillis(), "Attribute", "com.yammer.metrics.reporting.JmxReporter$Counter", "yammer.metrics", null, "name=\"uniqueName\",type=\"\"", ImmutableMap.of("Attribute", (Object) 0));
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    ArrayList<String> typeNames = new ArrayList<String>();
    typeNames.add("name");
    typeNames.add("type");
    GraphiteWriter writer = getGraphiteWriter(out, typeNames);
    writer.doWrite(server, query, of(result));
    // check that the empty type "type" is ignored when allowDottedKeys is true
    assertThat(out.toString()).startsWith("servers.host_example_net_4321.yammer.metrics.uniqueName.Attribute 0 ");
    // check that this also works when literal " characters aren't included in the JMX ObjectName
    query = Query.builder().setUseObjDomainAsKey(true).setAllowDottedKeys(true).setObj("yammer.metrics:name=uniqueName,type=").build();
    out = new ByteArrayOutputStream();
    writer = getGraphiteWriter(out, typeNames);
    writer.doWrite(server, query, of(result));
    assertThat(out.toString()).startsWith("servers.host_example_net_4321.yammer.metrics.uniqueName.Attribute 0 ");
    // check that the empty type "type" is ignored when allowDottedKeys is false
    query = Query.builder().setUseObjDomainAsKey(true).setAllowDottedKeys(false).setObj("\"yammer.metrics\":name=\"uniqueName\",type=\"\"").build();
    out = new ByteArrayOutputStream();
    writer = getGraphiteWriter(out, typeNames);
    writer.doWrite(server, query, of(result));
    assertThat(out.toString()).startsWith("servers.host_example_net_4321.yammer_metrics.uniqueName.Attribute 0 ");
}
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) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Result(com.googlecode.jmxtrans.model.Result) ResultFixtures.singleTrueResult(com.googlecode.jmxtrans.model.ResultFixtures.singleTrueResult) ResultFixtures.numericResult(com.googlecode.jmxtrans.model.ResultFixtures.numericResult) ResultFixtures.stringResult(com.googlecode.jmxtrans.model.ResultFixtures.stringResult) Test(org.junit.Test)

Example 8 with Server

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

the class ElasticWriterTests method sendMessageToElasticAndVerify.

@Test
public void sendMessageToElasticAndVerify() throws Exception {
    Server serverWithKnownValues = serverWithAliasAndNoQuery();
    int epoch = 1123455;
    String attributeName = "attributeName123";
    String className = "className123";
    String objDomain = "objDomain123";
    String classNameAlias = "classNameAlias123";
    String typeName = "typeName123";
    String key = "myKey";
    int value = 1122;
    Result resultWithKnownValues = new Result(epoch, attributeName, className, objDomain, classNameAlias, typeName, ImmutableMap.of(key, (Object) value));
    ArgumentCaptor<Index> argument = ArgumentCaptor.forClass(Index.class);
    // return for call, add index entry
    when(mockClient.execute(isA(Index.class))).thenReturn(jestResultTrue);
    writer.doWrite(serverWithKnownValues, dummyQuery(), ImmutableList.of(resultWithKnownValues));
    verify(mockClient).execute(argument.capture());
    assertEquals(PREFIX + "_jmx-entries", argument.getValue().getIndex());
    Gson gson = new Gson();
    String data = argument.getValue().getData(gson);
    assertTrue("Contains host", data.contains(DEFAULT_HOST));
    assertTrue("Contains port", data.contains(DEFAULT_PORT));
    assertTrue("Contains attribute name", data.contains(attributeName));
    assertTrue("Contains class name", data.contains(className));
    assertTrue("Contains object domain", data.contains(objDomain));
    assertTrue("Contains classNameAlias", data.contains(classNameAlias));
    assertTrue("Contains type name", data.contains(typeName));
    assertTrue("Contains timestamp", data.contains(String.valueOf(epoch)));
    assertTrue("Contains key", data.contains(key));
    assertTrue("Contains value", data.contains(String.valueOf(value)));
    assertTrue("Contains serverAlias", data.contains(SERVER_ALIAS));
}
Also used : ServerFixtures.dummyServer(com.googlecode.jmxtrans.model.ServerFixtures.dummyServer) Server(com.googlecode.jmxtrans.model.Server) Gson(com.google.gson.Gson) Index(io.searchbox.core.Index) Result(com.googlecode.jmxtrans.model.Result) JestResult(io.searchbox.client.JestResult) DocumentResult(io.searchbox.core.DocumentResult) Test(org.junit.Test)

Example 9 with Server

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

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

the class Tester method main.

/** */
public static void main(String[] args) throws Exception {
    Server server = Server.builder().setHost("w2").setPort("1099").setNumQueryThreads(2).addQuery(Query.builder().setObj("java.lang:type=Memory").addAttr("HeapMemoryUsage", "NonHeapMemoryUsage").addOutputWriterFactory(new StdOutWriter(ImmutableList.<String>of(), false, false, Collections.<String, Object>emptyMap())).build()).addQuery(Query.builder().setObj("java.lang:name=CMS Old Gen,type=MemoryPool").addAttr("Usage").addOutputWriterFactory(new StdOutWriter(ImmutableList.<String>of(), false, false, Collections.<String, Object>emptyMap())).build()).addQuery(Query.builder().setObj("java.lang:name=ConcurrentMarkSweep,type=GarbageCollector").addAttr("LastGcInfo").addOutputWriterFactory(new StdOutWriter(ImmutableList.<String>of(), false, false, Collections.<String, Object>emptyMap())).build()).build();
    JmxProcess process = new JmxProcess(server);
    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) Server(com.googlecode.jmxtrans.model.Server) Injector(com.google.inject.Injector) JmxProcess(com.googlecode.jmxtrans.model.JmxProcess) StdOutWriter(com.googlecode.jmxtrans.model.output.StdOutWriter)

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