Wednesday, 18 May 2011

Remotely Monitor WSO2 Carbon Instance with Groovy

This is a quick Groovy script that demonstrates how to print the memory usage of any remote JVM.

// Replace HOSTNAME,PORT,USERNAME,PASSWORD as appropriate.
import groovy.jmx.builder.JmxBuilder 
def jmx = new JmxBuilder()
def conn = jmx.connectorClient (

conn.connect([ 'jmx.remote.credentials' :  [ 'USERNAME','PASSWORD' ] as String[] ])

def mem = new GroovyMBean(    conn.getMBeanServerConnection(),'java.lang:type=Memory');

println "Heap:"
println "===="
println 'Committed: ' + mem.HeapMemoryUsage.committed
println '     Used: ' + mem.HeapMemoryUsage.used
println '      Max: ' + mem.HeapMemoryUsage.max

println "\nNon-heap:"
println "========"
println 'Committed: ' + mem.NonHeapMemoryUsage.committed
println '     Used: ' + mem.NonHeapMemoryUsage.used
println '      Max: ' + mem.NonHeapMemoryUsage.max


WSO2 Carbon:
In order to use this to monitor a WSO2 Carbon instance (ESB, Data Services etc.), edit repository/conf/carbon.xml. In <Ports> uncomment the <JMX> section. Restart the WSO2 Carbon process. The username used for access must have the admin role.

1 comment:

  1. You can use following article also to remotely monitor a WSO2 Carbon product using JConsole