Advertisement

08.20.2008 at 06:56AM PDT, ID: 23663083
[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: , , ,

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
Start Free Trial
[+][-]08.20.2008 at 07:29AM PDT, ID: 22269904

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.2008 at 07:32AM PDT, ID: 22269933

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.2008 at 08:02AM PDT, ID: 22270357

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.2008 at 07:45PM PDT, ID: 22275773

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.2008 at 10:16PM PDT, ID: 22276395

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.2008 at 10:55AM PDT, ID: 22282327

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.2008 at 12:51PM PDT, ID: 22283666

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.2008 at 04:52PM PDT, ID: 22285324

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.2008 at 11:57PM PDT, ID: 22415116

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.2008 at 12:23AM PDT, ID: 22415197

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.2008 at 02:34AM PDT, ID: 22415714

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.2008 at 03:30AM PDT, ID: 22415949

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
 
 
[+][-]09.08.2008 at 08:43AM PDT, ID: 22418519

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.2008 at 01:39PM PDT, ID: 22421293

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.2008 at 07:20PM PDT, ID: 22423848

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.2008 at 07:24PM PDT, ID: 22423861

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...
20081112-EE-VQP-44 / EE_QW_2_20070628