Author: @Bharath Srinivas
Co-Authored By: @GIREESH PUNATHIL
Introduction
In part 1 of this Java application monitoring series, Java Monitoring 101: Basic Concepts ,we introduced essential ingredients in JVM monitoring, metrics as well as their constituent events, and mechanisms to capture those events. In this article, we will talk about common monitoring tools that are used in the Java ecosystem, their advantages and challenges and how they can be used effectively to monitor Java applications and help to maintain production stability of your business critical Java workloads.
Commonly used monitoring tools
There are wide variety of monitoring tools that are used for monitoring Java applications. These are tools ranging from profilers, performance monitors, tracers and many more. Each group of tools provides different perspectives of the application and thereby showcases different angles to the problem that we are trying to isolate and diagnose. Each monitoring tool provides a separate set of information. So, it is always advisable to use more than one tool and select the combination of tools that best suits your application needs. Let’s have a look at some of the important Java monitoring tools:
Java Flight Recorder (JFR)
JFR, or alternatively JDK Flight Recorder by OpenJDK, are Java monitoring tools that help in collecting information about events during the execution of a Java application. They are production time profiling and diagnostics engines built into the JVM. The main function of these monitoring tools is to run in conjunction with the running Java application, collect relevant metrics as per the configuration, collate and summarise the collected metrics, record these metrics in the form of a JFR record (in headless mode) or transport the metrics through the network (in socket mode or live mode) . Since the JFR records are binary files, it requires another tool to extract, interpret and visualize the JFR record in a human-consumable way so that developers can figure out what the problem may be and how to solve it. JDK Mission Control (JMC) helps in extracting and visualizing the JFR record. It acts as the client tool used to look at recordings produced by the JFR. The main advantage of using Java Flight Recorder (JFR) is its ability to provide comprehensive and low-overhead monitoring and profiling of Java applications in production environments.
The JFR can be started in two different ways:
-
At JVM startup, by configuring it in the command line (e.g. using the -XX:StartFlightRecording command). See an example of this below:
-
Attach it to an already running JVM (e.g. using jcmd <pid> <command>). See an example of this below:
Jconsole
The Java Monitoring and Management Console (Jconsole) is a graphical tool that helps developers monitor and manage their java applications. The JConsole tool is built on the java.lang.management API and provides a variety of information like running threads, memory usage, and information about the loaded classes, and more. Jconsole allows developers to monitor local as well as remote Java processes. One of the significant advantages of using the Jconsole tool is that it provides more of a graphical, user friendly interface when compared to other tools, which can help to make it easier to understand and solve the identified problem.
Local and Remote Monitoring can be done with the help of below commands:
Below is an example of the interface you can expect when using Jconsole.
Jstat
Jstat is a command line tool that provides statistics about the Java Virtual Machine. Jstat does not require the JVM to start with any special arguments, it is included in the JDK and enabled by default. Jstat provides a variety of options so that it gives the users an understanding of all the aspects of JVM. This tool is often preferred by individuals who choose command line tools over graphical tools.
Common Jstat commands that are useful for developers, includes:
Healthcenter
Healthcenter is a monitoring and diagnostic tool used to monitor IBM Java SDK based Java applications. The main advantage of using healthcenter is that it uses less processor time and memory when compared to other monitoring tools. It consists of two parts:
Healthcenter operates in two modes based on when the client interprets the recorded data:
-
Headless mode: collects and records metrics data from a running JVM and writes into disc.
-
Live mode (aka socket mode): collects and transports metrics data from a running JVM through a socket which clients can tap into.
Summary and next steps
In this article, we’ve explored some useful tools that can be used to effectively monitor java applications, with each tool having it’s own way of monitoring and it’s own unique set of benefits and challenges. For example, tools like JFR and Healthcenter focus on reducing the performance overhead, whereas tools like Jconsole and Jstat are used to mainly monitor the JVM statistics. So, it depends on the users to decide what tool should be used based on their needs. In the next article in this series, Java Monitoring 101: Debugging, we will take a look at the various problems that can be addressed using monitoring and show how to resolve them.
If you’re interested in continuing your learning of monitoring, check out this free, in-depth learning course on edx: [Monitoring and Observability for Application Developers](https://www.edx.org/learn/devops/ibm-monitoring-and-observability-for-application-developers). This course provides a comprehensive overview of monitoring and observability, and teaches you the hands-on skills to employ monitoring, observability, and logging for your application.
Alternatively, take a look at the interactive guides available on the Open Liberty website that take you through how to use further monitoring/observability tools for your Java applications at the application level: https://openliberty.io/guides/#observability.