There are some well known alternatives to count the number of active session in a Web application, one of the most popular being adding Session Listeners to the application.
However if you cannot modify your application or simply you need to use this value in a batch script you can still use the nice Jboss utility called twiddle.

Sintax is quite simple: pass to twiddle the servername with -s and the Application Context you want to monitor (in our example /SampleApp ) 

twiddle -s localhost get "jboss.web:host=localhost,path=/SampleApp,type=Manager" activeSessions



Related articles available on

How do I get the list of MBeans with twiddle?

  JBoss provides a simple command line tool that allows for inte

How do I run garbage collector from shell?

  You can suggest JBoss to run the garbage collector in differen

How do I check my application status from shell?

  This is a two process step: at first you need to retrieve the

How do you shut down multiple JBoss instances?

  Supposing you have configured 2 instances of JBoss, one on por

twiddle reference guide

Please note: twiddle is not available any more as default Command

AS 7 Graphical CLI

One new feature of the release 7.1.0 of JBoss AS is the Graphical