Last active
August 4, 2022 10:41
-
-
Save jayankandathil/751ceb419de194931121392c8741c2e1 to your computer and use it in GitHub Desktop.
Groovy script that prints out JMX Metrics for [Adobe Experience Manager] [Apache Sling] [AllQueues]
This file contains 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
// Author : Jayan Kandathil | |
// Last Updated : May 19, 2017 | |
// Version : 0.1 | |
import java.lang.management.* | |
import javax.management.ObjectName | |
import javax.management.remote.JMXConnectorFactory as JmxFactory | |
import javax.management.remote.JMXServiceURL as JmxUrl | |
import java.text.DecimalFormat; | |
DecimalFormat df = new DecimalFormat("###,##0"); | |
def serverUrl = 'service:jmx:rmi:///jndi/rmi://localhost:10000/jmxrmi' | |
String beanName = "org.apache.sling:type=queues,name=AllQueues" | |
try | |
{ | |
def server = JmxFactory.connect(new JmxUrl(serverUrl)).MBeanServerConnection | |
def gmxb = new GroovyMBean(server, beanName) | |
long lngQueuedJobs = gmxb.getProperty("NumberOfQueuedJobs") | |
long lngActiveJobs = gmxb.getProperty("NumberOfActiveJobs") | |
long lngJobs = gmxb.getProperty("NumberOfJobs") | |
long lngFinishedJobs = gmxb.getProperty("NumberOfFinishedJobs") | |
long lngProcessedJobs = gmxb.getProperty("NumberOfProcessedJobs") | |
long lngCancelledJobs = gmxb.getProperty("NumberOfCancelledJobs") | |
long lngFailedJobs = gmxb.getProperty("NumberOfFailedJobs") | |
println df.format(lngQueuedJobs) + "," + df.format(lngActiveJobs) + "," + df.format(lngJobs) + "," + df.format(lngFinishedJobs) + "," + df.format(lngProcessedJobs) + "," + df.format(lngCancelledJobs) + "," + df.format(lngFailedJobs); | |
} | |
catch(java.io.IOException e) | |
{ | |
println "Unable to connect to JVM" | |
System.exit(0) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Assumes that the AEM start script has the following lines in it (Windows 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