Hi JBoss/Java Experts,
This is a somewhat long post, for which I apologise, but I want to ensure I have included all pertinent information.
I would like to reliably monitor (and report on) the number of active sessions for a particular web application deployed on JBoss 4.0.5 (the server is Windows Server 2003).
Initially I looked around for monitoring tools (eg: Hyperic) which would do all this for me, but alas, all of them seemed to monitor everything EXCEPT active sessions for a particular web app. But I did find one piece of software (AdventNet Application Manager) which does the next best thing (for my purposes) - it will execute a script and monitor the output of the script.
For example, say I have a script called sessions.bat, and when it is executed it will (somehow) output the number of sessions to a log file, sessions.log . Sample contents of the log file might be:
active_sessions=35
session_count=672
max_active_sessions=82
rejected_session_creations
=0
expired_sessions=637
longest_session_alive_time
=6618
average_session_alive_time
=1944
AdventNet Application Manager will execute the script at a desired interval (say every 15 minutes), and then read the contents of the resulting log file. I can even specify that it needs to look for specific strings (eg: "active_sessions"), and monitor the corresponding numeric values (it even creates pretty graphs for me!).
BUT - I need a script which will output the number of active sessions.
I have done a bunch of searching, and posted on other forums, and so far the consensus seems to be I need to write my own class which implements HttpSessionListener, and have a couple of methods to monitor when sessions are created and destroyed, and tally the session count somehow. I'm a pretty mediocre Java programmer, so I hunted around for some code which kind of seems to do the trick, but in my testing I found that the session count wasn't accurate (for details see my post at
http://forums.sun.com/thread.jspa?threadID=5322822).
One person suggested I have a look at the "JBoss Management Console" (
http://my-server:8180/web-console/)
,
"...then in the console function tree find: Monitoring - > Web Status -> Full Status.
You will get a page with loads of stats on the right side.
Find [Application list] and link to your application, simply click on it
and at the top of the page you will see all the stats that you need..."
I had a look at this and it looks perfect - it gives me more information than I was expecting, like Active sessions, Session count, Max active sessions, Rejected session creations, Expired sessions, Longest session alive time, and Average session alive time.
But my question is this: how does JBoss get this info when viewing the Management Console? I've been told by someone who replied to my post that this information is not stored in a log file (or anywhere). If it isn't stored, presumably there is an API of some kind which is being called/invoked by the Management Console to gather/retrieve that info. Or do I have it completely wrong? What is interesting to me is that JBoss can get this information without me having to write a custom class. How does it do this?
My preferred solution is to have a batch script (eg: sessions.bat) which calls some API(s) (or a custom class) which will return the current values for those different metrics (Active sessions , Session count , Max active sessions, Rejected session creations, Expired sessions , Longest session alive time , Average session alive time)? Or can they only be viewed via the Management Console? If the batch script can't get the values directly, can I get this information in a class that I write (or "borrow")?
In my ideal world, the batch script would look something like this:
@echo off
REM **************************
**********
**********
****
REM * APPLICATION SESSION INFO *
REM * *
REM * This script retrieves the session info *
REM * for MyApp and writes it to a log file. *
REM * *
REM **************************
**********
**********
****
set LOG_FILE=C:\logs\sessions.
log
REM Initialize the variables
set ACTIVE_SESSIONS=0
set SESSION_COUNT=0
set MAX_ACTIVE_SESSIONS=0
set REJECTED_SESSION_CREATIONS
=0
set EXPIRED_SESSIONS=0
set LONGEST_SESSION_ALIVE_TIME
=0
set AVERAGE_SESSION_ALIVE_TIME
=0
set ACTIVE_SESSIONS=[some magic code to get the info]
set SESSION_COUNT=[some magic code to get the info]
set MAX_ACTIVE_SESSIONS=[some magic code to get the info]
set REJECTED_SESSION_CREATIONS
=[some magic code to get the info]
set EXPIRED_SESSIONS=[some magic code to get the info]
set LONGEST_SESSION_ALIVE_TIME
=[some magic code to get the info]
set AVERAGE_SESSION_ALIVE_TIME
=[some magic code to get the info]
echo active_sessions=%ACTIVE_SE
SSIONS% > %LOG_FILE%
echo session_count=%SESSION_COU
NT% >> %LOG_FILE%
echo max_active_sessions=%MAX_A
CTIVE_SESS
IONS% >> %LOG_FILE%
echo rejected_session_creations
=%REJECTED
_SESSION_C
REATIONS% >> %LOG_FILE%
echo expired_sessions=%EXPIRED_
SESSIONS% >> %LOG_FILE%
echo longest_session_alive_time
=%LONGEST_
SESSION_AL
IVE_TIME% >> %LOG_FILE%
echo average_session_alive_time
=%AVERAGE_
SESSION_AL
IVE_TIME% >> %LOG_FILE%
This log file can then be parsed by the monitoring software, and it will produce pretty graphs and reports for my customers. :)
The bit that is missing is [some magic code to get the info]. Can someone suggest how I might do this?
Please, please, someone tell me it is possible to get this information!
Cheers,
Paul Hobbs
Start Free Trial