tomcat jmx 소스
JMX 소스
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
import javax.management.MBeanServerConnection; import javax.management.ObjectName; import javax.management.openmbean.CompositeData; import javax.management.remote.JMXConnector; import javax.management.remote.JMXConnectorFactory; import javax.management.remote.JMXServiceURL; import java.io.Console; public class check_jmx { public static final char ESC = 27; public static void main(String[] args) { // TODO Auto-generated method stub try { // Create an RMI connector client and // connect it to the RMI connector server // JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://127.0.0.1:9999/jmxrmi"); JMXConnector jmxc = JMXConnectorFactory.connect(url, null); MBeanServerConnection mbsc = jmxc.getMBeanServerConnection(); ObjectName tomcatThreadPoolObh = new ObjectName("Catalina:type=Executor,name=tomcatThreadPool"); Object activeCnt = mbsc.getAttribute(tomcatThreadPoolObh, "activeCount"); ObjectName memoryObh = new ObjectName("java.lang:type=Memory"); CompositeData memoryRes = (CompositeData) mbsc.getAttribute(memoryObh, "HeapMemoryUsage"); Console c = System.console(); if (c == null) { System.err.println("no console"); System.exit(1); } // clear screen only the first time c.writer().print(ESC + "[2J"); c.flush(); Thread.sleep(200); for (int i = 0; i < 100000; ++i) { // reposition the cursor to 1|1 c.writer().print(ESC + "[1;1H"); c.flush(); //c.writer().println("hello " + i); c.writer().println("activeCount = " + activeCnt); c.writer().println("HeapMemoryUsage committed = " + memoryRes.get("committed")); c.writer().println("HeapMemoryUsage init = " + memoryRes.get("init")); c.writer().println("HeapMemoryUsage max = " + memoryRes.get("max")); c.writer().println("HeapMemoryUsage used = " + memoryRes.get("used")); c.flush(); Thread.sleep(5000); } /* echo("activeCount = " + activeCnt); echo("HeapMemoryUsage committed = " + memoryRes.get("committed")); echo("HeapMemoryUsage init = " + memoryRes.get("init")); echo("HeapMemoryUsage max = " + memoryRes.get("max")); echo("HeapMemoryUsage used = " + memoryRes.get("used")); */ jmxc.close(); } catch (Exception e) { e.printStackTrace(); } } private static void echo(String msg) { System.out.println(msg); } } |