WebLogic 診断フレームワークのコンフィグレーションと使い方

     前  次    新しいウィンドウで目次を開く     
ここから内容の開始

WebLogic Scripting Tool のサンプル

以下のサンプルでは、WLST および JMX を使用して WLDF コンポーネントと対話します。

WebLogic Scripting Tool (weblogic.WLST) スクリプトの実行については、『WebLogic Scripting Tool ガイド』の「スクリプトの実行」を参照してください。JMX アプリケーションの開発については、『JMX による管理の容易なアプリケーションの開発』を参照してください。

 


サンプル : DyeInjection モニタの動的な作成

このデモ スクリプトでは (コード リスト C-1 を参照)、weblogic.WLST ツールを使用して動的に DyeInjection モニタを作成する方法について示します。このスクリプトでは以下のことを行います。

このデモ スクリプトでは、診断コンテキストに仕分けの値を挿入する仕分けモニタのコンフィグレーションのみを行います。イベントをトリガするには、指定された仕分け条件を基に仕分けフィルタを使用してトリガを行う、下流工程の診断モニタを実装する必要があります。この下流工程のモニタ アーティファクトのサンプルは下記に示します。これは weblogic-diagnostics.xml というファイルに設定して、アプリケーションのアーカイブの META-INF ディレクトリに配置する必要があります。JSR-88 のデプロイメント プランを使用してモニタを作成することも可能です。アプリケーションのデプロイの詳細については、『WebLogic Server アプリケーションのデプロイメント』を参照してください。

コード リスト C-1 サンプル : WLST を使用した DyeInjection モニタの動的な作成 (demoDyeMonitorCreate.py)
# スクリプト名 : demoDyeMonitorCreate.py

# WLST によって DyeInjectionMonitor を動的に作成する方法を示す
# デモ スクリプト。このスクリプトでは以下のことを行う。
# - サーバに接続し、必要な場合には始めにサーバを起動する
# - WLDF システム リソースをルックアップまたは作成する
# - DyeInjection モニタ (DIM) を作成する
# - 仕分け条件を指定する
# - モニタを有効にする
# - 保存してアクティブ化する
# - ServerDiagnosticConfig MBean を介して
# 診断コンテキスト機能を有効にする
# 注意 : ここでは、診断コンテキストに仕分けの値を挿入する仕分けモニタの
# コンフィグレーションのみを行う。イベントをトリガするには、指定された
# 仕分け条件を基にトリガを行うように設定された「下流工程」のモニタがある
# 必要がある。

