Showing posts with label WLST online. Show all posts
Showing posts with label WLST online. Show all posts

Monday, December 17, 2012

Monitoring JDBC Datasource Runtime Attributes using WLST

In weblogic server , we can monitor the JDBC resources easly with WLST.

See how can ?
Step 1 :- Set the environment
C:\bea103\user_projects\domains\testdomain\bin>setDomainEnv.bat
Step 2:- Connect to server and browse to the JDBCDataSourceRuntime MBean
C:\bea103\user_projects\domains\testdomain>java weblogic.WLST
Initializing WebLogic Scripting Tool (WLST) …
Welcome to WebLogic Server Administration Scripting Shell
Type help() for help on available commands
wls:/offline> connect()
Please enter your username [weblogic] :
Please enter your password [weblogic] :
Please enter your server URL [t3://localhost:7001] :t3://localhost:7003
Connecting to t3://localhost:7003 with userid weblogic …
Successfully connected to managed Server ‘MS0′ that belongs to domain ‘testdomain′.
Warning: An insecure protocol was used to connect to the
server. To ensure on-the-wire security, the SSL port or
Admin port should be used instead.
wls:/testdomain/serverConfig> serverRuntime()
Location changed to serverRuntime tree. This is a read-only tree with ServerRunt
imeMBean as the root.
For more help, use help(serverRuntime)
wls:/testdomain/serverRuntime> cd(‘JDBCServiceRuntime’)
wls:/testdomain/serverRuntime/JDBCServiceRuntime> cd(‘MS0′)
wls:/testdomain/serverRuntime/JDBCServiceRuntime/MS0> cd(‘JDBCDataSourceRuntimeMBeans’)
wls:/testdomain/serverRuntime/JDBCServiceRuntime/MS0/JDBCDataSourceRuntimeMBeans> cd(‘MyDs’)
gaRules> cmo.getActiveConnectionsCurrentCount()
1
The other JDBC Datasource Runtime attributes that can be monitored are listed below.
wls:/testdomain/serverRuntime/JDBCServiceRuntime/MS0/JDBCDataSourceRuntimeMBeans/PegaRules> ls()
dr– JDBCDriverRuntime
dr– LastTask
dr– WorkManagerRuntimes
-r– ActiveConnectionsAverageCount 1
-r– ActiveConnectionsCurrentCount 0
-r– ActiveConnectionsHighCount 5
-r– ConnectionDelayTime 627
-r– ConnectionsTotalCount 5
-r– CurrCapacity 5
-r– CurrCapacityHighCount 4
-r– DeploymentState 2
-r– Enabled true
-r– FailedReserveRequestCount 0
-r– FailuresToReconnectCount 0
-r– HighestNumAvailable 5
-r– HighestNumUnavailable 0
-r– LastTask null
-r– LeakedConnectionCount 0
-r– ModuleId PegaRules
-r– Name PegaRules
-r– NumAvailable 5
-r– NumUnavailable 0
-r– PrepStmtCacheAccessCount 11852
-r– PrepStmtCacheAddCount 420
-r– PrepStmtCacheCurrentSize 50
-r– PrepStmtCacheDeleteCount 370
-r– PrepStmtCacheHitCount 11432
-r– PrepStmtCacheMissCount 420
-r– Properties {serverName=localhost, SID=prpc612, portNumber=1521, user=SYSTEM}
-r– ReserveRequestCount 11844
-r– State Running
-r– Type JDBCDataSourceRuntime
-r– VersionJDBCDriver oracle.jdbc.OracleDriver
-r– WaitSecondsHighCount 0
-r– WaitingForConnectionCurrentCount 0
-r– WaitingForConnectionFailureTotal 0
-r– WaitingForConnectionHighCount 0
-r– WaitingForConnectionSuccessTotal 4
-r– WaitingForConnectionTotal 0
-r– WorkManagerRuntimes null
-r-x clearStatementCache Void :
-r-x dumpPool Void :
-r-x dumpPoolProfile Void :
-r-x forceShutdown Void :
-r-x forceSuspend Void :
-r-x poolExists Boolean : String(name)
-r-x preDeregister Void :
-r-x reset Void :
-r-x resume Void :
-r-x shrink Void :
-r-x shutdown Void :
-r-x start Void :
-r-x suspend Void :
-r-x testPool String

Easy Syntax with WLST

WLST is a powerful scripting solution for managing and administering WebLogic Server and resources deployed on them. WLST is built on the Java implementation of the scripting language Python called as Jython.

 All the commands in WLST are implemented as Jython functions and they require a set of parentheses for passing any arguments. Even any commands that do not require any arguments are supposed to be suffixed with parentheses. For example the command "ls" is used to list all the child MBeans and/or attributes of the current MBean you are at.

ls() - lists all the child MBeans and attributes
ls('a') - lists all the attribute names and values only
ls('c') - lists all the child MBeans only

So even if you want to invoke "ls" with no arugments you must use "ls()". This might not be an issue when you are building scripts that you might want to run many times. But while connected to a server and working with WLST in interactive mode, it might get a little frustated to type the parentheses everytime you want to run some simple commands with no arguments. To ease this pain there is a hidden option in WLST which can be used to ease the syntax for WLST commands - easeSyntax().



You can supply the "easeSyntax()" command to ease the syntax but this is not recommended for script mode and especially when using loop constructs. You can also use the regular Jython syntax with parentheses even after you enabled the easy syntax. To turn off the easy syntax mode simply issue the command again "easeSyntax".

How To Encrypt Clear Text Passwords With WebLogic Server

WebLogic Server encrypts all the plain text passwords stored in its domain configuration XML file(s). This is to prevent access to sensitive information. When passwords are entered using administration console or scripting tools, it will automatically get encrypted before they are stored in the configuration XML files(s).

Prior to WebLogic Server 9.0

If those passwords need to be reset either the configuration tools (Console or scripting tools) can be used which will automatically re-encrypt the passwords or by directly changing the configuration files using a text editor. When files are directly modified using a text editor the passwords will get encrypted during the subsequent restart.

Starting from WebLogic Server 9.0

Using clear text passwords in the configuration files are supported only for Development domain and it will not re-encrypt the passwords. If the domain is a Production domain then you cannot set the passwords in clear text. You have to either use a dedicated command-line utility or WLST to encrypt the clear text passwords. If the server encounters a clear text password when parsing the configuration file(s) while starting in Production Mode, then you will get an error similar to the following:

<Oct 20, 2008 9:05:35 PM EDT> <Critical> <WebLogicServer> <BEA-000362> <Server failed. Reason: [Management:141266]Parsing Failure in config.xml: java.lang.IllegalArgumentException: In production mode, it's not allowed to set a clear text value to the property: PasswordEncrypted of ServerStartMBean>


Depending on the configuration the MBean name value of the error message may change. In this case the ServerStartMBean has clear text value for a password property. Either the dedicated Java utility to encrypt clear text values can be used or WLST cant be used to re-encrypt. To run the encrypt utility follow the instructions below:


  1. Change directory to your domain's bin folder (For Eg. cd c:\bea\user_projects\domains\mydomain\bin)
  2. Execute the setDomainEnv script (For Eg. setDomainEnv.cmd)
  3. Execute java weblogic.security.Encrypt which will prompt for the password and will print the encrypted value in stdout.
The following are some sample output from running the utility

C:\bea\user_projects\domains\mydomain>java weblogic.security.Encrypt
Password:
{3DES}9HWsf87pJTw=

You should execute this utility from the domain folder as it requires the domain's password salt file (SerializedSystemIni.dat) for encrypting the clear text string. You can also pass the clear text string as an argument

C:\bea\user_projects\domains\mydomain>java weblogic.security.Encrypt testpwd
{3DES}9HWsf87pJTw=


You can also use WLST to encrypt clear text strings as below:

C:\bea\user_projects\domains\mydomain>java weblogic.WLST

Initializing WebLogic Scripting Tool (WLST) ...

Welcome to WebLogic Server Administration Scripting Shell

Type help() for help on available commands

wls:/offline> es = encrypt('testpwd')
wls:/offline> print es
{3DES}9HWsf87pJTw=
wls:/offline>

When running WLST from a location different than the domain folder you can pass in an argument to specify the domain directory. Once you have the encrypted value, the configuration files can be modified to include this encrypte value instead of clear text passwords. These features will make your domain to operate when resetting the encrypted passwords on a Production domain's configuration XML files. These methods not only can be used to encrypt configuration XML (config.xml) but also the JDBC or JMS descriptor XML files.

Starting Managed Servers without an Administration Server using Node Manager and WLST


Weblogic 12c


The steps for starting the Managed  Server without AdminServer using WLST and Node Manager are as follows :
i)  Setting up your environment.
Add WebLogic Server classes to the CLASSPATH environment variable and WL_HOME\server\bin to the PATH environment variable.  OR
You can use a  C:\Oracle\Middleware\wlserver_12.1\server\bin\setWLSEnv.cmd  script to set both variables.

