「WebLogic」JMX で MBean にアクセスする
JMX 使って WebLogic Server MBean にアクセスしてみました。その時のメモ。
[ 環境情報 ]
Windows 7 SP1
WebLogic Server 12c
Java SE 7 Update 45
※ wlclient.jar と wljmxclient.jar が必要なのでクラスパス内に置いておく。
上記の .jar ファイルは $WLS_HOME\wlserver_12.1\server\lib 配下にあるはずです。
ドキュメント的には以下になります。
・The WebLogic Server MBean Reference
http://docs.oracle.com/cd/E24329_01/apirefs.1211/e24403/index.html?skipReload=true
※ 具体的な接続方法とかはこの辺り。
・Accessing WebLogic Server MBeans with JMX - 12c Release 1 (12.1.1)
http://docs.oracle.com/cd/E24329_01/web.1211/e24415/accesswls.htm
ちゃんとサンプルコードまで載っているので、こいつを参考にして、今回は「管理サーバの ObjectName "com.bea:Name=AdminServer,Type=DataSource,Server=AdminServer" で登録されている MBean を取得する」ってコード書いてみました。
■ WebLogicMBeanTest.java
import java.util.Hashtable; import javax.management.MBeanServerConnection; import javax.management.ObjectName; import javax.management.remote.JMXConnector; import javax.management.remote.JMXConnectorFactory; import javax.management.remote.JMXServiceURL; import javax.naming.Context; public class WebLogicMBeanTest { public static void main(String[] args) throws Exception { String protocol = "t3"; String hostname = "localhost"; int port = 7001; String jndiroot = "/jndi/"; String mserver = "weblogic.management.mbeanservers.domainruntime"; JMXServiceURL serviceURL = new JMXServiceURL(protocol, hostname, port, jndiroot + mserver); ObjectName service = new ObjectName("com.bea:Name=AdminServer,Type=DataSource,Server=AdminServer"); String username = "weblogic"; String password = "weblogic1"; Hashtable h = new Hashtable(); h.put(Context.SECURITY_PRINCIPAL, username); h.put(Context.SECURITY_CREDENTIALS, password); h.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, "weblogic.management.remote"); h.put("jmx.remote.x.request.waiting.timeout", new Long(10000)); JMXConnector connector = JMXConnectorFactory.connect(serviceURL, h); MBeanServerConnection connection = connector.getMBeanServerConnection(); String name = (String) connection.getAttribute(service, "Name"); System.out.println("name : " + name); connector.close(); } }
■ 実行結果
name : AdminServer
ちゃんと取れとります。
WebLogic Server MBean にどんなものが登録されているのかってあたりは jconsole とかで調べてやればいいですかね ( ObjectName やら、属性やらもそこから確認できます )。
以上です。