PageRenderTime 23ms CodeModel.GetById 13ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/src/com/googlecode/jmxtrans/example/ActiveMQ.java

http://jmxtrans.googlecode.com/
Java | 155 lines | 119 code | 20 blank | 16 comment | 0 complexity | 0fdf5419741ac49aa3401c118a813bb9 MD5 | raw file
  1package com.googlecode.jmxtrans.example;
  2
  3import com.googlecode.jmxtrans.JmxTransformer;
  4import com.googlecode.jmxtrans.model.JmxProcess;
  5import com.googlecode.jmxtrans.model.Query;
  6import com.googlecode.jmxtrans.model.Server;
  7import com.googlecode.jmxtrans.model.output.GraphiteWriter;
  8import com.googlecode.jmxtrans.util.BaseOutputWriter;
  9import com.googlecode.jmxtrans.util.JmxUtils;
 10
 11/**
 12 * This example shows how to query an ActiveMQ server for some information.
 13 *
 14 * The point of this example is to show that * works as part of the objectName.
 15 * It also shows that you don't have to set an attribute to get for a query.
 16 * jmxtrans will get all attributes on an object if you don't specify any.
 17 *
 18 * @author jon
 19 */
 20public class ActiveMQ {
 21
 22	private static final String GW_HOST = "192.168.192.133";
 23
 24	/** */
 25	public static void main(String[] args) throws Exception {
 26
 27		Server server = new Server("w2", "1105");
 28		server.setAlias("w2_activemq_1105");
 29		GraphiteWriter gw = new GraphiteWriter();
 30		gw.addSetting(BaseOutputWriter.HOST, GW_HOST);
 31//        gw.addSetting(GraphiteWriter.HOST, "localhost");
 32		gw.addSetting(BaseOutputWriter.PORT, 2003);
 33
 34		// use this to add data to GW path
 35		gw.addTypeName("destinationName");
 36		gw.addTypeName("Destination");
 37		gw.addSetting(BaseOutputWriter.DEBUG, true);
 38
 39		Query q = new Query();
 40		q.setObj("org.apache.activemq:BrokerName=localhost,Type=Subscription,clientId=*,consumerId=*,destinationName=*,destinationType=Queue,persistentMode=Non-Durable");
 41		q.addAttr("PendingQueueSize");
 42		q.addAttr("DispatchedQueueSize");
 43		q.addAttr("EnqueueCounter");
 44		q.addAttr("DequeueCounter");
 45		q.addAttr("MessageCountAwaitingAcknowledge");
 46		q.addAttr("DispachedCounter");
 47		q.addOutputWriter(gw);
 48		server.addQuery(q);
 49
 50		Query q2 = new Query();
 51		q2.setObj("org.apache.activemq:BrokerName=localhost,Destination=ActiveMQ.Advisory.Consumer.Queue.*,Type=Topic");
 52		q2.addAttr("QueueSize");
 53		q2.addAttr("MaxEnqueueTime");
 54		q2.addAttr("MinEnqueueTime");
 55		q2.addAttr("AverageEnqueueTime");
 56		q2.addAttr("InFlightCount");
 57		q2.addAttr("ConsumerCount");
 58		q2.addAttr("ProducerCount");
 59		q2.addAttr("DispatchCount");
 60		q2.addAttr("DequeueCount");
 61		q2.addAttr("EnqueueCount");
 62		q2.addAttr("Subscriptions");
 63		q2.addOutputWriter(gw);
 64		server.addQuery(q2);
 65
 66		Query q3 = new Query();
 67		q3.setObj("org.apache.activemq:BrokerName=localhost,Destination=*,Type=Queue");
 68		q3.addAttr("QueueSize");
 69		q3.addAttr("MaxEnqueueTime");
 70		q3.addAttr("MinEnqueueTime");
 71		q3.addAttr("AverageEnqueueTime");
 72		q3.addAttr("InFlightCount");
 73		q3.addAttr("ConsumerCount");
 74		q3.addAttr("ProducerCount");
 75		q3.addAttr("DispatchCount");
 76		q3.addAttr("DequeueCount");
 77		q3.addAttr("EnqueueCount");
 78		q3.addAttr("Subscriptions");
 79		q3.addOutputWriter(gw);
 80		server.addQuery(q3);
 81
 82		Query q4 = new Query();
 83		q4.setObj("org.apache.activemq:BrokerName=localhost,Destination=*,Type=Topic");
 84		q4.addAttr("QueueSize");
 85		q4.addAttr("MaxEnqueueTime");
 86		q4.addAttr("MinEnqueueTime");
 87		q4.addAttr("AverageEnqueueTime");
 88		q4.addAttr("InFlightCount");
 89		q4.addAttr("ConsumerCount");
 90		q4.addAttr("ProducerCount");
 91		q4.addAttr("DispatchCount");
 92		q4.addAttr("DequeueCount");
 93		q4.addAttr("EnqueueCount");
 94		q4.addAttr("Subscriptions");
 95		q4.addOutputWriter(gw);
 96		server.addQuery(q4);
 97
 98		Query q5 = new Query();
 99		q5.setObj("org.apache.activemq:BrokerName=localhost,Type=Broker");
100		q5.addOutputWriter(gw);
101		server.addQuery(q5);
102
103		Query q6 = new Query();
104		q6.setObj("java.lang:type=Memory");
105		q6.addAttr("HeapMemoryUsage");
106		q6.addAttr("NonHeapMemoryUsage");
107		q6.addOutputWriter(gw);
108		server.addQuery(q6);
109
110		Query q7 = new Query("java.lang:type=Threading");
111		q7.addAttr("DaemonThreadCount");
112		q7.addAttr("PeakThreadCount");
113		q7.addAttr("ThreadCount");
114		q7.addAttr("CurrentThreadCpuTime");
115		q7.addAttr("CurrentThreadUserTime");
116		q7.addAttr("TotalStartedThreadCount");
117		q7.addOutputWriter(gw);
118		server.addQuery(q7);
119
120		Query q8 = new Query();
121		q8.setObj("java.lang:name=*,type=GarbageCollector");
122		q8.addKey("committed");
123		q8.addKey("init");
124		q8.addKey("max");
125		q8.addKey("used");
126		q8.addKey("duration");
127		q8.addKey("CollectionCount");
128		q8.addKey("CollectionTime");
129		q8.addOutputWriter(gw);
130		server.addQuery(q8);
131
132		GraphiteWriter gw2 = new GraphiteWriter();
133		gw2.addSetting(BaseOutputWriter.HOST, GW_HOST);
134		gw2.addSetting(BaseOutputWriter.PORT, 2003);
135
136		gw2.addTypeName("name");
137		gw2.addSetting(BaseOutputWriter.DEBUG, true);
138
139		Query q9 = new Query();
140		q9.setObj("java.lang:type=MemoryPool,name=*");
141		q9.addOutputWriter(gw2);
142		server.addQuery(q9);
143
144		JmxProcess process = new JmxProcess(server);
145		JmxUtils.prettyPrintJson(process);
146        JmxTransformer transformer = new JmxTransformer();
147        transformer.executeStandalone(process);
148
149//        for (int i = 0; i < 160; i++) {
150//            JmxUtils.processServer(server);
151//            Thread.sleep(1000);
152//        }
153
154	}
155}