CARVIEW |
jmesnil / jmx-js
- Source
- Commits
- Network (0)
- Issues (0)
- Downloads (0)
- Wiki (1)
- Graphs
-
Branch:
master
click here to add a description
click here to add a homepage
name | age | message | |
---|---|---|---|
![]() |
.classpath | Mon Aug 11 11:06:31 -0700 2008 | Initial commit [jmesnil] |
![]() |
.gitignore | Mon Aug 11 11:06:31 -0700 2008 | Initial commit [jmesnil] |
![]() |
.project | Mon Aug 11 11:06:31 -0700 2008 | Initial commit [jmesnil] |
![]() |
META-INF/ | Mon Aug 11 11:06:31 -0700 2008 | Initial commit [jmesnil] |
![]() |
README.markdown | Mon Dec 21 04:06:41 -0800 2009 | fixed markdown syntax [jmesnil] |
![]() |
build.xml | Mon Dec 21 04:08:49 -0800 2009 | removed 1.6 target from javac target [jmesnil] |
![]() |
examples/ | Mon Aug 11 11:06:31 -0700 2008 | Initial commit [jmesnil] |
![]() |
src/ | Mon Dec 21 03:25:59 -0800 2009 | fixed trailing spaces [jmesnil] |
![]() |
test/ | Mon Aug 11 11:06:31 -0700 2008 | Initial commit [jmesnil] |
jmx4r is a JavaScript bridge for JMX
It can be used to write simple JavaScripts to manage remote Java applications (e.g. JBoss, Tomcat) using JMX.
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:
- Download JSR 223’s engines
- Copy jsr223-engines/javascript/build/js-engine.jar to /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home/lib/ext/
- Download Mozilla Rhino 1.7.R1
- Copy rhino1_7R1/js.jar to /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home/lib/ext/
Examples
To trigger a garbage collection on a Java application:
First, run a Java application:
jconsole \
-J-Dcom.sun.management.jmxremote \
-J-Dcom.sun.management.jmxremote.port=3000 \
-J-Dcom.sun.management.jmxremote.ssl=false \
-J-Dcom.sun.management.jmxremote.authenticate=false
Then, create a file "memory.js":
var memory = mbsc.getMBean('java.lang:type=Memory');
memory.gc();
print("after gc: " + memory.heapMemoryUsage.get("used"));
Finally, run the script to trigger a GC on the remote Java application:
java -jar build/jmx-js.jar memory.js -p 3000 example/memory.js
This expects the remote Java application (e.g. jconsole) running on localhost to accept remote JMX connection on the port 3000.
How to Build
Retrieve the project:
git clone git://github.com/jmesnil/jmx-js.git
cd jmx-js
Build the jar
ant jar
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".