You are on page 1of 2

1 of 2

http://weblogicserver.blogspot.in/2010/02/http-session-monitoring-in-we...

01.
02.
03.
04.
05.
06.
07.
08.
09.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.

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

11/18/2016 2:45 PM

http://weblogicserver.blogspot.in/2010/02/http-session-monitoring-in-we...

54.
if comp.getType() == 'WebAppComponentRuntime':
55.
comp_name = comp.getName().split(servername+'_/')
if len(comp_name) == 1:
56.
display_comp_name = '(default web app)'
57.
else:
58.
display_comp_name = comp_name
59.
60.
print 'Component Context Root - ', display_comp_name
61.
#Get all active sessions
62.
sessions=comp.getServletSessions()
63.
64.
print 'Total no. of sessions - ', len(sessions)
65.
66.
#Loop through all the available sessions
for ssession in sessions:
67.
extractAndPrintSessionInfo(session)
68.
69.
70. #Disconnect and exit
71. disconnect()
72. exit()

2 of 2

11/18/2016 2:45 PM

You might also like