node-jmx

NPM version Code Climate Build Status Coverage Status

Node.js bridge library to communicate with Java applications through JMX.

Requirements

Installation

$ npm install jmx

Usage examples

var jmx = require("jmx");

client = jmx.createClient({
  host: "localhost", // optional
  port: 3000
});

client.connect();
client.on("connect", function() {

  client.getAttribute("java.lang:type=Memory", "HeapMemoryUsage", function(data) {
    var used = data.getSync('used');
    console.log("HeapMemoryUsage used: " + used.longValue);
    // console.log(data.toString());
  });

  client.setAttribute("java.lang:type=Memory", "Verbose", true, function() {
    console.log("Memory verbose on"); // callback is optional
  });

  client.invoke("java.lang:type=Memory", "gc", [], function(data) {
    console.log("gc() done");
  });

});
client = jmx.createClient({
  service: "service:jmx:rmi:///jndi/rmi://localhost:3000/jmxrmi"
});

You can check the node-java documentation to learn how to work with java objects in node.js.

Documentation

jmx.createClient(options)

Returns a Client object.

options

options is a hash table with the following values:

Client.connect()

Connects to the JMX server. Emits connect event when done.

Client.disconnect()

Disconnects from the JMX server. Emits disconnect event when done.

Client.getAttribute(mbean, attribute, callback)

Returns an attribute from a MBean.

Client.getAttributes(mbean, attributes, callback)

Returns an attribute list from a MBean.

Client.getDefaultDomain(callback)

Returns the default domain as string.

Client.getDomains(callback)

Returns an array of domain names.

Client.getMBeanCount(callback)

Returns total the number of MBeans.

Client.invoke(mbean, methodName, params, [signature,] [callback])

Invokes a MBean operation.

Client.listMBeans(callback)

Lists server MBeans. Callback returns an array of strings containing MBean names.

Client.on(event, callback)

Adds a listener for the especified event.

events

Client.setAttribute(mbean, attribute, value, [className,] [callback])

Changes an attribute value of the MBean.

Error handling

Errors are not printed to the console by default. You can catch them with something like the following:

client.on("error", function(err) {
  // ...
});

Debugging

You can enable debugging and error printing to console using NODE_DEBUG environment variable:

$ NODE_DEBUG="jmx" node [...]

Testing

See TESTING.md.

Contributing

Please do not hesitate to open an issue with any questions or problems.

See CONTRIBUTING.md.

TODO

See TODO.md.

History

See CHANGELOG.md.

License and Author

   
Author: Xabier de Zuazo (xabier@zuazo.org)
Contributor: Eric
Contributor: DarkSorrow
Copyright: Copyright (c) 2015, Xabier de Zuazo
Copyright: Copyright (c) 2013-2015 Onddo Labs, SL.
License: Apache License, Version 2.0
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.