Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jayankandathil/7119e7afa2e142e94a12 to your computer and use it in GitHub Desktop.
Save jayankandathil/7119e7afa2e142e94a12 to your computer and use it in GitHub Desktop.
Groovy script that reports Apache Sling average request duration
// Author : Jayan Kandathil
// Last Updated : June 18, 2014
// Version : 0.1
// Need following JVM init arguments for JMX access (Windows .bat example)
// set CQ_JVM_OPTS=%CQ_JVM_OPTS% -Dcom.sun.management.jmxremote
// set CQ_JVM_OPTS=%CQ_JVM_OPTS% -Dcom.sun.management.jmxremote.port=10000
// set CQ_JVM_OPTS=%CQ_JVM_OPTS% -Dcom.sun.management.jmxremote.authenticate=false
// set CQ_JVM_OPTS=%CQ_JVM_OPTS% -Dcom.sun.management.jmxremote.ssl=false
import java.lang.management.*
import javax.management.ObjectName
import javax.management.remote.JMXConnectorFactory as JmxFactory
import javax.management.remote.JMXServiceURL as JmxUrl
def serverUrl = 'service:jmx:rmi:///jndi/rmi://localhost:10000/jmxrmi'
String beanName = "org.apache.sling:type=engine,service=RequestProcessor"
try
{
def server = JmxFactory.connect(new JmxUrl(serverUrl)).MBeanServerConnection
def gmxb = new GroovyMBean(server, beanName)
double x = gmxb.getProperty("MeanRequestDurationMsec")
println x.round(2)
}
catch(java.io.IOException e)
{
println "Unable to connect to JVM"
System.exit(0)
}
catch(javax.management.InstanceNotFoundException e)
{
println 0
}
catch(groovy.lang.MissingPropertyException e)
{
println "Unable to find " + prop
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment