Tomcat Management: Using the JMXProxy
One hidden gem bundled with the Tomcat Manager is the JMXProxy, which allows you to do a whole bunch of cool and frightening things with your tomcat container and running applications. It is enabled by default once the Tomcat Manager is enabled. You'll need more than a browser to interact with it, however, because simply loading http://localhost:8080/manager/jmxproxy dumps everything in regular text, which is useful for getting MBean names.
Below are some groovy scripts that will highlight some of the interesting things you can get from the JMXProxy.
Don't assume that interaction with the jmxproxy is all 'getting' and no 'setting'. This article dealt with the cool things you can do with the jmxproxy—the next one will deal with the frightening things.
Below are some groovy scripts that will highlight some of the interesting things you can get from the JMXProxy.
Get Tomcat Thread Pool
#!/usr/bin/env groovy
package groovyx.net.http
import static groovyx.net.http.Method.GET
import static groovyx.net.http.ContentType.TEXT
def http = new HTTPBuilder( 'http://localhost:8080/manager/jmxproxy/?qry=*:type=ThreadPool,name=http-8080' )
http.request( GET,TEXT ) { req ->
http.auth.basic( 'tomcat', 'tomcat' )
headers.'User-Agent' = 'GroovyHTTPBuilderTest/0.4'
response.success = { resp, reader ->
println "-----Response-----"
println System.out << reader
println "\n------------------"
}
response.failure = { resp ->
println "Something bad happened. ${resp.statusLine}"
}
}
The script above will print out some useful stats regarding Thread Pool statistics on the HTTP connector. Output looks something like the following:-----Response-----
OK - Number of results: 1
Name: Catalina:type=ThreadPool,name=http-8080
modelerType: org.apache.tomcat.util.modeler.BaseModelMBean
maxThreads: 40
backlog: 100
currentThreadsBusy: 1
acceptorThreadCount: 1
threadPriority: 5
paused: false
port: 8080
tcpNoDelay: true
soLinger: -1
soTimeout: 20000
daemon: true
running: true
currentThreadCount: 6
name: http-8080
org.codehaus.groovy.runtime.FlushingStreamWriter@2580b3
------------------
Are you interested in connector-related statistics? Well, the following script will provide all the useful statistics exposed by the HTTP Connector.Get Tomcat Connector Statistics
#!/usr/bin/env groovy
package groovyx.net.http
import static groovyx.net.http.Method.GET
import static groovyx.net.http.ContentType.TEXT
def http = new HTTPBuilder( 'http://localhost:8080/manager/jmxproxy/?qry=*:type=Connector,port=8080' )
http.request( GET,TEXT ) { req ->
http.auth.basic( 'tomcat', 'tomcat' )
headers.'User-Agent' = 'GroovyHTTPBuilderTest/0.4'
response.success = { resp, reader ->
println "-----Response-----"
println System.out << reader
println "\n------------------"
}
response.failure = { resp ->
println "Something bad happened. ${resp.statusLine}"
}
}
Output will look similar to the following:-----Response-----
OK - Number of results: 1
Name: Catalina:type=Connector,port=8080
modelerType: org.apache.catalina.mbeans.ConnectorMBean
connectionUploadTimeout: 300000
keepAliveTimeout: -1
protocol: HTTP/1.1
maxThreads: 40
acceptCount: 100
connectionTimeout: 20000
connectionLinger: -1
scheme: http
port: 8080
tcpNoDelay: true
xpoweredBy: false
compression: off
maxHttpHeaderSize: 8192
proxyPort: 0
secure: false
maxPostSize: 2097152
redirectPort: 8443
bufferSize: 2048
emptySessionPath: false
threadPriority: 5
useBodyEncodingForURI: false
protocolHandlerClassName: org.apache.coyote.http11.Http11Protocol
enableLookups: false
allowTrace: false
maxKeepAliveRequests: 100
disableUploadTimeout: true
org.codehaus.groovy.runtime.FlushingStreamWriter@2580b3
------------------
List Running Servlets
#!/usr/bin/env groovy
package groovyx.net.http
import static groovyx.net.http.Method.GET
import static groovyx.net.http.ContentType.TEXT
def http = new HTTPBuilder( 'http://localhost:8080/manager/jmxproxy/?qry=*:j2eeType=Servlet,*' )
http.request( GET,TEXT ) { req ->
http.auth.basic( 'tomcat', 'tomcat' )
headers.'User-Agent' = 'GroovyHTTPBuilderTest/0.4'
response.success = { resp, reader ->
println "-----Response-----"
println System.out << reader
println "\n------------------"
}
response.failure = { resp ->
println "Something bad happened. ${resp.statusLine}"
}
}
There is an awful lot of output for this one so I will not be including the output for this particular script in this article. Don't assume that interaction with the jmxproxy is all 'getting' and no 'setting'. This article dealt with the cool things you can do with the jmxproxy—the next one will deal with the frightening things.