Administration Console will automatically populate the Session tab under the Monitoring tab with the individual session information for the specific application. By default the following column are displayed on the console page:
- Context Root
- Server
- Creation Time
- Time Last Accessed
- Max Inactive Interval
You can also add the following columns to the table by customizing the view:
- Monitoring ID
- Application
- Machine
The Monitoring ID provides a unique ID by default to identify the session. You can also customize the Monitoring ID by specifying a session attribute name which is unique for identifying the session for users. For example you can configure customer_id or user_id or order_id as Monitoring ID for tracking session. I shall talk about Monitoring IDs and finding session size in a different post. Internally WebLogic will concatenate the Monitoring ID with the creation time to make a unique name for each session. The following is an example screen shot of monitoring sessions after customizing the view:
WLST can also be able to retrieve these information from the ServletSessionRuntimeMBeans. The following is an example WLST script to connect to the Administration Server of a domain to retrieve session information for a specific application on a particular server.I had used the deprecated ServletSessionRuntimeMBeans in my WLST example as the session creation time is only available through that runtime mbean. You can also access all the information about the session except the creation time through the WebAppComponentRuntimeMBean. But you will have to use the Monitoring IDs (available through WebAppComponentRuntimeMBean) to get information about a specific session.
from java.util import Calendar
def defineVariables()
#Define all the variables used
username='system'
password='weblogic'
adminurl='t3://localhost:7001'
servername='AdminServer'
appname='CompanyStore'
def connectToAdminServer()
#Connect to Admin Server
connect(username,password,adminurl)
def extractAndPrintSessionInfo(servletSessionRuntime)
#Get session name
session_name=ssession.getName().split('!')[0]
#Creation time is concatinated to the session name. So split it
ct_millis=ssession.getName().split('!')[1]
cal = Calendar.getInstance()
cal.setTimeInMillis(Long(ct_millis))
ct = cal.getTime()
#Get last accessed time
tla_millis=ssession.getTimeLastAccessed()
cal.setTimeInMillis(Long(tla_millis))
tla = cal.getTime()
print ' '
print 'Session Name - ' + session_name
print 'Creation Time - ', ct
print 'Last Accessed Time - ', tla
#Main
defineVariables()
connectToAdminServer()
#Get Runtime for our server
domainRuntime()
cd('/ServerRuntimes/'+servername)
#Get all running applications
apps=cmo.getApplicationRuntimes()
for app in apps:
#We are intersted only on this application
if app.getName() == appname:
print 'Application Name - ', app.getName()
#Get all components in that application
comps=app.getComponentRuntimes()
for comp in comps:
#We are interested in only web components
if comp.getType() == 'WebAppComponentRuntime':
comp_name = comp.getName().split(servername+'_/')
if len(comp_name) == 1:
display_comp_name = '(default web app)'
else:
display_comp_name = comp_name
print 'Component Context Root - ', display_comp_name
#Get all active sessions
sessions=comp.getServletSessions()
print 'Total no. of sessions - ', len(sessions)
#Loop through all the available sessions
for ssession in sessions:
extractAndPrintSessionInfo(session)
#Disconnect and exit
disconnect()
exit()
The output from the above script will look something like this:
[test@mywlssvr-orcl ~]$ java weblogic.WLST sessions.py
Initializing WebLogic Scripting Tool (WLST) ...
Welcome to WebLogic Server Administration Scripting Shell
Type help() for help on available commands
Connecting to t3://localhost:7001 with userid system ...
Successfully connected to Admin Server 'AdminServer' that belongs to domain 'dizzyworld'.
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.
Location changed to domainRuntime tree. This is a read-only tree with DomainMBean as the root.
For more help, use help(domainRuntime)
Application Name - CompanyStore
Component Context Root - (default web app)
Total no. of sessions - 2
Session Name - dYvLLHgRGxQ8zS0ZYySLZKx1j2KK9Ws2G22nlJXvrQRFv64zsPTm
Creation Time - Fri Feb 26 01:13:21 UTC 2010
Last Accessed Time - Fri Feb 26 01:13:26 UTC 2010
Session Name - nGbTLHgFLnfNjwGT1cpHGQhJZGZynBYRsp2TjC8kC7KFRK1vCCf3
Creation Time - Fri Feb 26 01:13:41 UTC 2010
Last Accessed Time - Fri Feb 26 01:13:45 UTC 2010
Disconnected from weblogic server: AdminServer
Exiting WebLogic Scripting Tool.
Hello and congratulations for the great article.
ReplyDeleteDo you know which value is the default Monitoring ID? At first glance it seems the first part of JSESSION cookie value, but I've checked and they don't match.
Thank you.
Hi,
ReplyDeleteGreat article, Thankyou.
I am looking for some help in setting up an IDE for writing WLST. I tried setting up PyDev in Eclipse but could not make it work.
If you could come up with an article on setting up an IDE for WLST, it would be of great help for beginners like me.
Appreciate your efforts.
Thanks,
Naveen.
Monitoring IDs are NOT equal to the JSESSION Cookie value or session id. They are randomly generated unique ids.
ReplyDeleteSee my other post here for more information regarding the monitoring id -
http://weblogicserver.blogspot.com/2010/04/effective-session-monitoring-in.html
Hi,
ReplyDeleteThis works fine for 10.3.0 servers. How to do the same in 8.1.6 servers?
Thanks,
Kapil.
Hi,
ReplyDeleteThanks a lot for sharing this. It's very helpful to find out the information about web sessions.
I've deployed one test application to admin server "TrlDemo_application1_v7.0" and open some sessions so i can see 2 active sessions running on AdminServer in WL Admin Console:
Context Root Server Creation Time Time Last Accessed Max Inactive Interval Application Machine Monitoring ID
/prototype AdminServer 06/01/14 12:21:21 o'clock EST 06/01/14 12:35:16 o'clock EST 3600 TrlDemo_application1 (v7.0) 6yR2SKmR6Lnx4kTTRgV9LT1vtVN75LQfzPxqfMmClgnn4Rvj32dL
However the scripts returns 0 sessions running
I would appreciate if you have any recommedattions how to debug this.
Thanks
Script output:
Location changed to domainRuntime tree. This is a read-only tree with DomainMBean as the root.
For more help, use help(domainRuntime)
Application Name - TrlDemo_application1_v7.0
array(weblogic.management.runtime.ComponentRuntimeMBean,[[MBeanServerInvocationHandler]com.bea:ServerRuntime=AdminServer,Name=AdminServer_TrlDemo_application1#v7.0_empty.jar,Location=AdminServer,Type=AppClientComponentRuntime,ApplicationRuntime=TrlDemo_application1_v7.0, [MBeanServerInvocationHandler]com.bea:ServerRuntime=AdminServer,Name=AdminServer_/prototype_v7.0,Location=AdminServer,Type=WebAppComponentRuntime,ApplicationRuntime=TrlDemo_application1_v7.0])
comp_name ['', 'prototype_v7.0']
2 ['', 'prototype_v7.0']
Component Context Root - ['', 'prototype_v7.0']
comp [MBeanServerInvocationHandler]com.bea:ServerRuntime=AdminServer,Name=AdminServer_/prototype_v7.0,Location=AdminServer,Type=WebAppComponentRuntime,ApplicationRuntime=TrlDemo_application1_v7.0
Total no. of sessions - 0
Disconnected from weblogic server: AdminServer
I found the problem which I described in my previous post
ReplyDeleteThe following needs to be added to application weblogic.xml
true
Otherwise getServletSessions() returns 0 sessions Doc ID 775750.1
Hope it can help someone who has the same issue.
Dear, I am having an issue that We are using Oracle 11g DB & Weblogic server ... when ever end user is connect with the Applications, v$session show the Weblogic Server Name and does not show the actual connecting Terminal as well as Operating System Name... There is any way to get the User Terminal as well as OS Name ???
ReplyDelete