public
Description: A JavaScript Bridge for JMX
Homepage:
Clone URL: git://github.com/jmesnil/jmx-js.git
jmesnil (author)
Mon Aug 11 12:12:59 -0700 2008
commit  acd6a2c1a64628d03ac9d5ed957935e7a0cc9da2
tree    1aebb52b796e773eed37308342d473fd0a5ca598
parent  40564b35d91d0d5c3bc535cd34e25fc927a12a65
jmx-js /
README
jmx4r is a JavaScript bridge for JMX

It can be used to write simple JavaScripts to manage remote Java applications (e.g. JBoss[http://www.jboss.org],
Tomcat[http://tomcat.apache.org/]) using JMX[http://java.sun.com/javase/technologies/core/mntr-mgmt/javamanagement/].

== Examples 

To trigger a garbage collection on a Java application:

1. Create a file "memory.js".

    var memory = mbsc.getMBean('java.lang:type=Memory');

    memory.gc();
    print("after gc: " + memory.heapMemoryUsage.get("used"));

2. Run the script to trigger a GC on a remote Java application:

   java -jar jmx-js.jar memory.js -h node1 -p 3000 memory.js
   
This expects the remote Java application running on node1 to accept remote JMX connection
on the port 3000.

== How to build

1. Retrieve the project:

   git clone git://github.com/jmesnil/jmx-js.git
   cd jmx-js
   
2. Build the jar

   ant jar
   
3. Run the example

   java -jar jmx-js.jar examples/memory.js 
   
== How to write scripts

An object "mbsc" can be used to retrieve MBean:
  
   var mbean = mbsc.getMBean('java.lang:type=Memory');  
   
   or
   
   var mbeans = mbsc.getMBeans('java.lang:type=MemoryPool,*');
   
An object "args" contains all the remaning arguments passed on the command line after removing the file name and the 
optional host and port.
For example, if the script is run with "java -jar jmx-js.jar logging.js -p 3000 FINEST", in the script, args[0] is set 
to "FINEST".