Giter Club home page Giter Club logo

jmfrx's Introduction

JmFrX - A bridge for capturing JMX data with JDK Flight Recorder

The JmFrX project allows to periodically capture JMX MBeans and emit a corresponding JDK Flight Recorder (JFR) event. This allows to

  • Track changes to the values of JMX MBean attributes over time without resorting to external monitoring tools
  • Access JMX data from offline JFR recording files in situations where you cannot directly connect to JMX
  • Emit JMX data via the JFR event streaming API (JEP 349)

More details about JmFrX, its motivation and implementation can be found in the official project announcement. To learn more about JFR itself, please refer to this blog post.

Usage

This project requires OpenJDK 11 or later at runtime.

JmFrX is not yet available from Maven Central yet; in the meantime you can obtain snapshot builds from JitPack. To so, add the following dependency to your project's pom.xml:

...
<dependency>
  <groupId>com.github.gunnarmorling</groupId>
  <artifactId>jmfrx</artifactId>
  <version>master-SNAPSHOT</version>
</dependency>
...

Alternatively, build JmFrX from source (see below) yourself and add the following dependency to your project's pom.xml:

...
<dependency>
  <groupId>dev.morling.jmfrx</groupId>
  <artifactId>jmfrx</artifactId>
  <version>1.0-SNAPSHOT</version>
</dependency>
...

Then, register the JmFrX event type with Flight Recorder in the start-up routine of your program, e.g. its main method, the static initializer of a class loaded early on, an eagerly initialized Spring or CDI bean, etc. A Java agent for this purpose will be provided as part of this project soon. When using Quarkus, an application start-up event listener can be used like so:

@ApplicationScoped
public class EventRegisterer {

  public void registerEvent(@Observes StartupEvent se) {
    Jmfrx.getInstance().register();
  }

  public void unregisterEvent(@Observes ShutdownEvent se) {
    Jmfrx.getInstance().unregister();
  }
}

Start your application.

Now create a JFR configuration file, enabling the JmFrX event type. To do so, open JDK Mission Control, and choose your application in the JVM Browser. Then follow these steps:

  • Right-click the JVM -> Flight Recorder -> Start Flight Recording...
  • Click on Template Manager
  • Copy the Continuous setting and Edit this copy
  • Expand the JMX and JMX Dump nodes
  • Make sure the event is Enabled, choose a period for dumping the chose JMX MBeans (defaults to 60 s) and select the MBeans to be dumped by means of a regular expression, which matches one or more JMX object names:

Configuring JmFrX

  • Click OK and OK
  • Make sure that the template you edited is selected under Event settings
  • Click Finish to begin the recording

Once the recording is complete, open the recording file in JDK Mission Control and go to the Event Browser. You should see periodic events corresponding to the selected MBeans under the JMX node:

JmFrX Events in JDK Mission Control

When not using JDK Mission Control to initiate recordings, but the jcmd utility, also create a configuration as described above. Then export the file from the template manager and specify its name to jcmd via the settings=/path/to/settings.jfc parameter.

Build

This project requires OpenJDK 14 or later for its build. Apache Maven is used for the build. Run the following to build the project:

mvn clean install

Related Work

JDK Mission Control project lead Marcus Hirt discussed a similar project in a blog post in 2016. But unlike the implementation described by Marcus in this post, JmFrX is based on the public and supported APIs for defining, configuring and emitting JFR events, as available since OpenJDK 11.

License

This code base is available ander the Apache License, version 2.

jmfrx's People

Contributors

gunnarmorling avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

dpsoft doytsujin

jmfrx's Issues

Update group id

๐ŸŽ‰ @jiekang, @neugens et al. So the repo is here. Should it be announced anywhere?

Also, this is still using dev.morling.jmfrx as a Maven group id; any suggestions for what to use instead?

Another question: Is Apache license v2 ok? We can change it easily if needed, I'm the only contributor at this point.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.