[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

6.3

How to reliably count active sessions in J2EE web application

Asked by mrgordonz in Jboss Application Server, Java Programming Language, J2EE

Tags: JBoss, JBoss Application Server, 4.0.5, Sun JDK 1.4.2

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_SESSIONS% > %LOG_FILE%
echo session_count=%SESSION_COUNT% >> %LOG_FILE%
echo max_active_sessions=%MAX_ACTIVE_SESSIONS% >> %LOG_FILE%
echo rejected_session_creations=%REJECTED_SESSION_CREATIONS% >> %LOG_FILE%
echo expired_sessions=%EXPIRED_SESSIONS% >> %LOG_FILE%
echo longest_session_alive_time=%LONGEST_SESSION_ALIVE_TIME% >> %LOG_FILE%
echo average_session_alive_time=%AVERAGE_SESSION_ALIVE_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
[+][-]09/08/08 03:30 AM, ID: 22415949Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: Jboss Application Server, Java Programming Language, J2EE
Tags: JBoss, JBoss Application Server, 4.0.5, Sun JDK 1.4.2
Sign Up Now!
Solution Provided By: TomasHelgi
Participating Experts: 2
Solution Grade: B
 
[+][-]08/20/08 07:29 AM, ID: 22269904Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/20/08 07:32 AM, ID: 22269933Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/20/08 08:02 AM, ID: 22270357Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/20/08 07:45 PM, ID: 22275773Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/20/08 10:16 PM, ID: 22276395Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/21/08 10:55 AM, ID: 22282327Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/21/08 12:51 PM, ID: 22283666Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/21/08 04:52 PM, ID: 22285324Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/07/08 11:57 PM, ID: 22415116Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/08/08 12:23 AM, ID: 22415197Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/08/08 02:34 AM, ID: 22415714Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/08/08 08:43 AM, ID: 22418519Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]09/08/08 01:39 PM, ID: 22421293Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/08/08 07:20 PM, ID: 22423848Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/08/08 07:24 PM, ID: 22423861Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92 / EE_QW_2_20070628