Search This Blog

Oracle Fusion Middleware Administration Course

Oracle Fusion Middleware Administration Course
OFMW Admin Course

Saturday, November 14, 2009

JMS Monitoring using WLST

Let me walk through the script, The script is referring to a secure way of user credential usage in the WLST that is given here .

storeUserConfig() command in WLST can generates 2 file suserKeyFile, userConfigFile. These we can use multiple times in the script so I declared it on the top, Global scope variables, which can be used by any method in the script.
Coming to downside of the script, where you can find the main program logic. We need to understand from the main program onwards that is the good programmer reading habit :).

In the main module we don't want to see unnecessary data while running the script just want to see , so redirect useless data. first connect to the admin server in the domain.

Initialization of the URL dictionary for multiple server instances domain. The JmsStat module will tell you the actual status of each JMSRumtime Mbeans.

Here I got two hurdles the all script output is not from same MBean. I need to display the JMS statics from JMSRuntime MBean and need to navigate to the instance's specific JMS.

The list (ls) content need to store in variable and need to cding (cd)
myJmsls=ls(returnMap='true')

This makes turning point for the following script we surf for this found Satya Gattu Answer in ObjectMix.

Here (myJmsls) variable holds the value into list datastructure. Just by pointing index the value will be returned.

################################################################# 
# This script will  get the jms attributes
# Author : Prasanna Yalam
# Updated by: Pavan Devarakonda
################################################################# 

from java.util import Date

ucf='ursec'
ukf='urkey'
admurl='t3://url'
urldict={}

def conn():
try:
 connect(userConfigFile=ucf, userKeyFile=ukf, url=admurl)
except ConnectionException,e:
 print 'Unable to find admin server...'
 exit()
def initalize():
 serverlist= ['app010','app011',...]
 for svr in serverlist:
 cd("/Servers/"+svr)
 urldict[svr]='t3://'+get('ListenAddress')+':'+str(get('ListenPort'))

def JmsStat():
 d = Date() # now
 print  d 

 print 'Instance         ConCur ConHi ConTot High  MsgCur MsgPnd'
 print 'Name             Count  Count Count  Count Count  Count'
 print '===========**=======**==================================' 
 Ks = urldict.keys()
 Ks.sort()

 for key in Ks:
  try:
   connect(userConfigFile=ucf, userKeyFile=ukf,url=urldict[key])
   serverRuntime()
   cd('JMSRuntime/'+key+'.jms/JMSServers')
   curCnt= get('ConnectionsCurrentCount')
   cHiCnt=get('ConnectionsHighCount')
   cTotCnt=get('ConnectionsTotalCount')

   myJmsls=ls(returnMap='true')
   x=myJmsls[0]
   cd(x)

   hiCnt= get('MessagesHighCount')
   currCnt= get('MessagesCurrentCount')
   pendCnt= get('MessagesPendingCount')
   print '%14s   %4d   %4d  %4d  %4d  %4d  %4d' %  (key, curCnt, cHiCnt, cTotCnt,  hiCnt, currCnt, pendCnt) 
  except:
   print 'Exception...in server:', key
   pass
 quit()

def quit():
 d = Date() # now
 print  d
 print 'Hit any key to Re-RUN this script ...'
 Ans = raw_input("Are you sure Quit from WLST... (y/n)")
 if (Ans == 'y'):
  disconnect()
  stopRedirect() 
  exit()
else:
 JmsStat()

if __name__== "main":
 redirect('./logs/jmsCnt.log', 'false')
 conn()
 initalize()
 JmsStat()

Wednesday, October 28, 2009

Dynamic Domain creation with WLST

Introducing Dynamism

Hey all wise WLA welcome to this exclusive WLST blog again!

My dear buddies, this week I was invited  for a discussion on generic and dynamic domain creation in WebLogic for a development environment. The need of a script that is generic in the sense not specific to any operating environments such as Solaris, Linux, Windows or Mac. And, It should prompt for all the desired inputs to build a basic WebLogic domain in a development environment.

It looks like some what interactive and can be dynamic.

After looking into many search engines we did not get any generic or dynamic one. We took this from some part of the script from WebLogic forums and some from python forums. Finally got into conclusion that you need few lines of python required for Operating environment details to fetch from the system.


