use of com.googlecode.jmxtrans.model.Query in project jmxtrans by jmxtrans.
the class ConfigurationParserTest method testMerge.
@Test
public void testMerge() throws Exception {
Query q1 = Query.builder().setObj("obj:key=val").addAttr("foo").addAttr("bar").addKey("key1").addKey("key2").setResultAlias("alias").build();
// same as q1
Query q2 = Query.builder().setObj("obj:key=val").addAttr("foo").addAttr("bar").addKey("key1").addKey("key2").setResultAlias("alias").build();
// different than q1 and q2
Query q3 = Query.builder().setObj("obj3:key=val").addAttr("foo").addAttr("bar").addKey("key1").addKey("key2").setResultAlias("alias").build();
Server s1 = Server.builder().setAlias("alias").setHost("host").setPort("8004").setPool(createPool()).setCronExpression("cron").setNumQueryThreads(123).setPassword("pass").setUsername("user").addQuery(q1).addQuery(q2).build();
// same as s1
Server s2 = Server.builder().setAlias("alias").setHost("host").setPort("8004").setPool(createPool()).setCronExpression("cron").setNumQueryThreads(123).setPassword("pass").setUsername("user").addQuery(q1).addQuery(q2).build();
Server s3 = Server.builder().setAlias("alias").setHost("host3").setPort("8004").setPool(createPool()).setCronExpression("cron").setNumQueryThreads(123).setPassword("pass").setUsername("user").addQuery(q1).addQuery(q2).addQuery(q3).build();
List<Server> existing = new ArrayList<Server>();
existing.add(s1);
List<Server> adding = new ArrayList<Server>();
adding.add(s2);
existing = configurationParser.mergeServerLists(existing, adding);
// should only have one server with 1 query since we just added the same
// server and same query.
assertThat(existing).hasSize(1);
assertThat(existing.get(0).getQueries()).hasSize(1);
adding.add(s3);
existing = configurationParser.mergeServerLists(existing, adding);
assertThat(existing).hasSize(2);
assertThat(existing.get(0).getQueries()).hasSize(1);
assertThat(existing.get(1).getQueries()).hasSize(2);
}
use of com.googlecode.jmxtrans.model.Query in project jmxtrans by jmxtrans.
the class BaseOutputWriterTests method booleanValuesAreNotTransformedToNumber.
@Test
public void booleanValuesAreNotTransformedToNumber() throws Exception {
final ArrayList<Result> processedResults = Lists.newArrayList();
BaseOutputWriter outputWriter = new BaseOutputWriter(ImmutableList.<String>of(), false, 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(true);
assertThat(processedResult.getValues().get("false")).isEqualTo(false);
}
use of com.googlecode.jmxtrans.model.Query in project jmxtrans by jmxtrans.
the class JsonUtilsTest method loadFromFile.
private void loadFromFile(String file) throws URISyntaxException, IOException, MalformedObjectNameException {
File input = new File(JsonUtilsTest.class.getResource("/" + file).toURI());
JmxProcess process = jsonUtils.parseProcess(input);
assertThat(process.getName()).isEqualTo(file);
Server server = process.getServers().get(0);
assertThat(server.getPort()).isEqualTo("1099");
assertThat(server.getNumQueryThreads()).isEqualTo(2);
Optional<Query> queryOptional = from(server.getQueries()).firstMatch(new ByObj("java.lang:type=Memory"));
assertThat(queryOptional.isPresent()).isTrue();
assertThat(queryOptional.get().getAttr().get(0)).isEqualTo("HeapMemoryUsage");
}
use of com.googlecode.jmxtrans.model.Query in project jmxtrans by jmxtrans.
the class ActiveMQ method main.
public static void main(String[] args) throws Exception {
Server.Builder serverBuilder = Server.builder().setHost("w2").setPort("1105").setAlias("w2_activemq_1105");
GraphiteWriter gw = GraphiteWriter.builder().addTypeName("destinationName").addTypeName("Destination").setDebugEnabled(true).setHost(GW_HOST).setPort(2003).build();
Query q = Query.builder().setObj("org.apache.activemq:BrokerName=localhost,Type=Subscription,clientId=*,consumerId=*,destinationName=*,destinationType=Queue,persistentMode=Non-Durable").addAttr("PendingQueueSize").addAttr("DispatchedQueueSize").addAttr("EnqueueCounter").addAttr("DequeueCounter").addAttr("MessageCountAwaitingAcknowledge").addAttr("DispachedCounter").addOutputWriterFactory(gw).build();
serverBuilder.addQuery(q);
Query q2 = Query.builder().setObj("org.apache.activemq:BrokerName=localhost,Destination=ActiveMQ.Advisory.Consumer.Queue.*,Type=Topic").addAttr("QueueSize").addAttr("MaxEnqueueTime").addAttr("MinEnqueueTime").addAttr("AverageEnqueueTime").addAttr("InFlightCount").addAttr("ConsumerCount").addAttr("ProducerCount").addAttr("DispatchCount").addAttr("DequeueCount").addAttr("EnqueueCount").addAttr("Subscriptions").addOutputWriterFactory(gw).build();
serverBuilder.addQuery(q2);
Query q3 = Query.builder().setObj("org.apache.activemq:BrokerName=localhost,Destination=*,Type=Queue").addAttr("QueueSize").addAttr("MaxEnqueueTime").addAttr("MinEnqueueTime").addAttr("AverageEnqueueTime").addAttr("InFlightCount").addAttr("ConsumerCount").addAttr("ProducerCount").addAttr("DispatchCount").addAttr("DequeueCount").addAttr("EnqueueCount").addAttr("Subscriptions").addOutputWriterFactory(gw).build();
serverBuilder.addQuery(q3);
Query q4 = Query.builder().setObj("org.apache.activemq:BrokerName=localhost,Destination=*,Type=Topic").addAttr("QueueSize").addAttr("MaxEnqueueTime").addAttr("MinEnqueueTime").addAttr("AverageEnqueueTime").addAttr("InFlightCount").addAttr("ConsumerCount").addAttr("ProducerCount").addAttr("DispatchCount").addAttr("DequeueCount").addAttr("EnqueueCount").addAttr("Subscriptions").addOutputWriterFactory(gw).build();
serverBuilder.addQuery(q4);
Query q5 = Query.builder().setObj("org.apache.activemq:BrokerName=localhost,Type=Broker").addOutputWriterFactory(gw).build();
serverBuilder.addQuery(q5);
Query q6 = Query.builder().setObj("java.lang:type=Memory").addAttr("HeapMemoryUsage").addAttr("NonHeapMemoryUsage").addOutputWriterFactory(gw).build();
serverBuilder.addQuery(q6);
Query q7 = Query.builder().setObj("java.lang:type=Threading").addAttr("DaemonThreadCount").addAttr("PeakThreadCount").addAttr("ThreadCount").addAttr("CurrentThreadCpuTime").addAttr("CurrentThreadUserTime").addAttr("TotalStartedThreadCount").addOutputWriterFactory(gw).build();
serverBuilder.addQuery(q7);
Query q8 = Query.builder().setObj("java.lang:name=*,type=GarbageCollector").addKey("committed").addKey("init").addKey("max").addKey("used").addKey("duration").addKey("CollectionCount").addKey("CollectionTime").addOutputWriterFactory(gw).build();
serverBuilder.addQuery(q8);
Query q9 = Query.builder().setObj("java.lang:type=MemoryPool,name=*").addOutputWriterFactory(GraphiteWriter.builder().addTypeName("name").setDebugEnabled(true).setHost(GW_HOST).setPort(2003).build()).build();
serverBuilder.addQuery(q9);
JmxProcess process = new JmxProcess(serverBuilder.build());
new JsonPrinter(System.out).prettyPrint(process);
Injector injector = JmxTransModule.createInjector(new JmxTransConfiguration());
JmxTransformer transformer = injector.getInstance(JmxTransformer.class);
transformer.executeStandalone(process);
}
use of com.googlecode.jmxtrans.model.Query 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 ");
}
Aggregations