Are there any libraries that would allow me to call a JMX MBean method from a shell script. We expose some operations/admin commands through JMX, and we could have our admins use JConsole, or VisualVM, but some tasks are better left to automation. In that automation we'd like to be able to call a JMX MBean method on our running server, preferably from a shell script.
By default, Java provides a remote JMX connector that is based on Java RMI (Remote Method Invocation).
Java™ Management Extension (JMX) commandsControls the JMX technology that is useful for monitoring B2B Advanced Communications and updating system settings at runtime. jmx config command. The jmx config command changes the password for the JMX tool on a node to your own password.
The JMX Messaging Protocol (JMXMP) connector is a configuration of the generic connector where the transport protocol is based on TCP and the object wrapping is native Java serialization. Security is more advanced than for the RMI connector.
An MBean server is a repository of MBeans that provides management applications access to MBeans.
The following command line JMX utilities are available:
Groovy JMX Example:
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:9003/jmxrmi' String beanName = "com.webwars.gameplatform.data:type=udmdataloadsystem,id=0" def server = JmxFactory.connect(new JmxUrl(serverUrl)).MBeanServerConnection def dataSystem = new GroovyMBean(server, beanName) println "Connected to:\n$dataSystem\n" println "Executing jmxForceRefresh()" dataSystem.jmxForceRefresh();
cmdline-jmxclient example:
If you have an
With an Operation called:
Then you can write a simple bash script (assuming you download cmdline-jmxclient-0.10.3.jar and put in the same directory as your script):
#!/bin/bash cmdLineJMXJar=./cmdline-jmxclient-0.10.3.jar user=yourUser password=yourPassword jmxHost=localhost port=9003 #No User and password so pass '-' echo "Available Operations for com.company.data:type=datasystem,id=0" java -jar ${cmdLineJMXJar} ${user}:${password} ${jmxHost}:${port} com.company.data:type=datasystem,id=0 echo "Executing XML update..." java -jar ${cmdLineJMXJar} - ${jmxHost}:${port} com.company.data:type=datasystem,id=0 jmxForceRefresh
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With