ii)  Start WLST Session using command : java weblogic.WLST
iii)  Start Node Manager using command :
                         startNodeManager(verbose=’true’, NodeManagerHome=’C:\\Oracle\\Middleware\\wlserver_12.1\\common\\nodemanager’, ListenPort=’5556′, ListenAddress=’localhost’)
iv) Connect WLST to a Node Manager by entering the nmConnect command.
nmConnect(‘weblogic’, ‘weblogic123′, ‘localhost’, ’5556′, ‘base_domain’ , ‘C:\\Oracle\\Middleware\\user_projects\\domains\\base_domain’ , ‘ssl’)
note: Node Manager security relies on a one-way SSL connection between the client and server.If you are establishing a command line connection to the Java Node Manager using the WebLogic Server Scripting Tool (WLST) nmConnect command, you provide the Node Manager user name and password(here weblogic and weblogic123 respectively). Node Manager verifies the username and password against the domain’s nm_password.properties file.Node Manager credentials are located on the Security>General>Advanced Options of Console page.Administration Console users do not need to explicitly provide credentials to connect to Node Manager—the Node Manager user name and password are available in the domain configuration and are provided automatically.
v) Starts the managed server in the current domain using Node Manager. : nmStart('Server-0')


 Related Common Issues :


If you are trying to automate the environment using Node Manager and WLST .
And you are trying to Start the Admin Server and all the Managed Server using WLST only.
And the Managed servers are to be started for the first time using WLST and Node Manager then you may encounter the below error :


