The WebLogic Diagnostics Framework (WLDF) provides a set of services and APIs that allow users to efficiently gather and publish data on the health of the server and their applications in the WebLogic Server environment. However, some users find it difficult to determine what metrics to collect, and are not familiar with how to configure the WLDF. Here we try to provide a set of WLST scripts and utilities that provide a starting point for creating common WLDF configurations, referred to here as "profiles". Each profile is represented by a of Jython class that encapsulates the Harvester and Watch configurations for that profile, which can then be modified or extended to suit your individual needs. In addition, the framework of utility classes can be used separately, outside the context of profile configuration and management, to allow for easier interaction with WLDF from the WLST command-line.
下载地址:https://files.cnblogs.com/mengheyun/wldfProfiles.zip
WLST Scripts
Core Scripts
The core set of functionality for creating and managing these WLDF profiles can be found in the following WLST modules:
- WLDFResource.py
- WLDFProfiles.py
- destroyWLDFResource.py
- chainedProfilesExample.py
WLDFResource.py provides a core set of utility classes in Jython that provide useful functionality for manipulating instances of the WLDFSystemResourceMBean and it's constituent bean objects. In additional, it provides helper functions that are used by other classes and scripts in this set.
WLDFProfiles.py contains the set of Jython classes that represent the predefined profiles, as well as a utility class, WLDFProfileManager, for enabling or disabling groups of these profiles.
destroyWLDFResource.py will destroy the configured WLDFSystemResourceMBean; the name of the MBean to destroy can be configured on the command line when the script is invoked (see the Usage section).
chainedProfilesExample.py is an example script of how each of the individual profile scripts can be chained together (although it may be easier and more efficient to do it as shown in enableAllProfiles.py).
Profile Scripts
enableCoreProfile.py | Enables the "core" profile, containing a set of core JVM and server heatlh statistics |
enableEJBProfile.py |
Enables the EJB profile |
enableJDBCProfile.py |
Enables the JDBC profile |
enableJMSProfile.py |
Enables the JMS profile |
enableJTAProfile.py |
Enables the JTA profile |
enableWebAppProfile.py |
Enables the WebApp profile |
enableWSProfile.py |
Enables the Web Services profile |
enableAllProfiles.py |
Enables all available profiles |
createSMTPNotification.py |
Creates an SMTP notification, and a corresponding JavaMail session for sending SMTP notifications |
createSNMPNotification.py |
Deploys a domain-wide SNMP agent and an SNMP Trap destination, and creates an SNMP notification |
Each of the above "enable" scripts has a corresponding "disable" script, which will remove the configured WLDFHarvestedTypeBeans and WLDFWatchBean instances associated with each profile.
Profile Scripts Usage
Each script can be invoked separately or chained together. In addition, the WLDFProfileManager class can be used directly to enable ordisable multiple profiles (see the enableAllProfiles.py and disableAllProfiles.py scripts for examples of how to interact with the WLDFProfileManager.
The scripts also accept command-line arguments in the form of name/value pairs to override common settings and parameters, for example
java weblogic.WLST enableAllProfiles.py targets='myserver,mgd1' wldfResource='allProfiles' harvesterPeriod=30000
will create a WLDFSystemResourceMBean named 'allProfiles', configure all available profiles within that resource, set the harvester sampling frequency to 30 seconds, and target the resulting system resource MBean to the servers "myserver", and "mgd1". Below is a table of all the different parameters that can be specified on the command line to control some of the settings for the profile configurations.
Parameter Name |
Default Value |
Description |
user | "weblogic" |
Username used to connect to the server |
pass |
"weblogic" |
Password used to connect to the server |
url |
"t3://localhost:7001" |
Connection URL |
notifications |
Comma-separated list of names of WLDF notification to use for Watch rule configurations |
|
resetPeriod |
2*configured harvester period |
Reset period for Watch rules that have an alarm type of "AutomaticReset" |
harvesterPeriod |
Harvester sampling period in millis |
|
targets |
Comma-separated list of target names to deploy the configured WLDFSystemResourceMBean to |
|
wldfResource |
'mywldf' |
The name of the WLDFSystemResourceMBean that will be configured by the scripts |
Notification Scripts Usage
You will notice that there are two scripts that can be used to create common WLDF notification types, one for SMTP (email) notifications, and one for SNMP trap notifications. They are "createSMTPNotification.py" and "createSNMPNotification.py", respectively.
These scripts take the following common parameters:
Parameter Name |
Default Value |
Description |
user | "weblogic" |
Username used to connect to the server |
pass |
"weblogic" |
Password used to connect to the server |
url |
"t3://localhost:7001" |
Connection URL |
targets |
Comma-separated list of target names to deploy the configured WLDFSystemResourceMBean to | |
wldfResource |
'mywldf' |
The name of the WLDFSystemResourceMBean that will be configured by the scripts |
In addition to the common parameters above, the createSMTPNotification.py scripts takes the following additional parameters:
Parameter Name |
Default Value |
Description |
sessionName | None |
The name of the MailSessionMBean to create for sending SMTP notifications; if not provided, no MailSessionMBean will be created. |
sessionJNDIName |
"mail/mymailSession" |
The MailSession JNDI name to allow it to be looked up by the notification service |
sessionProps |
"mail.user=foo;mail.host=mymail.com" |
The properties for the javax.mail.MailSession instance; these are the properties used to connect to the SMTP server |
name |
"mysmtpNotif" |
The name of the WLDF SMTP notification instance to create |
recipients |
'bar@mymail.com' |
The comma-separated list of recipients for the notification email |
In addition to the common parameters, the createSNMPNotification.py scripts takes the following additional parameters:
Parameter Name |
Default Value |
Description |
trapDestName | None |
The name of the SNMP trap destination to create for sending SMTP traps; if not provided, no trap destination will be created |
trapPort | 4000 |
The port for the remote SNMP trap destination; only used if a trapDestName is provided to create a trap destination |
name |
"mysnmpNotif" |
The name of the SNMP notification instance to create |
You can use these to create SNMP and SMTP notifications in WLDF, and then pass the notification instances to the profile scripts. For example,
$ java weblogic.WLST createSMTPNotification.py sessionProps="mail.user=joeblow;mail.host=acme.com" \
sessionName='acmeMailServer' jndiName='mail/acmeMail' recipients="administrator@acme.com" name=acmeNotif targets=myserver
$ java weblogic.WLST createSMTPNotification.py jndiName="mail/acmeMail" recipients="administrator@bar.com" name=barNotif
$ java weblogic.WLST enableAllProfiles.py notifications=acmeNotif,barNotif targets=myserver
will do the following:
- create the the "acmeMailServer" MailSessionMBean on JNDI name "mail/acmeMail"
- target the mail session to "myserver"
- create the SMTP notification 'acmeNotif' with recipient "administrator@acme.com" in the WLDF System Resource 'mywldf'
- create the SMTP notification 'barNotif' with recipient "administrator@bar.com" in the WLDF System Resource 'mywldf', using the same 'acmeMailServer' MailSession for transport
- enable all profiles, using the created WLDF notifications above for all Watch rule notifications
Class Descriptions
The following table describes the different Jython utility classes available in the provided modules.
Class |
Module | Description |
WLDFResource |
WLDFResource.py | Wrappers the WLDFSystemResourceMBean and provides functionality to simplify configuring and interacting with it |
Accessor | WLDFResource.py |
Utility class for peforming WLDF Accessor queries from the WLST environment |
WLDFUtils |
WLDFResource.py | Set of utility functions for performing other WLDF functions, such as enabling or disabling debug attributes and scopes, configuring SNMP, and creating a MailSession (for WLDF Notifications) |
WLSCoreProfile, WLSEJBProfile, WLSJDBCProfile, WLSJMSProfile, WLSJTAProfile, WLSWebAppProfile, WLSWebServicesProfile |
WLDFProfiles.py |
Profile implementation classes |
WLDFProfileBase |
WLDFProfiles.py |
Base class for implementing a profile instance; implements the contract implicitly defined in WLDFProfileManager |
WLDFProfileManager | WLDFProfiles.py | Responsible for applying a set of profile objects to a WLDFResource object |
Profile Object Structure
The provided profile objects can be modified by modifying the profile classes directly, or implementing your own. A profile object defines the properties for a set of WLDFHarvestedTypeBean definitions, a set of Watch rule configurations, and a set of server-scoped instrumentation monitors.
All configurations are represented in a Profile object as maps:
- A map of arrays of harvested attributes, keyed by the MBean type to harvest from
- A map of Watch rules, keyed by watch name, where the payload is a map of Watch properties
- A map of Instrumentation monitors, keyed by monitor name, where the payload is a map of monitor properties
The structure of the harvested types map consists of
{ typeName1 : [ attribute1, attribute2, ... ]
typeName2 : [ attribute1, attribute2, ... ]
...
}
and the structure of the Watch rules configuration map consists of
{ watchName1 : { watchName1-props-map }
watchName2 : { watchName2-props-map }
...
}
where each watch rule properties map can consist of the following key/value pairs:
Property Name |
Default Value |
Description |
rule |
The watch rule expression | |
ruleType |
'Harvester' |
The watch rule type (can be one of either 'Harvester', 'Log', or 'EventData') |
resetType |
None |
The watch alarm type (either 'ManualReset' or 'AutomaticReset' |
resetPeriod |
60000 |
The reset period for 'AutomaticReset' alarm types, in millis |
The structure of the Instrumentation monitors configuration map consists of
{ monitorName1 : { monitorName1-props-map }
monitorName2 : { monitorName2-props-map }
...
}
where each monitor properties map can consist of the following key/value pairs:
Property Name |
Default Value |
Description |
props |
The monitor properties (currently used by the DyeInjection monitor only) |
|
desc |
'Harvester' |
Monitor textual description to store in the configuration |
dyeMask |
None |
A string containing a comma-separated list of dye masks to filter on, if filtering is enabled (USER1, ADDR1, etc) |
dyeFiltering |
false |
For downstream monitors, whether or not to fire only on matching dye filter critera in the DiagnosticContext |
actions |
None |
A Python list of the names of Instrumentation actions to use with the monitor |
You can look at the existing profile classes for examples of these structures.
Customizing a Profile
If you want to customize any of these profiles, you can do one of the following:
- Subclass and override the settings
- Modify the existing profile classes
- Define your own profile class
"Rolling Your Own"
If you choose to define your own profile class, you can use the others as an example. In order to avoid any problems with ensuring that you implement the contract expected by the WLDFProfileManager correctly, you can subclass WLDFProfileBase and set the member fields watches and attributes accordingly.
However, a profile does not need to implement this base class; if it does not, it must provide the same public interface methods to meet the contract defined and used by the WLDFProfileManager class, namely, implementing the following methods:
- getHarvestedAttributes()
- getWatchRules()
These must return map structures as described above in the beginning of the "Customizing a Profile" section. As Python/Jython is not type-safe, there's no way to enforce this ahead of time, and any errors will be discovered only at runtime. It is therefore recommended that you subclass the WLDFProfileBase class and override the member definitions.
Chaining Profiles
You can combine mutliple profiles together as shown in the chainedProfilesExample.py script.
Programmatically Applying Profiles
The class WLDFProfileManager is used to apply a list of profiles to a WLDFSystemResourceMBean instance. If you want to combine a set of profiles together, you can do so in the following manner (note the highlighted text):
execfile('WLDFProfiles.py')
argsDict = argsToDict(sys.argv)
connectIfNecessary(argsDict)
cd ("edit:/")
startEdit()
try:
# obtain the WLDFSystemResourceMBean
wldfResName = getValue(argsDict, 'wldfResource', 'mywldf')
wldfRes = WLDFResource(wldfResName)
profiles = [ WLSJTAProfile(), WLSWebAppProfile(),
WLSWebServicesProfile() ]
profileMgr = WLDFProfileManager(wldfRes, argsDict, profiles)
profileMgr.apply()
save()
activate()
....
The above snippet does the following:
- does an execfile of WLDFProfiles.py to bring all the classes defined in that module and in WLDFResource.py into the WLST namespace
- creates a python dictionary from the command-line options using a utility method defined in WLDFResource.py
- connects to the server if necessary (also using a utility method defined in WLDFResource.py)
- creates an instance of a WLDFResource
- creates an list of profile objects (namely, WLSJTAProfile, WLSWebAppProfile, and WLSWebServicesProfile)
- creates a WLDFProfileManager instance with this list and the set of arguments applied to the script
- calls apply() on the WLDFProfileManager instance to apply the profile to the WLDFSystemResourceMBean; note that the WLDFProfileManager will create the WLDFSystemResourceMBean referenced by the WLDFResource object if necessary, targeting the resource if targets are specified in the arguments dictionary (see the "Usage" section above for the expected dictionary keys and their expected values)
Note that you can create your own dictionary of arguments; you do not need to use them command-line arguments, i.e.,
argsDict = { "user" : "foo", "pass" : "bar", "url" : "t3://myhost:9010", "wldfResource" : "myWLDFProfile" }
For a working example of this, look at enableAllProfiles.py.
Programmatically Unapplying a Profile
If you wish to remove a profile from a WLDF configuration, you do it similarly to the manner in which it is applied, except that you call unapply() on the WLDFProfileManager instance:
execfile('WLDFProfiles.py')
argsDict = argsToDict(sys.argv)
connectIfNecessary(argsDict)
cd ("edit:/")
startEdit()
try:
# obtain the WLDFSystemResourceMBean
wldfResName = getValue(argsDict, 'wldfResource', 'mywldf')
wldfRes = WLDFResource(wldfResName)
profiles = [ WLSJTAProfile(), WLSWebAppProfile(),
WLSWebServicesProfile() ]
profileMgr = WLDFProfileManager(wldfRes, argsDict, profiles)
profileMgr.apply()
save()
activate()
....
For a working example of how to do this, look at disableAllProfiles.py.
Feedback
This set of utilities and profile definitions should not be considered absolute. They are the result of feedback from users and internal BEA Professional Services and Support staff. If you feel that the profiles here, or the utilities, do not meet your needs, or could otherwise be enhanced, please let us know! We encourage and welcome feedback into this process.
You can contact the WLDF team with any problems or suggestions through the Dev2Dev newsgroups, or through BEA support channels.
Thanks, and we hope you find this useful!