JAJMX is high level scala JMX API. The goal is to simplify to the maximum JMX operations. ( ** project page **)

Latest changes :
  • ConnectException taken into account in RichMBean genericGetter in order to propagates connection failures and allow api users to restarts...
  • CompositeData & TabularData support enhancements
  • API CHANGES !! getOption disappear, get method now returns an Option. previous get method replaced by apply.
  • more tests cases
  • jmx mbeans queries was broken, now the query is build with an object name instead of a string
  • findMBeanServers made public and moved to JMX object
  • checkServiceURL added to JMXObject : checks if a jmx service url works.
  • getInt added to mbean
  • now using sbt 0.11.3
  • now using sbt-assembly 0.8.1
  • now using sbteclipse 2.1.0-RC1
  • now using scalatest 1.8
  • trap exceptions while building attributes map in RichMBean
  • various examples scripts fixes

jvm force gc script


#!/bin/sh
JAVA_OPTS=""
JAVA_OPTS=$JAVA_OPTS" -Dcom.sun.management.jmxremote"
JAVA_OPTS=$JAVA_OPTS" -Dcom.sun.management.jmxremote.port=9999"
JAVA_OPTS=$JAVA_OPTS" -Dcom.sun.management.jmxremote.authenticate=false"
JAVA_OPTS=$JAVA_OPTS" -Dcom.sun.management.jmxremote.ssl=false"
exec java $JAVA_OPTS -jar jajmx.jar -nocompdaemon -usejavacp -savecompiled "$0" "$@"
!#

jajmx.JMX.once("127.0.0.1", 9999) { jmx =>
jmx.memory map { _ set("Verbose", true)} // Activate Verbose GC, to see on stdout next call effect
jmx.memory map {_ call "gc"} // Force GC
}

jmx grep script


#!/bin/sh
JAVA_OPTS=""
JAVA_OPTS=$JAVA_OPTS" -Dcom.sun.management.jmxremote"
JAVA_OPTS=$JAVA_OPTS" -Dcom.sun.management.jmxremote.port=9999"
JAVA_OPTS=$JAVA_OPTS" -Dcom.sun.management.jmxremote.authenticate=false"
JAVA_OPTS=$JAVA_OPTS" -Dcom.sun.management.jmxremote.ssl=false"
exec java $JAVA_OPTS -jar jajmx.jar -nocompdaemon -usejavacp -savecompiled "$0" "$@"
!#

import jajmx._

if (args.size == 0) {
println("Usage : jmxgrep host port searchMask1 ... searchMaskN")
println(" no args given so now let's connecting to myself, and list my mbeans...")
}
val host = if (args.size>1) args(0) else "localhost"
val port = if (args.size>2) args(1).toInt else 9999
val masks = if (args.size>3) args.toList.drop(2) map {s=>("(?i)"+s).r} else List.empty[util.matching.Regex]


def truncate(str:String, n:Int=60) = {
val nonl=str.replaceAll("\n", " ").replaceAll("\r", "")
if (nonl.size>n) nonl.take(n)+"..." else nonl
}

JMX.once(host, port) { jmx =>
for(mbean <- jmx.mbeans ; attr <- mbean.attributes; value <- mbean.getString(attr)) {
val found = List(mbean.name, attr.name, value) exists { item => masks exists {_.findFirstIn(item).isDefined } }
if (masks.isEmpty || found) println("%s - %s = %s".format(mbean.name, attr.name, truncate(value)))
}
}