public
Description: A JavaScript Bridge for JMX
Homepage:
Clone URL: git://github.com/jmesnil/jmx-js.git
jmx-js /
name age message
file .classpath Mon Aug 11 11:06:31 -0700 2008 Initial commit [jmesnil]
file .gitignore Mon Aug 11 11:06:31 -0700 2008 Initial commit [jmesnil]
file .project Mon Aug 11 11:06:31 -0700 2008 Initial commit [jmesnil]
directory META-INF/ Mon Aug 11 11:06:31 -0700 2008 Initial commit [jmesnil]
file README Mon Aug 11 12:17:33 -0700 2008 added Requirements section [jmesnil]
file build.xml Mon Aug 11 11:27:20 -0700 2008 added explicit source="1.6" to javac task adde... [jmesnil]
directory examples/ Mon Aug 11 11:06:31 -0700 2008 Initial commit [jmesnil]
directory src/ Mon Aug 11 11:29:34 -0700 2008 replaced call to deprecated NativeJavaObject.wr... [jmesnil]
directory test/ Mon Aug 11 11:06:31 -0700 2008 Initial commit [jmesnil]
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/].

== Requirements

This bridge works only on Java 6 with a JavaScript engine.
This is the case by default for Sun's JVM on Linux and Windows.
For Mac OS X, there are additional 
steps[http://jmesnil.net/weblog/2008/05/14/how-to-include-javascript-engine-in-apples-java-6-vm/].

== 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".