Skip to content

Instantly share code, notes, and snippets.

@nshaw
Created January 30, 2013 20:25
Show Gist options
  • Save nshaw/4676589 to your computer and use it in GitHub Desktop.
Save nshaw/4676589 to your computer and use it in GitHub Desktop.
Groovy script to display the current number of active Tomcat sessions. Useful if you don't have a Tomcat monitoring solution in place.
import java.lang.management.ManagementFactory
import javax.management.MBeanServer
import javax.management.ObjectName
import com.liferay.portal.kernel.util.StringUtil
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ObjectName objectName = new ObjectName("Catalina:type=Manager,context=/,host=localhost")
Object mbean = mbs.getMBeanInfo(objectName);
println "Found manager bean"
//println mbean.toString()
String ids = (String) mbs.invoke(objectName, "listSessionIds", null, null)
//println ids
String[] list = StringUtil.split(ids, " ")
println "Total number of sessions: " + list.size()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment