/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

  1. package com.googlecode.jmxtrans.example;
  2. import com.googlecode.jmxtrans.JmxTransformer;
  3. import com.googlecode.jmxtrans.model.JmxProcess;
  4. import com.googlecode.jmxtrans.model.Query;
  5. import com.googlecode.jmxtrans.model.Server;
  6. import com.googlecode.jmxtrans.model.output.GraphiteWriter;
  7. import com.googlecode.jmxtrans.util.BaseOutputWriter;
  8. import com.googlecode.jmxtrans.util.JmxUtils;
  9. /**
  10. * This example shows how to query ehcache for its statistics information.
  11. *
  12. * @author jon
  13. */
  14. public class Ehcache {
  15. private static final String GW_HOST = "192.168.192.133";
  16. /** */
  17. public static void main(String[] args) throws Exception {
  18. Server server = new Server("w2", "1099");
  19. server.setAlias("w2_ehcache_1099");
  20. GraphiteWriter gw = new GraphiteWriter();
  21. gw.addSetting(BaseOutputWriter.HOST, GW_HOST);
  22. gw.addSetting(BaseOutputWriter.PORT, 2003);
  23. // use this to add data to GW path
  24. gw.addTypeName("name");
  25. gw.addSetting(BaseOutputWriter.DEBUG, true);
  26. Query q = new Query();
  27. q.setObj("net.sf.ehcache:CacheManager=net.sf.ehcache.CacheManager@*,name=*,type=CacheStatistics");
  28. q.addAttr("CacheHits");
  29. q.addAttr("InMemoryHits");
  30. q.addAttr("OnDiskHits");
  31. q.addAttr("CacheMisses");
  32. q.addAttr("ObjectCount");
  33. q.addAttr("MemoryStoreObjectCount");
  34. q.addAttr("DiskStoreObjectCount");
  35. // q.addOutputWriter(new StdOutWriter());
  36. q.addOutputWriter(gw);
  37. server.addQuery(q);
  38. JmxProcess process = new JmxProcess(server);
  39. JmxUtils.prettyPrintJson(process);
  40. JmxTransformer transformer = new JmxTransformer();
  41. transformer.executeStandalone(process);
  42. // for (int i = 0; i < 160; i++) {
  43. // JmxUtils.processServer(server);
  44. // Thread.sleep(1000);
  45. // }
  46. }
  47. }