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);
}
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 ");
}
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));
}
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);
}
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);
}
Aggregations