Come join our live training webinar every other Wednesday at 11am PST and hear LogicMonitor experts explain best practices and answer common questions. We understand these are uncertain times, and we are here to help!
Although for accessing JMX MBeans within a DataSource you can typically use our JMX collection mechanism, when you need to do complex processing of results from a JMX query, using Groovy to retrieve the JMX results can be much simpler.
A complete reference of LogicMonitor’s Groovy JMX methods can be found at the bottom of this page, but here’s a few examples to demonstrate how this feature works.
// import the logicmonitor jmx helper class import com.santaba.agent.groovyapi.jmx.*; // get the jmx host, port, & credentials on which to query def jmx_host = hostProps.get('system.hostname'); def jmx_port = hostProps.get('jmx.port'); def jmx_user = hostProps.get('jmx.user'); def jmx_pass = hostProps.get('jmx.pass'); // define the jmx url def jmx_url = "service:jmx:rmi:///jndi/rmi://" + jmx_host + ":" + jmx_port + "/jmxrmi"; // open a connection to the jmx url def jmx_conn = JMX.open(jmx_url, jmx_user, jmx_pass); // print the value of the bean print jmx_conn.getValue("java.lang:type=Threading:ThreadCount"); // return with a response code that indicates we ran successfully return (0);
// import the logicmonitor jmx helper class import com.santaba.agent.groovyapi.jmx.*; // get the jmx host, port on which to query def jmx_host = hostProps.get('system.hostname'); def jmx_port = hostProps.get('jmx.port'); // define the jmx url def jmx_url = "service:jmx:rmi:///jndi/rmi://" + jmx_host + ":" + jmx_port + "/jmxrmi"; // open a connection to the jmx server, assuming no authentication required def jmx_conn = JMX.open(jmx_url); // get the names of each memory pool mempool_array = jmx_conn.getChildren("java.lang:type=MemoryPool,name=*"); // iterate over the mempool names mempool_array.each { pool -> println pool; } // return with a response code that indicates we ran successfully return (0);
// import the logicmonitor jmx helper class import com.santaba.agent.groovyapi.jmx.*; // get the jmx host, port on which to query def jmx_host = hostProps.get('system.hostname'); def jmx_port = hostProps.get('jmx.port'); // create a new hashmap and populate jmxmp parameters as key/value pairs clientEnv = new HashMap(); clientEnv.put("jmx.remote.profiles", "TLS SASL/PLAIN"); clientEnv.put("jmx.remote.tls.socket.factory", SSLContext.getInstance("TLSv1").getSocketFactory()); def jmxmp_conn = JMX.open("jmxmp", jmx_host, jmx_port, clientEnv, 5000); // do something more...
Object Instatiation
JMX.open(url, [timeout]) – open a connection to remote jmx service without authentication
JMX.open(url, [userid], [passwd], [timeout]) – open a connection to remote jmx service with authentication
JMX.open(protocol, host, port, environmentMap, [timeout]) – open a connection to remote jmxmp or rmi service
Object Methods
getValue(jmxpath) – get the value of a jmx mbean
getChildren(jmxpath) – reads text from the connection until it finds a match in the provided regular expression
In This Article