Saturday, April 14, 2012

JAJMX scala script to list all available JVM numerical JMX values

Using JAJMX it becomes very easy to list all available numerical values of a given JVM JMX plateform :
#!/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 fr.janalyse.jmx._

val host  = args.headOption.getOrElse("localhost")
val port  = if (args.size>1) args.tail.head.toInt else 9999

JMX.once(host, port) { jmx =>
  for(mbean <- jmx.mbeans ;
      attr  <- mbean.attributes collect {case n:RichNumberAttribute => n};
      value <- mbean.getLong(attr)) {
    println("%s - %s = %d".format(mbean.name, attr.name, value))
  }
}
Some jvm parameters (JAVA_OPTS) have been added in order to make possible to test this script against itself. So without any arguments it will give you such results :
$ ./lsnum
java.lang:type=Memory - ObjectPendingFinalizationCount = 0
java.lang:type=MemoryPool,name=PS Eden Space - CollectionUsageThreshold = 0
java.lang:type=MemoryPool,name=PS Eden Space - CollectionUsageThresholdCount = 0
java.lang:type=MemoryPool,name=PS Survivor Space - CollectionUsageThreshold = 0
java.lang:type=MemoryPool,name=PS Survivor Space - CollectionUsageThresholdCount = 0
java.lang:type=MemoryPool,name=Code Cache - UsageThreshold = 0
java.lang:type=MemoryPool,name=Code Cache - UsageThresholdCount = 0
java.lang:type=GarbageCollector,name=PS MarkSweep - CollectionCount = 1
java.lang:type=GarbageCollector,name=PS MarkSweep - CollectionTime = 90
java.lang:type=Runtime - StartTime = 1334354060679
java.lang:type=Runtime - Uptime = 5497
java.lang:type=ClassLoading - LoadedClassCount = 4806
java.lang:type=ClassLoading - UnloadedClassCount = 0
java.lang:type=ClassLoading - TotalLoadedClassCount = 4806
java.lang:type=Threading - DaemonThreadCount = 12
java.lang:type=Threading - PeakThreadCount = 13
java.lang:type=Threading - CurrentThreadCpuTime = 40000000
java.lang:type=Threading - CurrentThreadUserTime = 40000000
java.lang:type=Threading - ThreadCount = 13
java.lang:type=Threading - TotalStartedThreadCount = 13
java.lang:type=Compilation - TotalCompilationTime = 7144
java.lang:type=MemoryPool,name=PS Perm Gen - CollectionUsageThreshold = 0
java.lang:type=MemoryPool,name=PS Perm Gen - CollectionUsageThresholdCount = 0
java.lang:type=MemoryPool,name=PS Perm Gen - UsageThreshold = 0
java.lang:type=MemoryPool,name=PS Perm Gen - UsageThresholdCount = 0
java.lang:type=GarbageCollector,name=PS Scavenge - CollectionCount = 3
java.lang:type=GarbageCollector,name=PS Scavenge - CollectionTime = 57
java.lang:type=OperatingSystem - MaxFileDescriptorCount = 4096
java.lang:type=OperatingSystem - OpenFileDescriptorCount = 19
java.lang:type=OperatingSystem - CommittedVirtualMemorySize = 4598407168
java.lang:type=OperatingSystem - FreePhysicalMemorySize = 10819850240
java.lang:type=OperatingSystem - FreeSwapSpaceSize = 10742177792
java.lang:type=OperatingSystem - ProcessCpuTime = 13030000000
java.lang:type=OperatingSystem - TotalPhysicalMemorySize = 16816541696
java.lang:type=OperatingSystem - TotalSwapSpaceSize = 10742177792
java.lang:type=OperatingSystem - AvailableProcessors = 6
java.lang:type=OperatingSystem - SystemLoadAverage = 0
java.lang:type=MemoryPool,name=PS Old Gen - CollectionUsageThreshold = 0
java.lang:type=MemoryPool,name=PS Old Gen - CollectionUsageThresholdCount = 0
java.lang:type=MemoryPool,name=PS Old Gen - UsageThreshold = 0
java.lang:type=MemoryPool,name=PS Old Gen - UsageThresholdCount = 0

No comments:

Post a Comment