// Replace HOSTNAME,PORT,USERNAME,PASSWORD as appropriate.
import groovy.jmx.builder.JmxBuilder
def jmx = new JmxBuilder()
def conn = jmx.connectorClient (
protocol:"rmi",
url:"service:jmx:rmi:///jndi/rmi://HOSTNAME:PORT/server"
)
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
conn.close()
def jmx = new JmxBuilder()
def conn = jmx.connectorClient (
protocol:"rmi",
url:"service:jmx:rmi:///jndi/rmi://HOSTNAME:PORT/server"
)
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
conn.close()
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.
You can use following article also to remotely monitor a WSO2 Carbon product using JConsole
ReplyDeletehttp://maharachchi.blogspot.com/2011/02/monitoring-your-java-application-with.html