# この下流工程のモニタ アーティファクトのサンプルは下記に示す。これは
# 「weblogic-diagnostics.xml」というファイルに設定して、アプリケーションの
# アーカイブの「META-INF」ディレクトリに配置する必要がある。JSR 88 の
# デプロイメント プランを使用してモニタを作成することも可能。
# 詳細については、関連するマニュアルを参照のこと。
# <?xml version="1.0" encoding="UTF-8"?>
# <wldf-resource xmlns="http://www.bea.com/ns/weblogic/90/diagnostics"
# xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
# <instrumentation>
# <enabled>true</enabled>
# <!-- Servlet Session Monitors -->
# <wldf-instrumentation-monitor>
# <name>Servlet_Before_Session</name>
# <enabled>true</enabled>
# <dye-mask>USER1</dye-mask>
# <dye-filtering-enabled>true</dye-filtering-enabled>
# <action>TraceAction</action>
# <action>StackDumpAction</action>
# <action>DisplayArgumentsAction</action>
# <action>ThreadDumpAction</action>
# </wldf-instrumentation-monitor>
#     <wldf-instrumentation-monitor>
# <name>Servlet_After_Session</name>
# <enabled>true</enabled>
# <dye-mask>USER2</dye-mask>
# <dye-filtering-enabled>true</dye-filtering-enabled>
# <action>TraceAction</action>
# <action>StackDumpAction</action>
# <action>DisplayArgumentsAction</action>
# <action>ThreadDumpAction</action>
# </wldf-instrumentation-monitor>
# </instrumentation>
# </wldf-resource>
##########################################################################
myDomainDirectory="domain"
url="t3://localhost:7001"
user="weblogic"
password="weblogic"
myServerName="myserver"
myDomain="mydomain"
props="weblogic.GenerateDefaultConfig=true,weblogic.RootDirectory="\
+myDomainDirectory
try:
connect(user,password,url)
except:
  startServer(adminServerName=myServerName,domainName=myDomain,
username=user,password=password,systemProperties=props,
domainDir=myDomainDirectory,block="true")
connect(user,password,url)
# 編集セッションを開始する
edit()
startEdit()
cd ("/")
# WLDF システム リソースをルックアップまたは作成する
wldfResourceName = "mywldf"
myWldfVar = cmo.lookupSystemResource(wldfResourceName)
if myWldfVar==None:
print "Unable to find named resource,\
creating WLDF System Resource: " + wldfResourceName
myWldfVar=cmo.createWLDFSystemResource(wldfResourceName)
# システム リソースをデモ サーバに割り当てる
wldfServer=cmo.lookupServer(serverName)
myWldfVar.addTarget(wldfServer)
# DyeInjection モニタ (DIM) のプロパティを作成して設定する 
mywldfResource=myWldfVar.getWLDFResource()
mywldfInst=mywldfResource.getInstrumentation()
mywldfInst.setEnabled(1)
monitor=mywldfInst.createWLDFInstrumentationMonitor("DyeInjection")
monitor.setEnabled(1)
# DyeInjection モニタにプロパティを設定する際には、改行を 
# 含める必要がある
monitor.setProperties("\nUSER1=larry@celtics.com\
\nUSER2=brady@patriots.com\n")
monitor.setDyeFilteringEnabled(1)
# ServerDiagnosticConfig を介して診断コンテキスト機能を
# 有効にする
cd("/Servers/"+serverName+"/ServerDiagnosticConfig/"+serverName)
cmo.setDiagnosticContextEnabled(1)
# 保存して接続を切断する
save()
activate()
disconnect()
exit()

 


サンプル : 監視と JMX 通知のコンフィグレーション

このデモ スクリプトでは (コード リスト C-2 を参照)、weblogic.WLST ツールを用いて、WLDF の監視と通知コンポーネントを使用する、監視と JMX 通知をコンフィグレーションする方法を示します。このスクリプトでは以下のことを行います。

このスクリプトは以下のファイルおよびスクリプトと連携させることで使用できます。

これらのファイルを連携させるには、以下の手順を実行します。

  1. 次のように入力して、監視のコンフィグレーション スクリプト (demoWatch.py) を実行します。
  2.   java weblogic.WLST demoWatch.py
  3. 次のように入力して、JMXWatchNotificationListener.java ソースをコンパイルします。
  4. javac JMXWatchNotificationListener.java
  5. 次のように入力して、JMXWatchNotificationListener.class ファイルを実行します。
  6. java JMXWatchNotificationListener
    注意 : 前の手順で作成したクラスが見つかるよう、現在のディレクトリがクラス パス内にあることを確認してください。
  7. 次のように入力して、demoHarvester.py スクリプトを実行します。
  8.   java weblogic.WLST demoHarvester.py

demoHarvester.py スクリプトを実行すると、手順 1 でコンフィグレーションされた監視の JMX 通知がトリガされます。

