Skip to content

Monitoring

What is JMX?

The Java virtual machine (Java VM) has built-in instrumentation that enables you to monitor and manage it using the Java Management Extensions (JMX) technology. These built-in management utilities are often referred to as out-of-the-box management tools for the Java VM. You can also monitor any appropriately instrumented applications using the JMX API.

Enabling JMX

To enable and configure the out-of-the-box JMX agent so that it can monitor and manage the Java VM, you must set certain system properties when you start the Java VM. A full set of out-of-the-box management properties described here. Alternatively you can use a tool that complies to the JMX specification, such as JConsole.

Metrics Library

Instrumentation can be achieved by using native JMX or using a modular project like Metrics (GitHub repo). Metrics provides a powerful way to measure the behaviour of your critical components and reporting them to a variety of systems like, JConsole, or making them available through a web server. To install Metrics, we only have to add metrics dependency.

Note: If you are planning to use Metrics in production code, it is highly recommended that you put metrics logic into AOP whenever possible, to avoid mixing instrumentation code with business logic.

Metrics we can use 6 types of metrics:

  1. Gauges: an instantaneous measurement of a discrete value.
  2. Counters: a value that can be incremented and decremented. Can be used in queues to monitorize the remaining number of pending jobs.
  3. Meters: measure the rate of events over time. You can specify the rate unit, the scope of events or event type.
  4. Histograms: measure the statistical distribution of values in a stream of data.
  5. Timers: measure the amount of time it takes to execute a piece of code and the distribution of its duration.
  6. Healthy checks: as his name suggests, it centralize our service’s healthy checks of external systems.

References