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

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

http://jmxtrans.googlecode.com/
Java | 59 lines | 35 code | 12 blank | 12 comment | 0 complexity | ef64da6aa0ea8e12d334bd4dfb368e64 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 ehcache for its statistics information.
13 *
14 * @author jon
15 */
16public class Ehcache {
17
18	private static final String GW_HOST = "192.168.192.133";
19
20	/** */
21	public static void main(String[] args) throws Exception {
22
23		Server server = new Server("w2", "1099");
24		server.setAlias("w2_ehcache_1099");
25		GraphiteWriter gw = new GraphiteWriter();
26		gw.addSetting(BaseOutputWriter.HOST, GW_HOST);
27		gw.addSetting(BaseOutputWriter.PORT, 2003);
28
29		// use this to add data to GW path
30		gw.addTypeName("name");
31
32		gw.addSetting(BaseOutputWriter.DEBUG, true);
33
34		Query q = new Query();
35		q.setObj("net.sf.ehcache:CacheManager=net.sf.ehcache.CacheManager@*,name=*,type=CacheStatistics");
36		q.addAttr("CacheHits");
37		q.addAttr("InMemoryHits");
38		q.addAttr("OnDiskHits");
39		q.addAttr("CacheMisses");
40		q.addAttr("ObjectCount");
41		q.addAttr("MemoryStoreObjectCount");
42		q.addAttr("DiskStoreObjectCount");
43//        q.addOutputWriter(new StdOutWriter());
44		q.addOutputWriter(gw);
45		server.addQuery(q);
46
47		JmxProcess process = new JmxProcess(server);
48		JmxUtils.prettyPrintJson(process);
49
50		JmxTransformer transformer = new JmxTransformer();
51        transformer.executeStandalone(process);
52
53//        for (int i = 0; i < 160; i++) {
54//            JmxUtils.processServer(server);
55//            Thread.sleep(1000);
56//        }
57
58	}
59}