wvlet-jmx enables exposing application information through JMX so that you can check the running state of an application outside JVM. For example, you can
use jconsole
program to access JMX parameters.
JMX already provides various JVM metrics (e.g., heap memory usage, GC statistics, etc.). DataDog provides a handy way to collect JMX metrics:
For analyzing application behaviour for longer ranges (5 minute or more), we recommend using Treasure Data along with DataDog:
JMX -> fluentd -> DataDog (For real-time monitoring)
-> Treasure Data -> Presto SQL (Doing metric-driven actions with SQL queries)
libraryDependencies += "org.wvlet" %% "wvlet-jmx" % "(version)"
Usage is simple: Add @JMX
annotation to variables or methods you want to see in JMX.
@JMX(description = "A example MBean object")
class SampleMBean {
@JMX(description = "free memory size")
def freeMemory: Long = {
Runtime.getRuntime.freeMemory()
}
}
case class FieldMBean(@JMX a: Int, @JMX b: String)
class NestedMBean {
@JMX(description = "nested stat")
def stat: Stat = {
new Stat(Random.nextInt(10), "nested JMX bean")
}
}
case class Stat(@JMX count: Int, @JMX state: String)
In this example, stat.count
adn stat.state
will be reported.
You can launch JMXRegistry (e.g., on port 7199) by setting these JVM parameters:
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=7199
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.local.only=false
-Dcom.sun.management.jmxremote.ssl=false
For convenience, you can start JMXRegistry inside your program:
wvlet.jmv.JMXAgent.start(registryPort=7199)