コード リスト C-2 サンプル : 監視と JMX 通知 (demoWatch.py)
# スクリプト名 : demoWatch.py
##########################################################################
# WLDF の監視と通知のフレームワークを使用する監視および JMX 通知の
# コンフィグレーション方法を示すデモ スクリプト。
# このスクリプトでは以下のことを行う。
# - サーバに接続し、必要な場合には始めにサーバを起動する
# - WLDF システム リソースをルックアップまたは作成する
# - ServerRuntimeMBean に「OpenSocketsCurrentCount」属性用の
# 監視と監視ルールを作成する。
# - JMX 通知手段を使用するように監視をコンフィグレーションする
#
# このスクリプトは以下と連携させることで使用できる。
# - JMXWatchNotificationListener.java クラス
# - demoHarvester.py スクリプト
#   (このスクリプトでは、収集のためにハーベスタに「OpenSocketsCurrentCount」属性を登録する)
# これらのファイルを連携させるには、以下の手順を実行する。
# 1. 監視のコンフィグレーション スクリプトを実行する
# java weblogic.WLST demoWatch.py
# 2. JMXWatchNotificationListener.java ソース コードをコンパイルして起動する
# javac JMXWatchNotificationListener.java
#         java JMXWatchNotificationListener
# 3.










try:
connect(user,user,url)
except:
startServer(adminServerName=myServerName,domainName=myDomain,
username=user,password=user,systemProperties=props,
domainDir=myDomainDirectory,block="true")
connect(user,user,url)
edit()
startEdit()
# WLDF システム リソースをルックアップまたは作成する
wldfResourceName = "mywldf"
myWldfVar = cmo.lookupSystemResource(wldfResourceName)
if myWldfVar==None:
print "Unable to find named resource"
  print "creating WLDF System Resource: " + wldfResourceName
myWldfVar=cmo.createWLDFSystemResource(wldfResourceName)
# システム リソースをデモ サーバに割り当てる
wldfServer=cmo.lookupServer(myServerName)
myWldfVar.addTarget(wldfServer)
cd("/WLDFSystemResources/mywldf/WLDFResource/mywldf/WatchNotification/mywldf")
watch=cmo.createWatch("mywatch")
watch.setEnabled(1)
jmxnot=cmo.createJMXNotification("myjmx")
watch.addNotification(jmxnot)
serverRuntime()
cd("/")
on=cmo.getObjectName().getCanonicalName()
watch.setRuleExpression("${"+on+"} > 1")
watch.getRuleExpression()
watch.setRuleExpression("${"+on+"//OpenSocketsCurrentCount} > 1")
watch.setAlarmResetPeriod(10000)
edit()
save()
activate()
disconnect()
exit()

 


サンプル : JMXWatchNotificationListener クラスの記述

コード リスト C-3 に、JMXWatchNotificationListener の記述方法について示します。