Why Dynamic Domain Script?


  • The richness of this script is that,  you can use this for your environment directly.
  • This is reusable script.
  • It is for time saving compare to the regular config.sh execution
  • ease of use script
  • You can execute on Windows same script can run on Solaris without any changes
We also experimented this same script executed in WebLogic 9.x version and again in WebLogic 11g also successfully. So this dynamic and generic domain configuration script publishing for the all who want to explore the WLST with their experiments.


Prerequisites and preparation



To execute this script you must define the following:

1. JAVA_HOME define this from WebLogic installation paths
2. WL_HOME define this as WebLogic installation
3. CLASSPATH must have weblogic.jar for running weblogic.WLST
4. PATH must contain JAVA_HOME/bin to run java commands
After setting these you can verify above with echo each environment variable. In Nix platform you can try as:
echo $PATH 
echo $CLASSPATH
echo $WL_HOME
echo $JAVA_HOME
In Windows you can verify it by replace $ with % symbol.

###########################################################
# This script will dynamically create the domain as per your inputs
# Run on : Oracle WebLogic 8.1, 9.2 10.3 (11g)
# Author : Pavan Devarakonda
###########################################################

import os

WLHOME=os.environ['WL_HOME']

#==========================================
# Create a domain from the weblogic domain template.
#==========================================
readTemplate(WLHOME+'/common/templates/domains/wls.jar')
cd('Servers/AdminServer')
AdminName=raw_input('Please Enter Admin ServerName: ')
set('Name',AdminName)
#==========================================
# Configure the Administration Server
#==========================================
AdminListenAdr=raw_input('Please Enter Admin Listen Address: ')
AdminListenPort=int(input('Please enter Admin listen Port: '))

set('ListenAddress',AdminListenAdr)
set('ListenPort', AdminListenPort)

#====================================================
# Define the password for user weblogic. You must define the password before you
# can write the domain.
#====================================================
cd('/')
cd('Security/base_domain/User/weblogic')
usr=raw_input('Please Enter AdminUser Name: ')
set('Name',usr)
AdminPassword=raw_input('Please enter Admin password:')
cmo.setPassword(AdminPassword)

# - OverwriteDomain: Overwrites domain, when saving, if one exists.
setOption('OverwriteDomain', 'true')

#==============================================
# Write the domain, close template and finally exit from the WLST
#==============================================
domainPath=raw_input('Enter the domain path: ')
domainName=raw_input('Enter domain name: ')
print 'Given domain path, name : ', domainPath, domainName
writeDomain(domainPath+"/"+domainName)
closeTemplate()
exit()


Sample Execution
Assume that you saved the above script with the name as "createDomain.py". Of course you can choose your own name for the script!
At your command prompt you can invoke this script as follows:

[WLA@server~/.AdminScripts]$ java weblogic.WLST createDomain.py 
 
Initializing WebLogic Scripting Tool (WLST) ...
 
Welcome to WebLogic Server Administration Scripting Shell

Type help() for help on available commands
 
Please Enter Admin ServerName: testAdmin
Please Enter Admin Listen Address: 127.0.0.1
Please enter Admin listen Port: 8007
Please Enter AdminUser Name: system
Please enter Admin password:weblogic103
Enter the domain path: /home/wluser/domains/    
Enter domain name: testdomain
Given domain path, name :  /home/wluser/domains/testdomain
 
Exiting WebLogic Scripting Tool.
 
[WLA@server~/.AdminScripts]$ cd ../domains
[WLA@server~/domains]$ ls 
nmdomain103    testdomain

If you want the same thing without interactive mode, you just want to change the values you don't want to change the Python script for customizing your WebLogic domain then you can use properties file as shown below:

# File: myWLSTdom.properties
domainTemplate=c:/wls12c/wlserver/common/templates/domains/wls.jar

#Following property is the default property and should not be changed.
weblogicdomainpasspath=Security/base_domain/User/weblogic

adminUser=weblogic
adminPassword=weblogic123$


adminServerName=admin_myWLSTdom
adminServerListenaddr=localhost
admlistenport=7100

OverwriteDomain=true
domainName=myWLSTdom
domainHome=/wldomains/myWLSTdom

Creating WLST base domain


