1 2 Previous Next 21 Replies Latest reply on Sep 16, 2008 11:26 AM by peterj

    How to reliably count active sessions (re-post)

    mrgordonz

      Hi JBoss gurus,

      This is a slightly re-worded re-post (http://www.jboss.com/index.html?module=bb&op=viewtopic&t=140995) because I wasn't getting any replies.

      I would like to reliably monitor the number of active sessions for a particular web application deployed on JBoss 4.0.5 (the server is Windows Server 2003; JDK is Sun 1.4.2_14). I didn't create the app - I simply provide hosting for a growing number of customers.

      Initially I looked around for monitoring tools (eg: Hyperic) which would do all this for me, but alas they all seemed to monitor everything EXCEPT active sessions for a particular web app. But I did find one (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 log file contents might be:

      active_sessions=65


      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 the string "active_sessions", and monitor the corresponding numeric value (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 most people have suggested that I need to write my own class which implements HttpSessionListener, and in the class I keep a running tally of sessions as they are created and destroyed.

      However, 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 has exactly the information I want - Active sessions , Session count , Max active sessions, Rejected session creations, Expired sessions , Longest session alive time , Average session alive time. But, how can I get that info into a log file (of my choosing)? According to the person who pointed me in the direction of the JBoss Management Console, this data is not stored anywhere (eg: a log file).

      So the big question for me is how does JBoss get this information? Are there built-in APIs which are called by the Management Console? If so, is there some way I can call those APIs using a batch script or a custom class?

      My ideal solution would be to have a very simple batch script which simply executes/calls a class (which will probably be one I have to write myself, or get help to write). That class then gets the info which is available in the Management Console, and pumps it into a log file in the following format:

      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


      I have no idea if this is possible, but I am hoping like mad that it is. Please, please, someone tell me it is possible to get this information! Better yet, tell me not only it's possible, but how! :)

      Cheers,

      Paul Hobbs


        • 1. Re: How to reliably count active sessions (re-post)
          slaboure

          JSR-77 is what you want to look at. Feel free to open the code of the web-console, it does exactly this.

          • 2. Re: How to reliably count active sessions (re-post)
            kjkoster

            Dear Paul,

            All of this information is available through JMX. If you want that information in a file (presumably to feed it into a monitoring system) there are a few JMX command line tools. Failing that you can also use curl or wget to query the JBoss console. Crude, but effective.

            Suggested course of action:
            1. Hook up jconsole to JBoss (as per http://wiki.jboss.org/wiki/UseJDK5JConsole).
            2. Determine the objectname and the attribute of the mbean that shows the sessions you want to track.
            3. find a JMX command line tool (as per http://www.google.com)
            4. Script away
            5. ???
            6. Profit!

            Hope this helps.
            --
            Kees Jan
            http://java-monitor.com/forum

            • 3. Re: How to reliably count active sessions (re-post)
              mrgordonz

              Hi Sacha

              You'll have to forgive my ignorance, but I have no idea how to use JSR-77. I did some Googling, and I'm afraid I understood almost nothing of what I found.

              As to viewing the code for web-console, I didn't know where this code would be, but I guessed it might be in D:\JBoss_Tomcat\server\default\deploy\management\console-mgr.sar\web-console.war. I wasn't sure what I was looking for, but I tried decompiling a bunch of class in console-mgr-classes.jar, but I couldn't find any reference to an attribute like "Max active sessions".

              Sorry if I'm being dim! Java and J2EE are definitely not my strong points.

              • 4. Re: How to reliably count active sessions (re-post)
                mrgordonz

                 

                "kjkoster" wrote:
                Dear Paul,

                All of this information is available through JMX. If you want that information in a file (presumably to feed it into a monitoring system) there are a few JMX command line tools. Failing that you can also use curl or wget to query the JBoss console. Crude, but effective.

                Suggested course of action:
                1. Hook up jconsole to JBoss (as per http://wiki.jboss.org/wiki/UseJDK5JConsole).
                2. Determine the objectname and the attribute of the mbean that shows the sessions you want to track.
                3. find a JMX command line tool (as per http://www.google.com)
                4. Script away
                5. ???
                6. Profit!

                Hope this helps.
                --
                Kees Jan
                http://java-monitor.com/forum


                Hi Kees,

                I have been trying to get jconsole to work, but so far I haven't had any luck. Firstly I found that the JDK I am using (1.4.2_14, which is required by the application) doesn't have jconsole. So I installed JDK 1.5.0_15. When I launch jconsole and try to connect, I get a message in the little connection dialog saying "Connection failed". On my server, JBoss is listening on port 1098 (not 1099), but I wouldn't think this would make a difference. I am able to browse to http://localhost:8180/jmx-console/, and I get a huge long page with a heap of stuff I don't understand. Can I use this instead of the jconsole Java application?

                In my search for a JMX command line tool, I found some references to twiddle. I have found twiddle is on my server (I believe it is part of JBoss), but when I try executing a command like:

                twiddle -s localhost:1098 serverinfo -l


                it sits there for ages and does nothing. I left it for about 20 minutes, and nothing happened.

                Is twiddle the kind of thing you had in mind for allowing me to retrieve the values I am looking for?

                Cheers,

                Paul

                • 5. Re: How to reliably count active sessions (re-post)
                  kjkoster

                  Dear Paul,

                  *ouch* JDK 1.4 is indeed not the best JDK to have from a sysadmin point of view. It basically makes you blind and deaf.

                  Something like twiddle was what I had in mind. I never used it myself (I use Zapcat and Zabbix for monitoring, and jconsole for occasional troubleshooting). I'm afraid that I cannot help you with making it work. I'm sure this forum and Google will provide ample support, though.

                  Jmx-console is JBoss' web-based version of JConsole and it's indeed massive. JBoss is built on top of JMX and that shows. Good thing is that what you want to monitor is there. It's just a matter of isolating it in the barrage of mbeans and attributes. :-)

                  There is plenty of information out there to get you started with jconsole. Search for posts of Peter Johnson on this forum. Here is something to get you started: http://www.cecmg.de/doc/tagung_2007/agenda07/24-mai/2b4-peter-johnson/index.html

                  Please be aware that JMX uses RMI as a transport, and that RMI uses dynamically allocated ports. Check that you don't have a firewall interfering.

                  Kees Jan
                  http://java-monitor.com/forum

                  • 6. Re: How to reliably count active sessions (re-post)
                    kjkoster

                    Oh, and upgrade the app server to 1.5. ;-)

                    • 7. Re: How to reliably count active sessions (re-post)
                      mrgordonz

                      Hi Kees,

                      I wish I could upgrade the JDK. I use this JDK because it is the version that is supported by the vendor of the web application - if I use something else then the software is technically not supported.

                      You say...

                      JBoss is built on top of JMX and that shows. Good thing is that what you want to monitor is there. It's just a matter of isolating it in the barrage of mbeans and attributes.


                      Unfortunately I have no idea what to look for - I wouldn't know what to look for even if I got jconsole working. What I can tell you is that the information I want is viewable via the Management Console using the following click path:

                      Monitoring > Web Status > Full Status > under the Application List I click the link for the application > localhost/Saba

                      It jumps to the point on the page where it shows the info I want. Of all the attributes listed, the one I most need is "Active Sessions"; followed by "Average session alive time". The others I don't really need. The actual application is deployed as saba.ear, and in the ear file is saba.war. Does that help you to identify the object name/attribute of an MBean? If I know what those details are, perhaps someone else on this forum can help me to figure out how to use twiddle.

                      Cheers,

                      Paul

                      • 8. Re: How to reliably count active sessions (re-post)
                        kjkoster

                        Dear Paul,

                        I gave you a link to a jconsole tutorial. Play around with jconsole for a few hours. Just load up a clean JBoss in Java 1.5 and dig around. I cannot teach you how to use it across the Internet, though you can hire me to do that. :-)

                        Read up on what mbeans are and how to interpret them. Then apply that to the jboss jmx console. I know it's big, but the first time you looked under the hood of your car it was big also. Now you just top up the oil even on cars you've never seen in your life.

                        Kees Jan

                        • 9. Re: How to reliably count active sessions (re-post)
                          mrgordonz

                           

                          "kjkoster" wrote:
                          Read up on what mbeans are and how to interpret them. Then apply that to the jboss jmx console. I know it's big, but the first time you looked under the hood of your car it was big also. Now you just top up the oil even on cars you've never seen in your life


                          Hi Kees,

                          To extend your analogy of looking under the hood, the first time I topped up the oil someone showed me exactly how to do it. And while it is true that I can now confidently top up the oil in just about any car, that task is pretty trivial compared to say replacing a blown head gasket. I would not attempt to replace a head gasket because I don't have the time (or the inclination) to learn that much about engines - I pay a mechanic to do that.

                          Returning to the question at hand - I don't have the time (or the inclination) to delve into the guts of mbeans or the jmx console. My TO DO list is so huge that taking time out to learn about this stuff is not a viable option for me (as interesting as it might be).

                          I have been searching for an answer to this question for about 6 weeks now, and I am astonished at how difficult it seems to be. The JBoss Management Console shows me exactly the information I require - Active Sessions for a particular web application. Where does it get this information? Can that information be retrieved in some other way - for example, a custom class which calls some API?

                          "kjkoster" wrote:
                          ...though you can hire me to do that.


                          How much do you charge? If it took say an hour or two of your time to walk me through the steps to retrieve this information, and your rates are affordable, I would be interested in paying you to help me. Alternatively, I don't know if you are one of the Experts on Experts Exchange who tries to accumulate points by solving problems, but if you are I have an open question on this very topic: http://www.experts-exchange.com/Software/Server_Software/Application_Servers/Java/Jboss/Q_23663083.html

                          Cheers,

                          Paul

                          • 10. Re: How to reliably count active sessions (re-post)
                            peterj

                            Found it! The MBean you want is:

                            jboss.web:host=localhost,path=YYY,type=Manager

                            where YYY is the web application context. The interesting attributes are:

                            activeSessions
                            sessionCounter
                            maxActiveSessions

                            and various others.

                            • 11. Re: How to reliably count active sessions (re-post)
                              mrgordonz

                              Hi Peter,

                              This is looking promising! However, when I try the following command at the command prompt:

                              D:\JBoss_Tomcat\bin>twiddle.bat -s localhost:1098 get jboss.web:host=localhost,path=/MyApp,type=Manager activeSessions


                              I get the following exception:

                              07:08:14,829 ERROR [Twiddle] Command failure
                              org.jboss.console.twiddle.command.CommandException: Invalid object name: jboss.web:host
                               at org.jboss.console.twiddle.command.MBeanServerCommand.createObjectName(MBeanServerCommand.java:53)
                               at org.jboss.console.twiddle.command.GetCommand.processArguments(GetCommand.java:123)
                               at org.jboss.console.twiddle.command.GetCommand.execute(GetCommand.java:142)
                               at org.jboss.console.twiddle.Twiddle.main(Twiddle.java:305)
                              
                              Help for command: 'get'
                              
                              Get the values of one or more MBean attributes
                              
                              usage: get [options] <name> [<attr>+]
                               If no attribute names are given all readable attributes are retrieved
                              options:
                               --noprefix Do not display attribute name prefixes
                               -- Stop processing options


                              Any thoughts as to what might be causing that exception?

                              Cheers,

                              Paul

                              • 12. Re: How to reliably count active sessions (re-post)
                                peterj

                                I think that the equal sign confuses the command parser - try adding quotes around the object name:

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

                                • 13. Re: How to reliably count active sessions (re-post)
                                  mrgordonz

                                  Hi Peter,

                                  That certainly fixed the issue with the exception - thx. My command is now:

                                  D:\JBoss_Tomcat\bin>twiddle -s localhost:1098 get "jboss.web:host=localhost,path=/MyApp,type=Manager" activeSessions


                                  But now when I execute that command, nothing happens - the cursor just sits there and the command window never returns to a prompt.

                                  Is there a log file or something that would give me a clue as to why the command never seems to complete?

                                  Cheers,

                                  Paul

                                  • 14. Re: How to reliably count active sessions (re-post)
                                    mrgordonz

                                    Hi Peter,

                                    I have finally managed to achieve my goal of extracting the number of active sessions into a log file. Your clue regarding the actual MBean was the clincher (jboss.web:host=localhost,path=YYY,type=Manager). I guessed that I should be able to see the info in the JMX console (http://localhost:8180/jmx-console/), and then I just searched for "path=/MyApp,type=Manager", lo and behold - there it was! So I examined the URL (http://localhost:8180/jmx-console/HtmlAdaptor?action=inspectMBean&name=jboss.web:host=localhost,path=/MyApp,type=Manager) and concluded that there was nothing special about it (ie: I could re-use it without breaking it).

                                    The next tricky part was extracting just the activeSessions attribute from the resulting HTML stream, so I wrote a little VBScript batch file which does just that:

                                    ' Author: phobbs
                                    ' Date: 2008/09/09
                                    ' Revision: 1.0
                                    ' Name: getSessions.vbs
                                    ' Purpose: Queries the MBean to retrieve active session count
                                    ' MBean Name: Domain Name: jboss.web
                                    ' type: Manager
                                    ' host: localhost
                                    ' path: /MyApp
                                    
                                    'Usage:
                                    ' getSessions.vbs
                                    ' activeSessions is output to log file D:\MyApp\log\session_count.log
                                    ' if there is an error, output to log file D:\MyApp\log\session_count_errors.log
                                    
                                    '========================================================================================
                                    
                                    Function GetActiveSessionCount()
                                    
                                     On Error Resume Next
                                    
                                     Const ForWriting = 2
                                    
                                     Dim strURL
                                     Dim log_file
                                     Dim error_log
                                     Dim fso_write
                                     Dim WriteFile
                                     Dim intStart
                                     Dim intEnd
                                     Dim htmlStream
                                     Dim activeSessionsBlock
                                     Dim sessionCount
                                    
                                     strURL = "http://localhost:8180/jmx-console/HtmlAdaptor?action=inspectMBean&name=jboss.web:host=localhost,path=/MyApp,type=Manager"
                                     log_file = "D:\MyApp\log\session_count.log"
                                     error_log = "D:\MyApp\log\session_count_errors.log"
                                     Set fso_write = CreateObject("Scripting.FileSystemObject")
                                    
                                     'get the HTML response from the URL
                                     htmlStream = GetHtml(strURL)
                                    
                                     'get rid of all the text between <td>activeSessions</td> and <td>Number of active sessions at this moment</td>
                                     intStart = InStr(htmlStream, "<td>activeSessions</td>")
                                     intEnd = InStr(htmlStream, "<td>Number of active sessions at this moment</td>")
                                     activeSessionsBlock = Mid(htmlStream, intStart, intEnd - intStart)
                                    
                                     'replace all carriage returns, line breaks, tabs and spaces
                                     activeSessionsBlock = Replace(activeSessionsBlock,Chr(10),"")
                                     activeSessionsBlock = Replace(activeSessionsBlock,Chr(13),"")
                                     activeSessionsBlock = Replace(activeSessionsBlock,Chr(9),"")
                                     activeSessionsBlock = Replace(activeSessionsBlock," ","")
                                    
                                     'get rid of everything except the session count number
                                     activeSessionsBlock = Replace(activeSessionsBlock,"<td>activeSessions</td>","")
                                     activeSessionsBlock = Replace(activeSessionsBlock,"<td>int</td>","")
                                     activeSessionsBlock = Replace(activeSessionsBlock,"<td>R</td>","")
                                     activeSessionsBlock = Replace(activeSessionsBlock,"<td>","")
                                     activeSessionsBlock = Replace(activeSessionsBlock,"</td>","")
                                     sessionCount = activeSessionsBlock
                                    
                                     If IsNumeric(sessionCount) Then
                                     Set WriteFile = fso_write.OpenTextFile(log_file, ForWriting, True)
                                     WriteFile.WriteLine "active_sessions=" & sessionCount
                                     Else
                                     Set WriteFile = fso_write.OpenTextFile(error_log, ForWriting, True)
                                     WriteFile.WriteLine "There was an error"
                                     WriteFile.WriteLine "active_sessions=" & sessionCount
                                     End If
                                    
                                     Set strURL = Nothing
                                     Set log_file = Nothing
                                     Set error_log = Nothing
                                     Set fso_write = Nothing
                                     Set WriteFile = Nothing
                                     Set intStart = Nothing
                                     Set intEnd = Nothing
                                     Set htmlStream = Nothing
                                     Set activeSessionsBlock = Nothing
                                     Set sessionCount = Nothing
                                    
                                    End Function
                                    
                                    '========================================================================================
                                    
                                    Function GetHtml(sURL)
                                    
                                     On Error Resume Next
                                    
                                     Set oHTML = CreateObject("Microsoft.XMLHTTP")
                                     'Set oHTTP = Createobject("WinHttp.WinHttpRequest.5.1")
                                     Set oWeb = CreateObject("InternetExplorer.Application")
                                     oWeb.navigate (sURL)
                                     oHTML.open "GET" , sURL, false
                                     oHTML.send
                                     GetHtml = oHTML.responseText
                                    
                                    End Function
                                    
                                    '========================================================================================
                                    
                                    GetActiveSessionCount


                                    I found that twiddle just wasn't working, but knowing the specific MBean made all the difference. Thanks heaps for your help.

                                    Cheers,

                                    Paul


                                    1 2 Previous Next