Friday, February 26, 2010

HTTP Session Monitoring in WebLogic Server

Monitoring HTTP sessions on WebLogic Server is a common task when you have web component (WAR) deployed as a part of your enterprise application (EAR). By default WebLogic Server provides a way to access the number of active HTTP sessions for each web application. But if you need more information about the individual sessions like their creation time, last accessed time, maximum inactive interval etc. then you have to enable the session monitoring option in the web component's Deployment Descriptor (DD). If the application is already packaged and deployed you can make use of the deployment plan to enable this attribute. WebLogic Administration Console provide options to modify some of the attribute for the components and application through the interface. Eventually a deployment plan will be generated if there are no deployment plan associated with the application or the existing plan will be modified automatically by Administration Console. This will ease administrators job of enabling session monitoring for a packaged application. You may have to update or redeploy the application with the plan for the monitoring to take effect. No restarting of any server is required for this change.

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

def connectToAdminServer()
#Connect to Admin Server

def extractAndPrintSessionInfo(servletSessionRuntime)
#Get session name
#Creation time is concatinated to the session name. So split it
cal = Calendar.getInstance()
ct = cal.getTime()
#Get last accessed time
tla = cal.getTime()
print ' '
print 'Session Name - ' + session_name
print 'Creation Time - ', ct
print 'Last Accessed Time - ', tla


#Get Runtime for our server

#Get all running applications
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
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)'
display_comp_name = comp_name
print 'Component Context Root - ', display_comp_name

#Get all active sessions
print 'Total no. of sessions - ', len(sessions)

#Loop through all the available sessions
for ssession in sessions:

#Disconnect and exit

The output from the above script will look something like this:

[test@mywlssvr-orcl ~]$ java weblogic.WLST

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.


  1. Hello and congratulations for the great article.

    Do 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.

  2. Hi,

    Great 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.


  3. Monitoring IDs are NOT equal to the JSESSION Cookie value or session id. They are randomly generated unique ids.

    See my other post here for more information regarding the monitoring id -

  4. Hi,

    This works fine for 10.3.0 servers. How to do the same in 8.1.6 servers?


  5. Hi,

    Thanks 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.


    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(,[[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

  6. I found the problem which I described in my previous post

    The following needs to be added to application weblogic.xml


    Otherwise getServletSessions() returns 0 sessions Doc ID 775750.1

    Hope it can help someone who has the same issue.

  7. 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 ???