Accessing WildFly JMX Bus Remotely with novaordis-jmx: Difference between revisions
(20 intermediate revisions by the same user not shown) | |||
Line 10: | Line 10: | ||
=Classpath= | =Classpath= | ||
== | ==EAP 6 Classpath== | ||
EAP 6 exposes the JMX bus over its remoting protocol, so the JMX client needs JBoss remoting support in its classpath, which is available in <tt>${JBOSS_HOME}/bin/client/jboss-cli-client.jar</tt>. | |||
<pre> | <pre> | ||
Line 18: | Line 18: | ||
</pre> | </pre> | ||
== | ==EAP 7 Classpath== | ||
=URL= | =URL= | ||
The protocol to use for EAP 6 is "remoting-jmx". novaordis-jmx builds a <tt>javax.management.remote.JMXServiceURL</tt> which in turn prepends automatically "service:imx" and sends "service:jmx:remoting-jmx://<host>:<port>" to the underlying JMX logic. | |||
<pre> | <pre> | ||
JMXServiceURL jmxServiceURL = new JMXServiceURL("remoting-jmx", host, port); | |||
</pre> | |||
=Authentication= | |||
In case authentication is needed, see {{Internal|Remoting_WildFly_Subsystem_Concepts#Authentication_for_Remoting_JMX_Access|Authentication for Remoting JMX Access}} | |||
=novaordis-jmx API= | |||
<pre> | |||
JmxAddress address = new JmxAddress("jmx://localhost:9999"); | |||
address.setJmxServiceUrlProtocol("remoting-jmx"); | |||
JmxClient client = new JmxClient(address); | |||
client.connect(); | |||
MBeanServerConnection mBeanServerConnection = client.getMBeanServerConnection(); | |||
mBeanServerConnection.getMBeanCount(); | |||
</pre> | </pre> | ||
Example: {{External|https://github.com/NovaOrdis/novaordis-jmx/blob/master/src/main/java/io/novaordis/jmx/Main.java}} | |||
=Underlying JMX API= | |||
<pre> | <pre> | ||
JMXServiceURL jmxServiceURL = new JMXServiceURL("remoting-jmx", host, port); | JMXServiceURL jmxServiceURL = new JMXServiceURL("remoting-jmx", host, port); | ||
JMXConnector jmxConnector = JMXConnectorFactory.connect(jmxServiceURL); | |||
MBeanServerConnection mBeanServerConnection = jmxConnector.getMBeanServerConnection(); | |||
mBeanServerConnection.getMBeanCount(); | |||
</pre> | |||
=Alternative JMX API= | |||
A more generic way to connect to a JMX server, where it is assumed that an implementation of ClientProvider class is available in classpath: | |||
<pre> | |||
JMXServiceURL jmxServiceURL = new JMXServiceURL(<protocol>, host, port); | |||
Map<String, String> environment = new HashMap<>(); | |||
environment.put( | |||
"jmx.remote.protocol.provider.pkgs", | |||
<a-package-that-contains-a-subpackage-named-after-the-protocol-which-in-turn-contains-a-ClientProvider-class>); | |||
JMXConnector jmxConnector = JMXConnectorFactory.connect(jmxServiceURL, environment); | |||
MBeanServerConnection mBeanServerConnection = jmxConnector.getMBeanServerConnection(); | |||
mBeanServerConnection.getMBeanCount(); | |||
</pre> | </pre> | ||
For the sequence of API calls presented above, the JMX runtime assumes that the value associated with the "jmx.remote.protocol.provider.pkgs" in the environment Map contains the prefix of the name of one or more packages. | |||
The package should be available in the classpath, their names should start with the value mentioned above, and it should end with ".<protocol>" String. It also should contain a "ClientProvider" must implement [https://docs.oracle.com/javase/8/docs/api/javax/management/remote/JMXConnectorProvider.html javax.management.remote.JMXConnectorProvider]. |
Latest revision as of 07:30, 8 July 2017
Internal
Overview
The WildFly JMX bus can be accessed programmatically using standard JMX remoting API, as described in the Remote Access to a JMX Server section. novaordis-jmx is a library that provides a thin layer of functionality in top of the client-side JMX remoting API, with the intention to facilitate programmatic JMX access to a remote JMX bus. Note that novaordis-imx is NOT necessary for programmatic JMX access, but its code introduces a certain degree of convenience, and it can be used as an example for direct use of the JMX remote API.
Classpath
EAP 6 Classpath
EAP 6 exposes the JMX bus over its remoting protocol, so the JMX client needs JBoss remoting support in its classpath, which is available in ${JBOSS_HOME}/bin/client/jboss-cli-client.jar.
java ... -cp ...:${JBOSS_HOME}/bin/client/jboss-cli-client.jar:...
EAP 7 Classpath
URL
The protocol to use for EAP 6 is "remoting-jmx". novaordis-jmx builds a javax.management.remote.JMXServiceURL which in turn prepends automatically "service:imx" and sends "service:jmx:remoting-jmx://<host>:<port>" to the underlying JMX logic.
JMXServiceURL jmxServiceURL = new JMXServiceURL("remoting-jmx", host, port);
Authentication
In case authentication is needed, see
novaordis-jmx API
JmxAddress address = new JmxAddress("jmx://localhost:9999"); address.setJmxServiceUrlProtocol("remoting-jmx"); JmxClient client = new JmxClient(address); client.connect(); MBeanServerConnection mBeanServerConnection = client.getMBeanServerConnection(); mBeanServerConnection.getMBeanCount();
Example:
Underlying JMX API
JMXServiceURL jmxServiceURL = new JMXServiceURL("remoting-jmx", host, port); JMXConnector jmxConnector = JMXConnectorFactory.connect(jmxServiceURL); MBeanServerConnection mBeanServerConnection = jmxConnector.getMBeanServerConnection(); mBeanServerConnection.getMBeanCount();
Alternative JMX API
A more generic way to connect to a JMX server, where it is assumed that an implementation of ClientProvider class is available in classpath:
JMXServiceURL jmxServiceURL = new JMXServiceURL(<protocol>, host, port); Map<String, String> environment = new HashMap<>(); environment.put( "jmx.remote.protocol.provider.pkgs", <a-package-that-contains-a-subpackage-named-after-the-protocol-which-in-turn-contains-a-ClientProvider-class>); JMXConnector jmxConnector = JMXConnectorFactory.connect(jmxServiceURL, environment); MBeanServerConnection mBeanServerConnection = jmxConnector.getMBeanServerConnection(); mBeanServerConnection.getMBeanCount();
For the sequence of API calls presented above, the JMX runtime assumes that the value associated with the "jmx.remote.protocol.provider.pkgs" in the environment Map contains the prefix of the name of one or more packages.
The package should be available in the classpath, their names should start with the value mentioned above, and it should end with ".<protocol>" String. It also should contain a "ClientProvider" must implement javax.management.remote.JMXConnectorProvider.