{"id":13035,"date":"2016-12-13T09:00:56","date_gmt":"2016-12-13T00:00:56","guid":{"rendered":"http:\/\/www.techscore.com\/blog\/?p=13035"},"modified":"2018-11-14T16:33:44","modified_gmt":"2018-11-14T07:33:44","slug":"%e3%83%aa%e3%83%a2%e3%83%bc%e3%83%88%e3%82%b5%e3%83%bc%e3%83%90%e3%81%aejava%e3%83%97%e3%83%ad%e3%82%bb%e3%82%b9%e3%82%92jconsole%e3%81%a7%e8%a6%97%e3%81%8f","status":"publish","type":"post","link":"https:\/\/www.techscore.com\/blog\/2016\/12\/13\/%e3%83%aa%e3%83%a2%e3%83%bc%e3%83%88%e3%82%b5%e3%83%bc%e3%83%90%e3%81%aejava%e3%83%97%e3%83%ad%e3%82%bb%e3%82%b9%e3%82%92jconsole%e3%81%a7%e8%a6%97%e3%81%8f\/","title":{"rendered":"\u30ea\u30e2\u30fc\u30c8\u30b5\u30fc\u30d0\u306eJava\u30d7\u30ed\u30bb\u30b9\u3092JConsole\u3067\u8997\u304f"},"content":{"rendered":"
\u3053\u3093\u306b\u3061\u306f\u3002\u5bfa\u5ca1\u3067\u3059\u3002 JConsole\u3092\u4f7f\u3046\u3068\u3001CPU\u3084\u30e1\u30e2\u30ea\u306e\u30e1\u30c8\u30ea\u30af\u30b9\u3001JMX\u306eMBean\u3092\u4f7f\u3063\u305f\u30ab\u30b9\u30bf\u30e0\u30e1\u30c8\u30ea\u30af\u30b9\u306e\u53d6\u5f97\u3084\u7ba1\u7406\u7cfb\u306e\u64cd\u4f5c\u3092\u547c\u3073\u51fa\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002 GC\u3092\u547c\u3073\u51fa\u3057\u305f\u308a\u3001Tomcat\u306e\u30bb\u30c3\u30b7\u30e7\u30f3\u60c5\u5831\u3092\u8997\u3044\u305f\u308a\u2026\u2026\u308f\u308a\u3068\u306a\u3093\u3067\u3082\u3067\u304d\u3066\u3057\u307e\u3044\u307e\u3059\u3002<\/p>\n JConsole\u306e\u5229\u7528\u6642\u306f\u3001\u5bfe\u8c61\u306eJava\u30d7\u30ed\u30bb\u30b9\u5185\u3067JMX Server\u304c\u8d77\u52d5\u3057\u3066\u3044\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002 Java\u306b\u306f Attach API<\/a> \u3068\u3044\u3046\u6a5f\u80fd\u304c\u3042\u308a\u3001\u30ed\u30fc\u30ab\u30eb\u30de\u30b7\u30f3\u3067\u8d77\u52d5\u3057\u3066\u3044\u308bJVM\u306e\u60c5\u5831\u3092\u53d6\u5f97\u3057\u305f\u308a\u3001Instrumentation API\u3092\u4f7f\u3063\u305fJava\u30a8\u30fc\u30b8\u30a7\u30f3\u30c8\u3092\u30aa\u30f3\u30c7\u30de\u30f3\u30c9\u3067\u30ed\u30fc\u30c9\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002 Attach API\u306e\u30a8\u30fc\u30b8\u30a7\u30f3\u30c8 \u30aa\u30f3\u30c7\u30de\u30f3\u30c9\u30ed\u30fc\u30c9\u3092\u4f7f\u3044\u3001\u7a3c\u50cd\u4e2d\u306eJava\u30d7\u30ed\u30bb\u30b9\u5185\u306bJMX Server\u3092\u8d77\u52d5\u3055\u305b\u308b\u3053\u3068\u3067\u3001JMX\u306e\u8a2d\u5b9a\u3092\u3057\u3066\u3044\u306a\u3044JVM\u30d7\u30ed\u30bb\u30b9\u306b\u3082JConsole\u3067\u63a5\u7d9a\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n JConsole\u3067\u63a5\u7d9a\u3057\u305f\u3044JVM\u30d7\u30ed\u30bb\u30b9\u304c\u8d77\u52d5\u3057\u3066\u3044\u308b\u30b5\u30fc\u30d0\u3067\u3001\u304a\u3082\u3080\u308d\u306b\u30a8\u30c7\u30a3\u30bf\u3092\u958b\u3044\u3066\u3053\u3093\u306aJava\u30d5\u30a1\u30a4\u30eb\u3092\u7528\u610f\u3057\u307e\u3059\u3002<\/p>\n \u4e0a\u8a18\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u305f\u3089\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u30b3\u30f3\u30d1\u30a4\u30eb\u3057\u5b9f\u884c\u3057\u307e\u3059\u3002<\/p>\n \u5b9f\u884c\u3059\u308b\u3068\u3001\u2193\u3053\u3093\u306a\u611f\u3058\u306eURL\u304c\u8868\u793a\u3055\u308c\u308b\u3068\u601d\u3046\u306e\u3067\u3001\u30af\u30ea\u30c3\u30d7\u30dc\u30fc\u30c9\u306b\u30b3\u30d4\u30fc\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n service:jmx:rmi:\/\/127.0.0.1\/stub\/\u306a\u304c\u30fc\u3044\u6587\u5b57\u5217<\/p>\n \u3053\u308c\u3067\u5bfe\u8c61\u30b5\u30fc\u30d0\u3067JMX\u306e\u30ea\u30e2\u30fc\u30c8\u63a5\u7d9a\u3092\u53d7\u3051\u4ed8\u3051\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002 \u305d\u3053\u3067\u3001SSH\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u306eSocks\u30d7\u30ed\u30ad\u30b7\u3092\u5229\u7528\u3057\u3066\u30ea\u30e2\u30fc\u30c8\u304b\u3089\u306e\u63a5\u7d9a\u3092\u884c\u3044\u307e\u3059\u3002 JConsole\u306e\u753b\u9762\u304c\u958b\u304f\u306e\u3067\u3001\u300c\u30ea\u30e2\u30fc\u30c8\u30d7\u30ed\u30bb\u30b9\u300d\u3092\u9078\u629e\u3057\u3066\u3001\u5148\u307b\u3069\u30b3\u30d4\u30fc\u3057\u305fURL\u3092\u30da\u30fc\u30b9\u30c8\u3057\u3001\u300c\u63a5\u7d9a\u300d\u30dc\u30bf\u30f3\u3092\u30af\u30ea\u30c3\u30af\u3057\u307e\u3059\u3002<\/p>\n \u30e1\u30c8\u30ea\u30af\u30b9\u3092\u898b\u308b\u306a\u308a\u3001\u30b9\u30ec\u30c3\u30c9\u306e\u30b9\u30bf\u30c3\u30af\u3092\u8997\u304f\u306a\u308a\u3001GC\u5b9f\u884c\u3059\u308b\u306a\u308a\u2026\u2026\u8272\u3005\u3067\u304d\u3061\u3083\u3044\u307e\u3059\uff01\uff01 \u3053\u3093\u306b\u3061\u306f\u3002\u5bfa\u5ca1\u3067\u3059\u3002
\n\u3053\u306e\u8a18\u4e8b\u306f TECHSCORE Advent Calendar 2016<\/a> \u306e 13 \u65e5\u76ee\u306e\u8a18\u4e8b\u3067\u3059\u3002<\/p>\nJConsole \u4f7f\u3063\u3066\u307e\u3059\u304b\uff1f<\/h2>\n
\nJMX\u306fJSR3<\/a>\u3068\u3044\u3046\u6b74\u53f2\u3092\u611f\u3058\u3055\u305b\u308b\u4ed5\u69d8\u3060\u3051\u3042\u3063\u3066\u3001\u65e2\u5b58\u306e\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3084\u30e9\u30a4\u30d6\u30e9\u30ea\u306b\u3082\u591a\u304f\u63a1\u7528\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n
\n\u30ed\u30fc\u30ab\u30eb\u74b0\u5883\u3084\u3042\u3089\u304b\u3058\u3081\u8d77\u52d5\u30aa\u30d7\u30b7\u30e7\u30f3\u3067JMX Server\u306e\u8a2d\u5b9a<\/a>\u3092\u3057\u3066\u3044\u308b\u5834\u5408\u3001JConsole\u3092\u7acb\u3061\u4e0a\u3052\u3066\u63a5\u7d9a\u5148\u3092\u9078\u629e\u3059\u308b\u3060\u3051\u3067OK\u3067\u3059\u3002
\n\u4eca\u56de\u306f\u3001\u4f55\u306e\u6e96\u5099\u3082\u3057\u3066\u3044\u306a\u3044\u30b5\u30fc\u30d0\u306b\u5bfe\u3057\u3066\u30ea\u30e2\u30fc\u30c8\u304b\u3089JConsole\u3067\u63a5\u7d9a\u3059\u308b\u307e\u3067\u306e\u624b\u9806\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n\u305d\u306e\u524d\u306b\u3001\u3061\u3087\u3063\u3068\u3060\u3051Attach API\u306e\u8a71<\/h2>\n
\n\u3042\u307e\u308a\u805e\u304d\u6163\u308c\u306a\u3044API\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u304c\u3001jstack\u306e\u3088\u3046\u306a\u30b3\u30de\u30f3\u30c9\u306f\u5185\u90e8\u3067Attach API\u3092\u5229\u7528\u3057\u3066\u3044\u305f\u308a\u3057\u307e\u3059\u3002<\/p>\n\u5177\u4f53\u7684\u306a\u65b9\u6cd5<\/h2>\n
\r\n\r\nimport java.io.File;\r\nimport com.sun.tools.attach.VirtualMachine;\r\n\r\npublic class JMXAgentLoader {\r\n public static void main(String [] pids) {\r\n for (String pid: pids){\r\n try {\r\n String key = \"com.sun.management.jmxremote.localConnectorAddress\";\r\n VirtualMachine vm = VirtualMachine.attach(pid);\r\n String connectorAddress = vm.getAgentProperties().getProperty(key);\r\n if (connectorAddress == null) {\r\n String agent = vm.getSystemProperties().getProperty(\"java.home\") + File.separator + \"lib\" + File.separator + \"management-agent.jar\";\r\n vm.loadAgent(agent);\r\n connectorAddress = vm.getAgentProperties().getProperty(key);\r\n }\r\n System.out.print(\"pid: \" + pid);\r\n System.out.println(\" connectorAddress: \" + connectorAddress);\r\n vm.detach();\r\n } catch (Exception e) {\r\n e.printStackTrace();\r\n }\r\n }\r\n }\r\n}\r\n<\/pre>\n
\r\n# JMXAgentLoader\u3092\u30b3\u30f3\u30d1\u30a4\u30eb \r\njavac -cp ${JAVA_HOME}\/lib\/tools.jar JMXAgentLoader.java \r\n\r\n# jps\u306a\u3069\u3067\u5bfe\u8c61\u306eJava\u30d7\u30ed\u30bb\u30b9\u306ePID\u3092\u78ba\u8a8d \r\njps \r\n\r\n# \u30b3\u30f3\u30d1\u30a4\u30eb\u3057\u305fJava\u30d5\u30a1\u30a4\u30eb\u3092\u5b9f\u884c\u3057\u3066JMXServer\u306e\u30a2\u30c9\u30ec\u30b9\u3092\u53d6\u5f97 \r\njava -cp \".:${JAVA_HOME}\/lib\/tools.jar\" JMXAgentLoader {JAVA\u30d7\u30ed\u30bb\u30b9\u306ePID} \r\n<\/pre>\n
\n\u3057\u304b\u3057\u3001\u30eb\u30fc\u30d7\u30d0\u30c3\u30af\u30a2\u30c9\u30ec\u30b9\u3067\u3042\u308b127.0.0.1\u3078\u306e\u63a5\u7d9a\u3057\u304b\u53d7\u3051\u4ed8\u3051\u3066\u3044\u306a\u3044\u305f\u3081\u3001\u5916\u90e8\u304b\u3089\u63a5\u7d9a\u3059\u308b\u3053\u3068\u306f\u3067\u304d\u307e\u305b\u3093\u3002<\/p>\n
\n\u4ee5\u964d\u306fJConsole\u3092\u8d77\u52d5\u3059\u308b\u74b0\u5883\u3067\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\u3002\uff08JConsole\u306fGUI\u304c\u5229\u7528\u53ef\u80fd\u306a\u74b0\u5883\u3067\u8d77\u52d5\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\uff09<\/p>\n\r\n# socks\u30d7\u30ed\u30ad\u30b7(7777\u3067\u30ea\u30c3\u30b9\u30f3)\u3092\u6709\u52b9\u306b\u3057\u3066\u30d0\u30c3\u30af\u30b0\u30e9\u30a6\u30f3\u30c9\u3067SSH\u63a5\u7d9a\u3092\u958b\u304f \r\nssh -fN -D 7777 {\u5bfe\u8c61\u30b5\u30fc\u30d0} \r\n\r\n# socks\u30d7\u30ed\u30ad\u30b7\u3092\u6307\u5b9a\u3057\u3066jconsole\u3092\u8d77\u52d5\r\njconsole -J-DsocksProxyHost=localhost -J-DsocksProxyPort=7777\r\n<\/pre>\n
\n\u5168\u90e8\u7d42\u308f\u3063\u305f\u3089Proxy\u306b\u4f7f\u3063\u3066\u3044\u308b\u30d0\u30c3\u30af\u30b0\u30e9\u30a6\u30f3\u30c9\u306essh\u30d7\u30ed\u30bb\u30b9\u3092kill\u3059\u308b\u306e\u3092\u5fd8\u308c\u306a\u3044\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"
\n\u3053\u306e\u8a18\u4e8b\u306f TECHSCORE Advent Calendar 2016 \u306e 13 \u65e5\u76ee\u306e\u8a18\u4e8b\u3067\u3059\u3002
\u7d9a\u304d\u3092\u8aad\u3080...<\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[239,18],"tags":[141,57],"_links":{"self":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/13035"}],"collection":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/comments?post=13035"}],"version-history":[{"count":10,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/13035\/revisions"}],"predecessor-version":[{"id":13045,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/13035\/revisions\/13045"}],"wp:attachment":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/media?parent=13035"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/categories?post=13035"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/tags?post=13035"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}