Now let use the properties file and have simple adminserver configurations can be customized with set function.

loadProperties('myWLSTdom.properties')
readTemplate(domainTemplate)

def printInStyle(txt):
 print'-'*10 +txt
 
cd('Servers/AdminServer')
printInStyle('Give your custom AdminServer name')
set('Name',adminServerName)

printInStyle('Set the ListenAddress and ListenPort')
set('ListenAddress',adminServerListenaddr)
set('ListenPort', int(admlistenport))

# Security
printInStyle('Creating Password')
cd('/')
cd(weblogicdomainpasspath)
cmo.setPassword(adminPassword)

printInStyle('Setting StartUp Options')
setOption('OverwriteDomain', OverwriteDomain)

# Create Domain to File System
printInStyle('Writing Domain To File System')
# Change the path to your domain accordingly
writeDomain(domainHome)
closeTemplate()
# Exiting
print('Exiting now...')
exit()

Little cosmotizing with function 'printInStyle', here we can give any symbol then we can have multiple times the number you postfix to the '*'. In the above we had 10 times '-' symbol is printed then the text message.

C:\pbin>java weblogic.WLST -skipWLSModuleScanning create_basedomain.py

Initializing WebLogic Scripting Tool (WLST) ...

Welcome to WebLogic Server Administration Scripting Shell

Type help() for help on available commands

----------Give your custom AdminServer name
----------Set the ListenAddress and ListenPort
----------Creating Password
----------Setting StartUp Options
----------Writing Domain To File System
Exiting now...


Exiting WebLogic Scripting Tool.


Create Production Domain with WLST


A base WebLogic domain in production mode with generic option using properties file. If you compare with the above script this is having properties and more generic. We have experimented this script with Windows and Linux platforms.

readTemplate(TMPLATE)
cd('/')
cmo.setName(DOMAIN_NAME)
cd('Servers/AdminServer')
cmo.setListenAddress(ADMIN_LISTENADDRESS)
cmo.setListenPort(int(ADMIN_PORT))
cd( '/' )
cd( 'Security/'+DOMAIN_NAME+'/User/' +ADMIN_USER)
cmo.setPassword(ADMIN_PWD)
cd('/')
setOption("ServerStartMode", "prod")
setOption("OverwriteDomain", "true")

