Last active
December 16, 2015 20:29
-
-
Save chokkoyamada/5492816 to your computer and use it in GitHub Desktop.
count tomcat busy threads by groovy JMX
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import javax.management.ObjectName | |
| import javax.management.remote.JMXConnectorFactory as JmxFactory | |
| import javax.management.remote.JMXServiceURL as JmxUrl | |
| serverUrl = 'service:jmx:rmi:///jndi/rmi://localhost:9013/jmxrmi' | |
| conn = JmxFactory.connect(new JmxUrl(serverUrl)).MBeanServerConnection | |
| def query = new ObjectName('Catalina:*') | |
| String[] allNames = conn.queryNames(query, null) | |
| def modules = allNames.findAll{ | |
| name -> | |
| name.contains('Catalina:type=ThreadPool') | |
| }.collect{ new GroovyMBean(conn, it) } | |
| def busyThreadsCount = 0 | |
| modules.each{ m -> | |
| def obj = new ObjectName(m.name() as String) | |
| def ret = conn.getAttribute(obj, "currentThreadsBusy") | |
| busyThreadsCount = busyThreadsCount + ret | |
| } | |
| println(busyThreadsCount) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment