npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-jmx

v0.9.1

Published

Bridge library to communicate with Java applications through JMX.

Downloads

228

Readme

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:

  • service - The full service URL string, with host, port, protocol and urlPath included. For example "service:jmx:rmi:///jndi/rmi://localhost:3000/jmxrmi".
  • host - Hostname to connect to (defaults to "localhost").
  • port - JMX port number to connect to.
  • protocol - Protocol to use (defaults to "rmi").
  • urlPath - JMX URL Path (defaults to "/jndi/{protocol}://{host}:{port}/jmx{protocol}").
  • username - JMX authentication username.
  • password - JMX authentication password.

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.

  • mbean - MBean query address as string. For example "java.lang:type=Memory".
  • attribute - Attribute name as string.
  • callback(attrValue)

Client.getAttributes(mbean, attributes, callback)

Returns an attribute list from a MBean.

  • mbean - MBean query address as string. For example "java.lang:type=Memory".
  • attributes - Attribute names as an array of strings.
  • callback(attrValue)

Client.getDefaultDomain(callback)

Returns the default domain as string.

  • callback(domainName)

Client.getDomains(callback)

Returns an array of domain names.

  • callback(domainsArray)

Client.getMBeanCount(callback)

Returns total the number of MBeans.

  • callback(mbeanCount)

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

Invokes a MBean operation.

  • mbean - The MBean query address as string. For example "java.lang:type=Memory".
  • methodName - The method name as string.
  • params - The parameters to pass to the operation as array. For example [ 1, 5, "param3" ].
  • signature (optional) - An array with the signature of the params. Sometimes may be necessary to use this if class names are not correctly detected (gives a NoSuchMethodException). For example [ "int", "java.lang.Integer", "java.lang.String" ].
  • callback(returnedValue)

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

  • connect
  • disconnect
  • error - Passes the error as first parameter to the callback function.

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

Changes an attribute value of the MBean.

  • mbean - The MBean query address as string. For example "java.lang:type=Memory".
  • attribute - The attribute name as string.
  • value - The attribute value.
  • className (optional) - The attribute java className. Sometimes may be necessary to use this if value type is not correctly detected (gives a InvalidAttributeValueException). For example "java.lang.Long".
  • callback() (optional)

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 ([email protected]) | 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.