<Info> <Security> <BEA-090906> <Changing the default Random Number Generator in RSA CryptoJ from ECDRBG to FIPS186PRNG. To disable this change, specify -Dweblogic.security.allowCryptoJDefaultPRNG=true> 
<Info> <WebLogicServer> <BEA-000377> <Starting WebLogic Server with Java HotSpot(TM) 64-Bit Server VM Version 20.1-b02 from Sun Microsystems Inc.> 
<Info> <Management> <BEA-141107> <Version: WebLogic Server 10.3.4.0 Fri Dec 17 20:47:33 PST 2010 1384255 > 
<Critical> <WebLogicServer> <BEA-000362> <Server failed. Reason: 

There are 1 nested errors:

weblogic.management.ManagementException: Booting as admin server, but servername, soa_server1, does not match the admin server name, AdminServer
at weblogic.management.provider.internal.RuntimeAccessService.start(RuntimeAccessService.java:67)
at weblogic.t3.srvr.ServerServicesManager.startService(ServerServicesManager.java:461)
at weblogic.t3.srvr.ServerServicesManager.startInStandbyState(ServerServicesManager.java:166)
at weblogic.t3.srvr.T3Srvr.initializeStandby(T3Srvr.java:879)
at weblogic.t3.srvr.T3Srvr.startup(T3Srvr.java:566)
at weblogic.t3.srvr.T3Srvr.run(T3Srvr.java:467)
at weblogic.Server.main(Server.java:71)

Cause :

The reason for the above error is that when the Managed Server are to be started for the first time using the Node Manager and WLST,  the boot.properties file ( at %domain_home%/servers/ManagedServer/security/) and startup.properties file ( %domain_home%/servers/ManagedServer/data/NodeManager/) should be already present.

Solution :

To generate the boot.properties file , and startup.properties file use the below WLST command :
 nmGenBootStartupProps('ms1') 

Disabling and enabling the Weblogic Administration Console


To disable:
1. Select your domain name in the Domain Structure panel of the console(as base_domain below).

2. Select Configuration | General, and click Advanced at the bottom of the page, and unselect Console Enabled.

OR
Using WLST:-
connect(“username”,”password”)
edit()
startEdit()
cmo.setConsoleEnabled(false)
save()
activate()
disconnect()
exit()

3. To enable, you can use WLST. The following code shows how to do it:
connect(“username”,”password”)
edit()
startEdit()
cmo.setConsoleEnabled(true)
save()
activate()
disconnect()
exit()

Thread Dumps in WebLogic12c Server


