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 View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4175194#4175194 Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4175194 _______________________________________________ jboss-user mailing list [email protected] https://lists.jboss.org/mailman/listinfo/jboss-user