writeDomain( DOMAIN_DIR+’/'+DOMAIN_NAME )
closeTemplate()



Let me try with the WebLogic 11g version, if you have latest 12c then the domain template path changes as C:/Oracle/Middleware/wlserver/common/templates/wls/wls.jar
If you are using vagrant box use /home/vagrant/fmw/oraclehome/wlserver/common/teplates/wls/wls.jar
The sample properties file looks like this:

TMPLATE = 'C:/Oracle/Middleware/wlserver_10.3/common/templates/domains/wls.jar'
ADMIN_PORT = 8001 
ADMIN_PWD =  weblogic123
ADMIN_USER = weblogic
DOMAIN_DIR = C:/wlsdomains
DOMAIN_NAME = NC_DOMAIN
ADMIN_LISTENADDRESS = 192.168.1.18


java weblogic.WLST -loadProperties ncdomain.properties createproddomain.py

Confirmation of the Domain creation as following screen shot:

WebLogic production domain created with WLST




Suggestions and improvements

1. You can improve this script for Clustered environment.
2. You can add more functions for each resource configurations such as JDBC DataSource, JMS, and application deployment
3. Verifying the given domain path is also recommended
4. The python script must have exception handling I mean there should try: except: blocks to make more robust.

Buddy you can extend your domain template using pack and unpack commands.

Tuesday, June 30, 2009

Start timing of WebLogic instances

Here again I m concerned with regular reoccuring issues ... due to one of the issue the servers were bounced one of them at any time in the day...
Here is an oppurtunity to create a new script. The very first thing is a at what time the server instances were bounced, and there is manager need of knowing how many servers were bounced today.



WLST attribute 'ActivationTime' will give a time in the form of integer. That date can be converted to java.util.Date format.
The new learning is that easy to read the WLST script we can declare all constant values in a separate file which can be reused to other scripts too. The common, separate file is your properties file.
In WLST we have a wonder method called loadProperties(). This is defined for segrigating script with logic and all constants into properties which are loaded dynamically. We can load them while invoking the WLST script also.

Jython (Java utilities provides current day).
So I traced it with the little research on Jython date, string formating comparing server start date with the today date. The tuff part was that when I was printing integer with concatinating with string it is throwing exception. So don't use + symbol for concatinating int,string values.

The script goes like this...
Don't forget to indent the code..
#This script is for display the start time of instance
# and  it will also counts the number of WebLogic Server instances restarted today

from java.util import Date
from java.text import SimpleDateFormat
loadProperties(">
ud = {}  # This dictonary object is used in the getSite module
t = Date()  # Current date will be returned to t
searchday=SimpleDateFormat("dd").format(t) # extracting only day from the today date e.g:  Jul 3 2009 returns 3 here

redirect('./logs/urSiteStart.log', 'false')
def getSite(site):
srvlist=site.split(',')
# setting up the dictionary elements now...
for y in srvlist:
i=y.split('#')
ud[i[0]]=i[1]
return ud

def showMenu():
print '1: SITE1 \n2: SITE2\n3: SITE3\n .... '
print '0: Quit'
choice=raw_input('ENTER Site CHOICE:')
return choice

# The main script logic starts here...
while 1
site=int(showMenu())
if site == 1:
u=getSite(SITE1)
elif site == 2:
u=getSite(SITE2)
elif site == 3:
u=getSite(SITE3)
# Add as much sites(physical locations) you have in your domain...
else:
print 'exiting from the script now...'
disconnect()
stopRedirect()
exit()

restartCnt=0
for svr,surl in u.items():
try:
connect(userConfigFile=UCK, userKeyFile=UKF, url=surl)
serverRuntime()
strout=svr+' instance is stared @'+ SimpleDateFormat('d MMM yyyy HH:mm:ss').format(java.util.Date(cmo.getActivationTime()))
num_matches=strout.find(searchday)
print strout

if num_matches > 0:                     # a nonzero count means there was a match
restartCnt = restartCnt + 1
except:
print 'Exception...in server: \033[1;47;31m', svr, ' \033[0m'     
pass
print '\033[1;47;31mThere are ',restartCnt,  'instance(s) restarted today in this site\033[0m'
u.clear()


Sunday, May 24, 2009

Cosmotising your WLST output

Here I am with new idea that colored output according to the state of the Server.
Hope most of you(WLA) knows WLST script for displaying Server status, my idea is when the server state is in SHUTDOWN state let it display in red color, STARTING state in YELLOW, and geen for RUNNING state and so on... colors you can specify as per your choice. 

I ran thru google for searching colors in python... it is simple logic print instruction in python putting UNIX shell code way. The color code need to be prefix in the line where color need to appear in the output.



My choice of WLST is that it should have a provision to rerun the script if user wish to run the script after a while. this makes less time to get output because re-initializing of WLST is not required 

CODE Snippet:
#Fetch the state of the every WebLogic instance
        for name in serverNames:
                cd("/ServerLifeCycleRuntimes/" + name.getName())
                serverState = cmo.getState()
                if serverState == "RUNNING":
                        print 'Server ' + name.getName() + ' is :\033[1;32m' + serverState + '\033[0m'
                elif serverState == "STARTING":
                        print 'Server ' + name.getName() + ' is :\033[1;33m' + serverState + '\033[0m'
                elif serverState == "UNKNOWN":
                        print 'Server ' + name.getName() + ' is :\033[1;34m' + serverState + '\033[0m'
                else:
                        print 'Server ' + name.getName() + ' is :\033[1;31m' + serverState + '\033[0m'



Thursday, April 30, 2009

WLST Thread Count

WLST Thread Count in WebLogic 9.x and all higher version the Thread model is depends on WorkManager. The WorkManager internally uses self-tuning threads for each WebLogic Server instances.
-->

To get the thread Model and its Idle count as in the WebLogic 8.1 we need to tune the server instance parameter in the config.xml. While changing this you should be cautious,

 make sure you have  a backup copy the config.xml before editing.
Enter the following line in the child element, given same level as element.






Full detail description about how to change this parameter is given here...
http://download.oracle.com/docs/cd/E13222_01/wls/docs92/perform/appb_queues.html

The WLST script for Thread count monitoring will be as follows: 



######################################################
# This script is used to monitor all servers
# Author: Pavan Devarakonda
# Date:   28th April 2009
######################################################
import thread
 
# Configured user credentials with storeUserConfig
 
 ucf='keypath/xuserconfig.key'
 ukf='keypath/xkeyfile.key'
 admurl = "t3://hostingdns.com:port"
  
 def monitorThrds():
     connect(userConfigFile=ucf, userKeyFile=ukf, url= admurl )
     serverNames = getRunningServerNames()
     domainRuntime()
     print 'EXECUTE QUEUES'
     print ' '
     print 'Execute   Total  Current   PendRequest ServicedRequest'
     print 'QueueName Count  IdleCount CurrCount   TotalCount '
     print '===========**=======**=================================='
     for snam in serverNames:
         try:
                 cd("/ServerRuntimes/" + snam.getName() + "/ExecuteQueueRuntimes/weblogic.kernel.Default") 
                 totcnt=get('ExecuteThreadTotalCount') 
                 idlecnt = get('ExecuteThreadCurrentIdleCount')
                 pndcnt =get('PendingRequestCurrentCount') 
                 sevcnt = get('ServicedRequestTotalCount') 
                 print '%10s  %4d    %4d    %4d   %16d' %  (snam.getName(), totcnt, idlecnt, pndcnt, sevcnt) 
         except WLSTException,e:
                 # this typically means the server is not active, just ignore
                 pass
  
 def getRunningServerNames():
         domainConfig()
         return cmo.getServers()
  
 if __name__== "main":
     monitorThrds()
     disconnect()

Wednesday, April 22, 2009

JVM Monitoring with WLST

Hey dear WLAs, here I am with a new assignment for JVM monitoring. The fresh production environment setup with Clustered Domain with multiple physical locations with multiple UNIX machines.

The WebLogic capacity planning going on and various low memory or OutOfMemory issues araising when new migration happen from WebLogic 8.1 to 9.2 MP3. To identity how the Garbage Collection working? How much free memory is available for each instance? This can be known with JVM statistics, which inturn tuning the JVM parameters or reset is easy for decide.

I had found a JVM monitoring script that is best suites to my WebLogic environment.

This script is able to get all server instances JVM statistics with a single run. The beauty of WLST is that it runs on single JVM and provides us the required output with the help of domain, server Runtime MBeans, which are supported by WebLogic 9.x and later releases by default supporting JMX 1.2, which has many good features to control and monitor the Runtime Environment of a WebLogic Server instance.


Here have the script which I have modified as per my task there is little C-style customization done with Python language syntax. I mean in Jython which actally used in the WLST.


This could be further refined but ... short of time I am pubishing this
Enjoy!!! Jython/WLST SCRIPTING

#You can create key files
ucf='keypath/xuserconfig.key'
ukf='keypath/xkeyfile.key'
admurl = "t3://hostingdns.com:port"

# This module is for retrieve the JVM statistics
def monitorJVMHeapSize():
     connect(userConfigFile=ucf, userKeyFile=ukf, url=admurl)
     # alternate connect('user', 'passwd', 'adminurl')
     serverNames = getRunningServerNames()
     domainRuntime()

     print '                TotalJVM  FreeJVM  Used JVM' 
     print '=============================================='
     for name in serverNames:
   try:
    cd("/ServerRuntimes/"+name.getName()+"/JVMRuntime/"+name.getName())
    freejvm = int(get('HeapFreeCurrent'))/(1024*1024)
    totaljvm = int(get('HeapSizeCurrent'))/(1024*1024)
    usedjvm = (totaljvm - freejvm)
    print '%14s  %4d MB   %4d MB   %4d MB ' %  (name.getName(),totaljvm, freejvm, usedjvm)
   except WLSTException,e:
     pass

# This module for managed Servers list
def getRunningServerNames():
     domainConfig()
     return cmo.getServers()
 
if __name__== "main":
     monitorJVMHeapSize()
     disconnect()

Here in this program you can add more functionality with getting the HeapFreePercent. It is just a variable assigned with get('HeapFreePercent') . Later, You can print that variable value.

Popular Posts

Oracle WebLogic Administration Course

Oracle WebLogic Administration Course
WebLogic Training

Followers