Here going to provide information about different ways on taking java thread dumps in a WebLogic Server environment.
Thread dumps are very useful to analyze and troubleshoot performance related issues such as server hang, deadlocks, slow running, idle or stuck applications,  etc.
Different ways to take thread dumps in WebLogic Server
Always prefer Operating system(OS) commands rather instead of Admin Console or Java Classes, because if the console is hanging, users won’t be able to connect to it to issue thread dumps.
1. OS Commands for Thread Dumps
i) On Windows,
<ctrl>+<break> — the thread dumps are generated in the server stdout
ii) On Solaris / Linux
first identify the process ID (pid) using   ps -ef | grep java, then run   kill -3 <pid> td_filename 2>&1
2. Using weblogic.WLST ( work only from WLS 9.x onwards)
First set CLASSPATH using setDomain.cmd or setDomain.sh (wlst.sh /wlst.cmd will also do in path C:\Oracle\Middleware\wlserver_12.1\common\bin ). Then run below command
java weblogic.WLST ThreadDumps.py
save below code in ThreadDumps.py file:
connect(“<username>”,”<password>”,”t3://<url>:<port>”)
cd(‘Servers’)
cd(‘AdminServer’)
threadDump()
disconnect()
exit()
threadDump()
The thread dumps get stored in the location from where you run it.
3. From Weblogic Administration Console
navigating to Server -> <server_name> -> Monitoring -> Dump threads stack.
4. From the JRockit Command line
jrcmd <pid> print_threads

Site Performance Testing


There are a number of approaches to getting performance metrics for a web site. Ultimately web site performance should be best gauged by the page response within a client browser.

Using a collection of available tools such as Firefox, Firebug and Harlog you can get a realistic baseline of your expected site performance. This approach leverages Firefox and Firebug to collect data on site performance. Using Firebox to fetch pages from the site gives results that would be similar to those seen by visitors. Firebug is used to collect detailed metrics on page performance.  NetExport is a plug-in for Firebug that lets to send Firebug results to a data receiving service. Harlog is used as a data reciever to  collect metrics and to generate a tab delimited file that can be used to generate reports in Excel or another reporting tool.

Install Firefox, Firebug, NetExport and Harlog on a test PC.

Setup Harlog by downloading the latest files from http://www.imagossoftware.com/harlog/ and copying them into a suitable directory. For this example I will use c:\harlog. Create a directory under c:\harlog also called logs. Edit the HarLog.exe.config file and create a series of XML format settings between the tags. These settings are:

<add key=”directory” value=”C:\harlog\logs”/>
<add key=”output” value=”c:\harlog\results.txt”/>
<add key=”header” value=”all”/>
<add key=”style” value=”basic”/>

Now you can run the HarLog.exe with a -w switch to run as a mini-web server.
Now launch Firefox, and go to about:config (this will allow you to change the beacon URL for NetExport to send data to HarLog). Find the preference setting for extensions.firebug.netexport.beaconServerURL and if you have installed HarLog locally set the value to http://localhost:9090/ also set extensions.firebug.netexport.autoExportToServer to true. If are running HarLog on another PC or port set the address appropriately.

Next launch Firefox go to your test site, and open the Firebug window and go to the Net panel. Under the “Export” activate “Auto Export”. This will send the results from the Firebug Net “waterfall” to HarLog each time a page from the site is loaded.

When you have completed your testing, import the “results.txt” file into Excel or another reporting application to format and or chart your site results.

Site Performance Testing (Part 2) – Weblogic


Jvisualvm is a great tool for looking at various aspects of Java application performance. When you are running your application on an application server such as Weblogic it can be more difficult to use. The steps below allow you to attach Jvisualvm to a remote instance of Weblogic
You either need to run jstatd on the remote side, or specify a JMX connection using host:port.

Jstatd:
jstatd -J-Djava.security.policy=permissions.txt [-p port]
After that: add a remote connection to the target machine, and on the properties of that remote connection configure the jstatd connection.
(permissions.txt contains for example this:
grant {
  permission java.security.AllPermission;
};
  1. ssh -D 9696 me@remote, and run jstatd as above on the remote command line. If you want jstatd to be on a different port than the default 1099, use the -p argument to jstatd.
  2. run visualvm.exe -J-Dnetbeans.system_socks_proxy=localhost:9696 -J-Djava.net.useSystemProxies=true on the local machine
in visual vm: add new remote connection, and specify remote as host and the port for jstatd (1099 for default, or what you specified with -p when running jstatd)
You should now see the processes on the remote side in visualvm

To connect JMX to weblogic

Add the following JVM parameters to your Weblogic startup scripts:
-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8888 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false
and restart the server. 

You’ll be able to connect remotely via JConsole/VisualVM/etc at host:8888 then

Steps to reset console password on WLS 8x :


In the example below we are creating a new console user and password in WLS 8x :
Below are the steps for password recovery  :
STEP 1 :  Firstly, Stop the server if running and make sure that weblogic.jar is in the classpath.
STEP 2 : Open a command prompt and navigate to ” D:\bea816\user_projects\domains\mydomain “  and run “setEnv.cmd “
STEP 3 : Now run the following command :
“Java weblogic.security.utils.AdminAccount NewAdminUser NewAdminPassword . “
where ” NewAdminUser ” and ” NewAdminPassword ” are the new user and password you would like to create.
Note : The “ . “ (period) at the end of the command is very important..!! as it tells the command that this should be run in the domain directory.
STEP 4 : The above command creates a file “ DefaultAuthenticatorInit.ldift “ in the domain directory. ( as shown below )
.

STEP 5 : Delete the file “ DefaultAuthenticatormyrealmInit.initialized “ located in D:\bea816\user_projects\domains\mydomain\myserver\ldap “
STEP 6 : Clear the contents of boot.properties file located in ” D:\bea816\user_projects\domains\mydomain “
STEP 7 : Now start the server and login with the new user and password.