コード リスト C-3 サンプル : JMXWatchNotificationListener クラス (JMXWatchNotificationListener.java)
import javax.management.*;
import weblogic.diagnostics.watch.*;
import weblogic.diagnostics.watch.JMXWatchNotification;
import javax.management.Notification;
import javax.management.remote.JMXServiceURL;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXConnector;
import javax.naming.Context;
import java.util.Hashtable;
import weblogic.management.mbeanservers.runtime.RuntimeServiceMBean;
public class JMXWatchNotificationListener implements NotificationListener, Runnable {
  private MBeanServerConnection rmbs = null;
private String notifName = "myjmx";
private int notifCount = 0;
private String serverName = "myserver";
  public JMXWatchNotificationListener(String serverName) {
  }
  public void register() throws Exception {
rmbs = getRuntimeMBeanServerConnection();
addNotificationHandler();
}
  public void handleNotification(Notification notif, Object handback) {
synchronized (this) {
try {
if (notif instanceof JMXWatchNotification) {
WatchNotification wNotif =
                ((JMXWatchNotification)notif).getExtendedInfo();
notifCount++;
System.out.println("===============================================");
System.out.println("Notification name: " +
notifName + " called.Count= " + notifCount + ".");
System.out.println("Watch severity: " +
                 wNotif.getWatchSeverityLevel());
System.out.println("Watch time: " +
                 wNotif.getWatchTime());
System.out.println("Watch ServerName: " +
                 wNotif.getWatchServerName());
System.out.println("Watch RuleType: " +
                 wNotif.getWatchRuleType());
System.out.println("Watch Rule: " +
                 wNotif.getWatchRule());
System.out.println("Watch Name: " +
                 wNotif.getWatchName());
System.out.println("Watch DomainName: " +
                 wNotif.getWatchDomainName());
System.out.println("Watch AlarmType: " +
                 wNotif.getWatchAlarmType());
System.out.println("Watch AlarmResetPeriod: " +
                 wNotif.getWatchAlarmResetPeriod());
  System.out.println("===============================================");
}
} catch (Throwable x) {
System.out.println("Exception occurred processing JMX watch                 notification: " + notifName +"\n" + x);
x.printStackTrace();
}
}
}
  private void addNotificationHandler() throws Exception {
    /*
     * JMX 監視通知リスナを対応する監視 Bean 名と一致する
     * 実行時 MBean に登録する。
     * 各監視に独自の実行時 MBean のインスタンスがある
     */
    ObjectName oname = 
new ObjectName(
"com.bea:ServerRuntime=" + serverName + ",Name=" +
JMXWatchNotification.GLOBAL_JMX_NOTIFICATION_PRODUCER_NAME +
",Type=WLDFWatchJMXNotificationRuntime," +
"WLDFWatchNotificationRuntime=WatchNotification," +
"WLDFRuntime=WLDFRuntime"
);
     System.out.println("Adding notification handler for: " +
       oname.getCanonicalName());
rmbs.addNotificationListener(oname, this, null, null);
}
  private void removeNotificationHandler(String name,
NotificationListener list) throws Exception {
ObjectName oname =
new ObjectName(
"com.bea:ServerRuntime=" + serverName + ",Name=" +
JMXWatchNotification.GLOBAL_JMX_NOTIFICATION_PRODUCER_NAME +
",Type=WLDFWatchJMXNotificationRuntime," +
"WLDFWatchNotificationRuntime=WatchNotification," +
"WLDFRuntime=WLDFRuntime"
);
System.out.println("Removing notification handler for: " +
        oname.getCanonicalName());
rmbs.removeNotificationListener(oname, list);
}
  public void run() {
try {
System.out.println("VM shutdown, unregistering notification
          listener");
removeNotificationHandler(notifName, this);
} catch (Throwable t) {
System.out.println("Caught exception in shutdown hook");
t.printStackTrace();
}
}
  private String user = "weblogic";
private String password = "weblogic";
  public MBeanServerConnection getRuntimeMBeanServerConnection()
throws Exception {
    String JNDI = "/jndi/";
    JMXServiceURL serviceURL;
serviceURL =
new JMXServiceURL("t3", "localhost", 7001,
JNDI + RuntimeServiceMBean.MBEANSERVER_JNDI_NAME);
    System.out.println("URL=" + serviceURL);
    Hashtable h = new Hashtable();
h.put(Context.SECURITY_PRINCIPAL,user);
h.put(Context.SECURITY_CREDENTIALS,password);
h.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES,
"weblogic.management.remote");
JMXConnector connector = JMXConnectorFactory.connect(serviceURL,h);
return connector.getMBeanServerConnection();
}
  public static void  main(String[] args) {
try {
String serverName = "myserver";
if (args.length > 0)
serverName = args[0];
JMXWatchNotificationListener listener =
new JMXWatchNotificationListener(serverName);
System.out.println("Adding shutdown hook");
Runtime.getRuntime().addShutdownHook(new Thread(listener));
listener.register();
// 通知を待機してスリープする
Thread.sleep(Long.MAX_VALUE);
} catch (Throwable e) {
e.printStackTrace();
} // try-catch の終了
} // main() の終了
}

 


サンプル : 収集用の MBean と属性の登録

このデモ スクリプトでは、WLDF ハーベスタで収集するために、weblogic.WLST ツールを使用して MBean および属性を登録する方法を示します。このスクリプトでは以下のことを行います。


  ページの先頭       前  次