Oracle® Fusion Middleware Oracle WebLogic Server JMXによるカスタム管理ユーティリティの開発 11g リリース1(10.3.5) B61630-03 |
|
前 |
次 |
以下の節では、JMXクライアントからWebLogic Server MBeanにアクセスする方法について説明します。
JMXクライアントが独自のJVM (つまり、WebLogic ServerインスタンスでないJVM)で実行される場合は、クライアントのクラス・パスに次のJARファイルを含めます。
WL_HOME\lib\wljmxclient.jar
WL_HOME
は、WebLogic Serverのインストール先ディレクトリです。
このJARには、HTTPプロトコルとIIOPプロトコルのOracle実装が含まれます。Oracle実装を使用する場合は、JMXクライアントが接続リクエストとともにログイン資格証明を送信し、WebLogic Serverのセキュリティ・フレームワークがクライアントを認証します。認証されたクライアントだけが、WebLogic Server MBeanサーバーに登録されているMBeanにアクセスできます。
注意: HTTPプロトコルとIIOPプロトコルのOracle実装を使用することをお薦めしますが、JMXクライアントでは標準のJDKで定義されているIIOPプロトコルを使用することもできます。「JDKクラスのみを使用したリモート接続」を参照してください。T3プロトコルが指定されている場合、IIOPを使用するようクライアントで自動的に変換されます。 |
各WebLogic Serverドメインには3種類のMBeanサーバーが含まれており、それぞれのMBeanサーバーが別々のMBean階層へのアクセスを提供します。「MBeanサーバー」を参照してください。
WebLogic MBeanサーバーに接続するには、次の手順に従います。
javax.management.remote.JMXServiceURL
オブジェクトを作成して、MBeanサーバーのアドレスを記述します。
以下のパラメータの値をコンストラクタに渡します(http://download.oracle.com/javase/6/docs/api/javax/management/remote/JMXServiceURL.html
でJ2SE 6.0 API仕様のJMXServiceURL
を参照してください)。
MBeanサーバーとの通信に使用するプロトコルとして、以下の値からいずれか1つ。
t3
,t3s
,http
,https
,iiop
,iiops
MBeanサーバーをホストするWebLogic Serverインスタンスのリスニング・アドレス。
WebLogic Serverインスタンスのリスニング・ポート。
MBeanサーバーの絶対JNDI名。JNDI名の先頭には/jndi/
を指定し、その後には表4-1で説明するJNDI名のいずれかを続ける必要があります。
javax.management.remote.JMXConnector
オブジェクトを作成します。このオブジェクトには、JMXクライアントがMBeanサーバーへの接続に使用するメソッドがあります。
JMXConnector
のコンストラクタ・メソッドは、以下のとおりです。
javax.management.remote.JMXConnectorFactory.
connector(JMXServiceURL
serviceURL, Map<String,?>
environment)
以下のパラメータの値をコンストラクタに渡します(http://download.oracle.com/javase/6/docs/api/javax/management/remote/JMXConnectorFactory.html
でJ2SE 6.0 API仕様のJMXConnectorFactory
を参照してください)。
前の手順で作成したJMXServiceURL
オブジェクト。
以下の名前と値のペアを含むハッシュ・マップ。
javax.naming.Context.SECURITY_PRINCIPAL, admin-user-name javax.naming.Context.SECURITY_CREDENTIALS, admin-user-password javax.management.remote.JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, "weblogic.management.remote"
weblogic.management.remote
パッケージは、WebLogic MBeanサーバーへの接続に使用できるプロトコルを定義します。リモートJMXクライアントは、クラス・パスにこのパッケージのクラスを含める必要があります。「リモート・クライアントのクラス・パスの設定」を参照してください。
必要に応じて、以下の名前と値のペアをハッシュ・マップに含めます。
jmx.remote.x.request.waiting.timeout, milliseconds
milliseconds
は、JMXクライアントがMBeanサーバー・メソッドの呼出しが返されるまで待機するミリ秒数が格納されたjava.lang.Long
オブジェクトです。メソッドがタイムアウト期間の終了までに返されない場合、クライアントは次の命令セットに移動します。デフォルトでは、クライアントはメソッドが返されるのを無期限に待機します。MBeanサーバーが呼出しを完了できない場合には、JMXクライアントは無期限にハングします。
JMXConnector.getMBeanServerConnection()
メソッドを呼び出して、WebLogic MBeanサーバーに接続します。
このメソッドは、javax.management.MBeanServerConnection
型のオブジェクトを返します。
MBeanServerConnection
オブジェクトは、WebLogic MBeanサーバーへの接続です。このオブジェクトは、ローカルおよびリモートの接続に使用できます。J2SE 6.0 API仕様(http://download.oracle.com/javase/6/docs/api/javax/management/MBeanServerConnection.html
)のMBeanServerConnection
を参照してください。
クライアントが作業を終了したら、JMXConnector.close()
メソッドを呼び出してMBeanサーバーとの接続を閉じることをお薦めします。
例4-1のコードに関する以下の点に留意してください。
クラスは、グローバル変数connection
およびconnector
を使用して、MBeanサーバーへの接続を表します。connection
変数およびconnector
変数に値を割り当てるinitConnection()
メソッドは、クラス内で再利用できる1つの接続を確立するためにクラス・インスタンスごとに一度だけ呼び出される必要があります。
initConnection()
メソッドは、クラスがインスタンス化されるときに渡される引数として、(サーバーのリスニング・アドレスとリスニング・ポートとともに)ユーザー名とパスワードを取ります。暗号化されていないユーザー資格証明がコード内に含まれないようにするため、この方法をお薦めします。これらの引数を保持するString
オブジェクトは破棄され、JVMのガベージ・コレクション・ルーチンによってメモリーから削除されます。
クライアントは、jmx.remote.x.request.waiting.timeout
環境パラメータを10000に設定するので、MBeanサーバー・メソッド呼出しはすべて、呼出し後10000ミリ秒以内にメソッドが返されなければ、タイムアウトします。
クラスが作業を終了したら、JMXConnector.close()
メソッドを呼び出してMBeanサーバーとの接続を閉じる(J2SE 6.0 API仕様(http://download.oracle.com/javase/6/docs/api/javax/management/remote/JMXConnector.html
)のJMXConnector
を参照してください。)
例4-1 ドメイン・ランタイムMBeanサーバーへの接続
public class MyConnection { private static MBeanServerConnection connection; private static JMXConnector connector; private static final ObjectName service; /* * Initialize connection to the Domain Runtime MBean Server. */ public static void initConnection(String hostname, String portString, String username, String password) throws IOException, MalformedURLException { String protocol = "t3"; Integer portInteger = Integer.valueOf(portString); int port = portInteger.intValue(); String jndiroot = "/jndi/"; String mserver = "weblogic.management.mbeanservers.domainruntime"; JMXServiceURL serviceURL = new JMXServiceURL(protocol, hostname, port, jndiroot + mserver); 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)); connector = JMXConnectorFactory.connect(serviceURL, h); connection = connector.getMBeanServerConnection(); } public static void main(String[] args) throws Exception { String hostname = args[0]; String portString = args[1]; String username = args[2]; String password = args[3]; MyConnection c= new MyConnection(); initConnection(hostname, portString, username, password); ... connector.close(); } }
WebLogic Serverドメインは3種類のMBeanサーバーを保持しており、それぞれのMBeanサーバーが特定の機能を実行します。以下のように、実行しようとしているタスクをサポートしているMBeanサーバーを介してMBeanにアクセスします。
ドメインの構成を変更するには、編集MBeanサーバーを使用します。
保留中の構成MBeanの階層に対する変更をモニターするには、編集MBeanサーバーを使用します。
アクティブな構成MBeanのみをモニターする(ランタイムMBeanはモニターしない)ためには、ランタイムMBeanサーバーを使用します。
ランタイムMBeanサーバーを使用したモニターのほうが、ドメイン・ランタイムMBeanサーバーを使用したモニターより、使用するメモリーとネットワーク・トラフィックの量が小さくなります。(WebLogic Serverは、クライアントが接続を要求するまでドメイン・ランタイムMBeanサーバーを初期化しません)。
ほとんどの場合、ドメイン内のすべてのサーバー・インスタンスは同じ構成データのセットを保持しているため、管理サーバーまたは管理対象サーバーどちらのランタイムMBeanサーバーをモニターするかは重要ではありません。ただし、サーバーを再起動しないと消費できない変更を行うと、サーバーは変更を受け入れなくなり、そのサーバーの構成データが古くなるおそれがあります。この場合、このサーバーのランタイムMBeanサーバーをモニターすることは、その特定のサーバー・インスタンスの構成のみをモニターすることになります。WebLogic Serverドメインの変更、および変更のアクティブ化のプロセスを理解するには、Oracle WebLogic Serverドメイン構成についてのドキュメントの構成の変更の管理に関する項を参照してください。
クライアントが複数のサーバーのランタイムMBeanをモニターする場合や、クライアントが別のJVMで実行されている場合は、ドメイン内の各サーバー・インスタンス上のそれぞれのランタイムMBeanサーバーに個別に接続するのではなく、管理サーバー上のドメイン・ランタイムMBeanサーバーに接続することをお薦めします。
ドメイン・ランタイムMbeanサーバーのMbeanにJMXリスナーとフィルタを登録する場合は、JMXフィルタを、それがモニターするMBeanと同じJVMで実行します。たとえば、ある管理対象サーバー上のMBeanにフィルタを登録する場合は、フィルタをその管理対象サーバーで実行し、フィルタ条件を満たすメッセージのみをリスナーに転送します。
一般的に、ドメイン・ランタイムMBeanサーバーを使用するコードのほうが、各サーバー・インスタンス上のランタイムMBeanサーバーを使用するコードより管理がしやすく安全性も高くなっています。その理由は以下のとおりです。
コードで必要なのは、管理サーバー上のドメイン・ランタイムMBeanサーバーに接続するための1つのURLを作成することだけです。以後、コードですべてのサーバー・インスタンスの値をルックアップしたり、必要に応じて結果をフィルタ処理したりできます。
コードでランタイムMBeanサーバーを使用して複数のサーバー・インスタンス上のMBeanの値を読み込む場合には、各サーバー・インスタンス用のURLを作成する必要があり、URLごとに一意のリスニング・アドレスとリスニング・ポートの組合せが必要になります。
管理サーバーのセキュアな管理ポートを介してWebLogic Serverドメイン内のすべての管理トラフィックをルーティングでき、ファイアウォールを使用して管理対象サーバーの管理ポートへのファイアウォール外部からの接続を回避できます。
ドメイン・ランタイムMBeanサーバーを使用してすべてのJMXリクエストを転送することによるトレード・オフとして、ネットワーク・レイテンシとメモリー使用量の増加のためにパフォーマンスが若干低下します。MBean値を読み込むために各管理対象サーバーのランタイムMBeanサーバーに直接接続すると、管理対象サーバーから値を取得するためにドメイン・ランタイムMBeanサーバーが作成するネットワーク・ホップが削除されます。ただし、大半のネットワーク・トポロジとパフォーマンス要件では、ドメイン・ランタイムMBeanサーバーによって有効化される簡略化されたコード・メンテナンスおよび強化セキュリティが推奨されます。
リモートJMXクライアントからの接続ではWebLogic Serverクラスを使用することをお薦めします。ただし、リモートJMXクライアントでJDKのクラスのみを使用してWebLogic Server JMXエージェントに接続することもできます。そのためには、次の手順に従います。
wljmxclient.jar
とwlclient.jar
をクライアント・クラス・パスに指定しない場合、
MBeanをホストするWebLogic ServerインスタンスのIIOPプロトコルを有効にします。
管理者権限を持つWebLogic Serverユーザーになるように、デフォルトのIIOPユーザーを構成します。
管理コンソール・オンライン・ヘルプの「IIOPの有効化と構成」を参照してください。
wljmxclient.jar
とwlclient.jar
をクライアント・クラス・パスに指定した場合、デフォルトのIIOPユーザーを有効にする必要はありません。ステップ2に進みます。
注意: wlclient.jar はwljmxclient.jar のMANIFEST ClassPathエントリにあるので、wlclient.jar とwljmxclient.jar は同じディレクトリにあるか、または両方のjarはクラス・パスで指定する必要があります。
クラス・パスに |
JMXクライアントで、javax.management.JMXConnector
オブジェクトを次のように作成します。
String hostname = "WLS-host" int port = WLS-port String protocol = "iiop"; String jndiroot= new String("/jndi/iiop://" + hostname + ":" + port + "/"); String mserver = "MBean-server-JNDI-name"; JMXServiceURL serviceURL = new JMXServiceURL(protocol, hostname, port, jndiroot + mserver); Hashtable h = new Hashtable(); h.put(Context.SECURITY_PRINCIPAL, username); h.put(Context.SECURITY_CREDENTIALS, password); connector = JMXConnectorFactory.connect(serviceURL, h);
WLS-host
とWLS-port
はWebLogic Serverインスタンスのリスニング・アドレスとリスニング・ポートであり、MBean-server-JNDI-name
は表4-1に示した値のいずれかです。
作成するハッシュ表には、プロトコル・パッケージの名前が含まれていません。この値をnullのままにしておくことで、JMXクライアントはJDKのcom.sun.jmx.remote.protocol
パッケージからプロトコル定義を使用します。
ローカル・クライアントは、JMXServiceURL
オブジェクトを作成するのではなく、JNDIツリーを介してWebLogic ServerインスタンスのランタイムMBeanサーバーにアクセスできます。
注意: 「ドメイン・ランタイムMBeanサーバーへのローカル接続の作成」の説明に従って、ローカル・クライアントは、JNDIツリーを介してWebLogic Serverのドメイン・ランタイムMBeanサーバーにもアクセスできます。 |
JNDIからアクセスされると、ランタイムMBeanサーバーはそのjavax.management.MBeanServer
インタフェースを返します。このインタフェースには、MBeanServerConnection
インタフェースのすべてのメソッドと、ローカル・プロセスがカスタムMBeanの登録に使用するregisterMBean()
などの追加のメソッドがあります。(「J2SE 6.0 API仕様」(http://download.oracle.com/javase/6/docs/api/javax/management/MBeanServer.html
)のMBeanServer
を参照してください。)
JMXクライアントのクラスが、EJBまたはWebアプリケーションなどのJava EEモジュールにある場合、ランタイムMBeanServerのJNDI名は次のようになります。
java:comp/env/jmx/runtime
例:
InitialContext ctx = new InitialContext(); server = (MBeanServer)ctx.lookup("java:comp/env/jmx/runtime");
JMXクライアントのクラスがJava EEモジュールの一部ではない場合、ランタイムMBeanサーバーのJNDI名は次のようになります。
java:comp/jmx/runtime
ローカル・クライアントは、JMXServiceURL
オブジェクトを作成するのではなく、JNDIツリーを介してWebLogic Serverインスタンスのドメイン・ランタイムMBeanサーバーにアクセスできます。
JNDIからアクセスされると、ドメイン・ランタイムMBeanサーバーはそのjavax.management.MBeanServer
インタフェースを返します。このインタフェースには、MBeanServerConnection
インタフェースのすべてのメソッドと、ローカル・プロセスがカスタムMBeanの登録に使用するregisterMBean()
などの追加のメソッドの他にgetMBeanCount()
、instatiate()
、とgetClassLoader()
などのメソッドもあります。(「J2SE 6.0 API仕様」(http://download.oracle.com/javase/6/docs/api/javax/management/MBeanServer.html
)のMBeanServer
を参照してください。)
注意: ベスト・プラクティスとして、Oracleでは、ドメイン・ランタイムMBeanサーバーをドメイン全体の操作を実行するMBeanにのみ使用することをお薦めします。MBeanの処理とネットワーク・アクティビティにより管理サーバーの処理速度が低下し、管理操作の開始が回避されていないことを確認してください。 |
JMXクライアントのクラスが、EJBまたはWebアプリケーションなどのJava EEモジュールにある場合、ドメイン・ランタイムMBeanServerのJNDI名は次のようになります。
java:comp/env/jmx/domainRuntime
例:
InitialContext ctx = new InitialContext(); server = (MBeanServer)ctx.lookup("java:comp/env/jmx/domainRuntime");
JMXクライアントのクラスがJava EEモジュールの一部ではない場合、ドメイン・ランタイムMBeanサーバーのJNDI名は次のようになります。
java:comp/jmx/domainRuntime
ドメイン・ランタイムMBeanサーバーは、管理サーバー上にのみ存在します。呼出しctx.lookup()
は、ローカルMBeanServerに参照を返すため、ルックアップ・メソッドは管理サーバー上で実行する場合にのみ呼び出すことができます。管理対象サーバー上で実行するときに呼び出された場合、NameNotFound
例外がスローされます。
WebLogic Serverは、MBeanを階層データ・モデルにまとめます。(「WebLogic Server MBeanデータ・モデル」を参照してください)このモデルでは、すべての親MBeanに、その子のオブジェクト名を含む属性が含まれます。標準のJMX APIで子のオブジェクト名を使用して、子MBeanの属性の値を取得または設定したり、そのメソッドを呼び出したりします。
WebLogic Server MBean階層を移動するには、次の手順に従います。
MBeanサーバーへの接続を開始します。
上記の項「MBeanサーバーへのリモート接続の作成」を参照してください。
接続を開始すると、次の型のオブジェクトを返します。
javax.management.MBeanServerConnection
MBeanServerConnection
.getAttribute(ObjectName
object-name
, String
attribute
)
メソッドを呼び出して、MBean階層のルートにあるMBeanのオブジェクト名を取得します。各値の説明は次のとおりです。
object-name
は、MBeanサーバーに登録されているサービスMBeanのオブジェクト名。(「サービスMBean」を参照してください。)
表2-3には、各種のMBeanサーバーで使用可能なサービスMBeanのタイプが示されています。
attribute
は、ルートMBeanを含むサービスMBean属性の名前。
次のようなコードを連続して呼び出します。
ObjectName on =
MBeanServerConnection.getAttribute(
object-name
,
attribute
)
説明:
object-name
は、MBean階層内の現在のノード(MBean)のオブジェクト名。
attribute
は、子MBeanの1つまたは複数のインスタンスを含む、現在のMBeanの属性の名前。属性に複数の子がある場合は、その出力をオブジェクト名の配列ObjectName[]
に割り当てます。
MBean階層でのMBeanの場所を判別するには、Oracle WebLogic Server MBeanリファレンスでそのMBeanの説明を参照してください。WebLogic Server MBeanリファレンスでは、各MBeanについて、現在のMBeanのファクトリ・メソッドを保持する親MBeanが記載されています。ファクトリ・メソッドがパブリックでないMBeanについては、Oracle WebLogic Server MBeanリファレンスに、現在のMBeanにアクセスできる他のMBeanが記載されています。
例4-2のサンプル・コードでは、ドメイン・ランタイムMBeanサーバーに接続し、DomainRuntimeServiceMBean
を使用してドメイン内の各ServerRuntimeMBean
のオブジェクト名を取得します。その後、各サーバーのServerRuntimeMBean
のName
属性およびState
属性の値を取得し、出力します。
例4-2のコードに関する以下の点に留意してください。
クラスは、connection
グローバル変数とconnector
グローバル変数に加えて、WebLogic ServerサービスMBeanのオブジェクト名をグローバル変数に割り当てます。クラス内のメソッドはこのオブジェクト名を頻繁に使用します。このオブジェクト名は一度定義したら、変更する必要はありません。
printServerRuntimes()
メソッドは、ドメイン内のすべてのServerRuntimeMBean
インスタンスの配列を保持するDomainRuntimeServiceMBean
のServerRuntimes
属性の値を取得します。(Oracle WebLogic Server MBeanリファレンスのDomainRuntimeServiceMBeanに関する項を参照してください。)
例4-2 例:サーバーの名前と状態の出力
import java.io.IOException; import java.net.MalformedURLException; import java.util.Hashtable; import javax.management.MBeanServerConnection; import javax.management.MalformedObjectNameException; 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 PrintServerState { private static MBeanServerConnection connection; private static JMXConnector connector; private static final ObjectName service; // Initializing the object name for DomainRuntimeServiceMBean // so it can be used throughout the class. static { try { service = new ObjectName( "com.bea:Name=DomainRuntimeService,Type=weblogic.management. mbeanservers.domainruntime.DomainRuntimeServiceMBean"); }catch (MalformedObjectNameException e) { throw new AssertionError(e.getMessage()); } } /* * Initialize connection to the Domain Runtime MBean Server */ public static void initConnection(String hostname, String portString, String username, String password) throws IOException, MalformedURLException { String protocol = "t3"; Integer portInteger = Integer.valueOf(portString); int port = portInteger.intValue(); String jndiroot = "/jndi/"; String mserver = "weblogic.management.mbeanservers.domainruntime"; JMXServiceURL serviceURL = new JMXServiceURL(protocol, hostname, port, jndiroot + mserver); 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"); connector = JMXConnectorFactory.connect(serviceURL, h); connection = connector.getMBeanServerConnection(); } /* * Print an array of ServerRuntimeMBeans. * This MBean is the root of the runtime MBean hierarchy, and * each server in the domain hosts its own instance. */ public static ObjectName[] getServerRuntimes() throws Exception { return (ObjectName[]) connection.getAttribute(service, "ServerRuntimes"); } /* * Iterate through ServerRuntimeMBeans and get the name and state */ public void printNameAndState() throws Exception { ObjectName[] serverRT = getServerRuntimes(); System.out.println("got server runtimes"); int length = (int) serverRT.length; for (int i = 0; i < length; i++) { String name = (String) connection.getAttribute(serverRT[i], "Name"); String state = (String) connection.getAttribute(serverRT[i], "State"); System.out.println("Server name: " + name + ". Server state: " + state); } } public static void main(String[] args) throws Exception { String hostname = args[0]; String portString = args[1]; String username = args[2]; String password = args[3]; PrintServerState s = new PrintServerState(); initConnection(hostname, portString, username, password); s.printNameAndState(); connector.close(); } }
Webアプリケーションの各サーブレットは、サーブレットのランタイムの状態についての情報を保持するServletRuntimeMBean
のインスタンスを提供します。(Oracle WebLogic Server MBeanリファレンスのServletRuntimeMBeanに関する項を参照してください。)
WebLogic Serverのデータ・モデルでは、ServletRuntimeMBean
へのパスは次のようになります。
ドメイン・ランタイムMBeanサーバー(ドメイン内の全サーバー上にあるすべてのサーブレット用)、または特定のサーバー・インスタンス上のランタイムMBeanサーバー。
DomainRuntimeServiceMBean
またはRuntimeServiceMBean
のServerRuntimes
属性。
ServerRuntimeMBean
のApplicationRuntimes
属性。
ApplicationRuntimeMBean
のComponentRuntimes
属性。
ComponentRuntimes
属性には、様々なタイプのコンポーネントのランタイムMBeanが保持されます。それらの1つがWebAppComponentRuntimeMBean
です。この属性の値を取得したら、子MBeanのType
属性を使用して特定のタイプのコンポーネントのランタイムMBeanを取得します。
WebAppComponentRuntimeMBean
のServletRuntimes
属性。
例4-3のコードでは、上記の節で説明したように階層を移動し、ServletRuntimeMBean
属性の値を取得します。
例4-3 サーブレットのモニター
import java.io.IOException; import java.net.MalformedURLException; import java.util.Hashtable; import javax.management.MBeanServerConnection; import javax.management.MalformedObjectNameException; 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 MonitorServlets { private static MBeanServerConnection connection; private static JMXConnector connector; private static final ObjectName service; // Initializing the object name for DomainRuntimeServiceMBean // so it can be used throughout the class. static { try { service = new ObjectName( "com.bea:Name=DomainRuntimeService,Type=weblogic.management.mbeanser vers.domainruntime.DomainRuntimeServiceMBean"); }catch (MalformedObjectNameException e) { throw new AssertionError(e.getMessage()); } } /* * Initialize connection to the Domain Runtime MBean Server */ public static void initConnection(String hostname, String portString, String username, String password) throws IOException, MalformedURLException { String protocol = "t3"; Integer portInteger = Integer.valueOf(portString); int port = portInteger.intValue(); String jndiroot = "/jndi/"; String mserver = "weblogic.management.mbeanservers.domainruntime"; JMXServiceURL serviceURL = new JMXServiceURL(protocol, hostname, port, jndiroot + mserver); 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"); connector = JMXConnectorFactory.connect(serviceURL, h); connection = connector.getMBeanServerConnection(); } /* * Get an array of ServerRuntimeMBeans */ public static ObjectName[] getServerRuntimes() throws Exception { return (ObjectName[]) connection.getAttribute(service, "ServerRuntimes"); } /* * Get an array of WebAppComponentRuntimeMBeans */ public void getServletData() throws Exception { ObjectName[] serverRT = getServerRuntimes(); int length = (int) serverRT.length; for (int i = 0; i < length; i++) { ObjectName[] appRT = (ObjectName[]) connection.getAttribute(serverRT[i], "ApplicationRuntimes"); int appLength = (int) appRT.length; for (int x = 0; x < appLength; x++) { System.out.println("Application name: " + (String)connection.getAttribute(appRT[x], "Name")); ObjectName[] compRT = (ObjectName[]) connection.getAttribute(appRT[x], "ComponentRuntimes"); int compLength = (int) compRT.length; for (int y = 0; y < compLength; y++) { System.out.println(" Component name: " + (String)connection.getAttribute(compRT[y], "Name")); String componentType = (String) connection.getAttribute(compRT[y], "Type"); System.out.println(componentType.toString()); if (componentType.toString().equals("WebAppComponentRuntime")){ ObjectName[] servletRTs = (ObjectName[]) connection.getAttribute(compRT[y], "Servlets"); int servletLength = (int) servletRTs.length; for (int z = 0; z < servletLength; z++) { System.out.println(" Servlet name: " + (String)connection.getAttribute(servletRTs[z], "Name")); System.out.println(" Servlet context path: " + (String)connection.getAttribute(servletRTs[z], "ContextPath")); System.out.println(" Invocation Total Count : " + (Object)connection.getAttribute(servletRTs[z], "InvocationTotalCount")); } } } } } } public static void main(String[] args) throws Exception { String hostname = args[0]; String portString = args[1]; String username = args[2]; String password = args[3]; MonitorServlets s = new MonitorServlets(); initConnection(hostname, portString, username, password); s.getServletData(); connector.close(); } }