Airframe

Airframe

  • Docs
  • Blog
  • Release Notes
  • GitHub

›Utilities

Resources

  • Overview
  • Articles
  • Release Notes
  • Logos

Framework

  • airframe-di: Dependency Injection
  • Airframe RPC
  • airframe-http: Creating REST Service
  • airframe-rx: ReactiveX interface
  • AirSpec: Testing Framework

Core Modules

  • airframe-codec: Schema-On-Read Object Serializer
  • airframe-config: Application Config Flow
  • airframe-control: Retry/Rate Control
  • airframe-log: Application Logger
  • airframe-metrics: Human-Friendly Measures for Time and Data Size
  • airframe-surface: Object Shape Inspector

Utilities

  • airframe-benchmark: JMH Benchmark
  • airframe-canvas: Off-Heap Memory Manager
  • airframe-fluentd: Fluentd Logger
  • airframe-http-recorder: Web Request/Response Recorder
  • airframe-jdbc: JDBC Connection Pool
  • airframe-jmx: JMX Application Monitor
  • airframe-json: Pure-Scala JSON Parser
  • airframe-launcher: Command-Line Program Launcher
  • airframe-msgpack: Pure-Scala MessagePack Parser
  • airframe-parquet: Parquet Columnar File Reader and Writer
  • airframe-sql: SQL Parser
  • airframe-ulid: ULID Generator

airframe-jmx: JMX Application Monitor

airframe-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:

  • Monitoring Java application through DataDog

For analyzing application behavior 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)

Usage

Maven Central

libraryDependencies += "org.wvlet.airframe" %% "airframe-jmx" % "(version)"

Usage is simple: Add @JMX annotation to variables or methods you want to see in JMX.

Registering JMX parameters

import wvlet.airframe.jmx._

@JMX(description = "A example MBean object")
class SampleMBean {
  @JMX(description = "free memory size")
  def freeMemory: Long = {
    Runtime.getRuntime.freeMemory()
  }
}

// Register the MBean to make it visible from JMX interface
val mbean = new SampleMBean
JMXAgent.defaultAgent.register[SampleMBean](mbean)

Nested parameters

To report nested parameters, add @JMX to parameters as well:

class NestedMBean {
  @JMX(description = "nested stat")
  def stat: Stat = {
    Stat(Random.nextInt(10), "nested JMX bean")
  }
}

case class Stat(@JMX count: Int, @JMX state: String)

In this example, stat.count and stat.state will be reported.

Specify parameter names explicitly

Parameter names are automatically generated but also can be specified explicitly.

@JMX(description = "A example MBean object")
class NamedMBean {
  @JMX(name = "memory.free", description = "free memory size")
  def freeMemory: Long = {
    Runtime.getRuntime.freeMemory()
  }
}

Launching JMX Registry

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.airframe.jmx.JMXAgent.start(registryPort=7199)

Using airframe-jmx with Airframe DI

import wvlet.airframe._
import wvlet.airframe.jmx._

case class MyAppStats(
  @JMX(description = "application access count")
  accessCount:Int
)

@JMX(description = "My application")
trait MyApp { self =>

  bind[JMXAgent].onStart { agent =>
    // Register MyApp to JMX registry when starting the application
    agent.register[MyApp](self)
  }

  private var accessCount: Long = 0

  @JMX(description = "application stats")
  def stats: MyAppStats = {
    MyAppStats(accessCount)
  }
}

← airframe-jdbc: JDBC Connection Poolairframe-json: Pure-Scala JSON Parser →
  • Usage
  • Registering JMX parameters
  • Nested parameters
  • Specify parameter names explicitly
  • Launching JMX Registry
  • Using airframe-jmx with Airframe DI
Airframe
Docs
Documentation
Community
Gitter Chat
More
GitHubStar
airframe logo
Copyright © 2024 wvlet.org