Java Application Monitoring: Tools and Libraries for Metric Collection

Online Python Trainer for Beginners

Learn Python easily without overwhelming theory. Solve practical tasks with automatic checking, get hints in Russian, and write code directly in your browser — no installation required.

Start Course

Java Application Monitoring: Overview of Tools and Libraries



In modern development, monitoring Java applications has become a mandatory practice. Without it, it is impossible to understand how the system behaves under load, where bottlenecks occur, and how to quickly respond to failures. In this article, we will review the key libraries and tools for collecting metrics, tracing, and visualizing the state of Java applications: Micrometer, Prometheus Java Client, JMX, and Java Flight Recorder.



1. Micrometer — A Facade for Metrics



Micrometer is the de facto standard for collecting metrics in the Spring Boot ecosystem and beyond. It provides a unified API that can be used with various backends: Prometheus, Datadog, Graphite, InfluxDB, and others.



Key features:

  • Support for counters (Counter), timers (Timer), histograms (Histogram), and gauges (Gauge).
  • Automatic integration with Spring Actuator.
  • Flexible configuration of tags for metric filtering.


Example of using Micrometer with Prometheus:

// Add the dependency to pom.xml:// <dependency>//     <groupId>io.micrometer</groupId>//     <artifactId>micrometer-registry-prometheus</artifactId>// </dependency>

import io.micrometer.core.instrument.MeterRegistry;import io.micrometer.core.instrument.Counter;import io.micrometer.prometheus.PrometheusMeterRegistry;import io.micrometer.prometheus.PrometheusConfig;

public class MetricsExample { private final Counter requestCounter;

public MetricsExample() { PrometheusMeterRegistry registry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT); requestCounter = Counter.builder("http.requests.total") .description("Total HTTP requests") .tag("method", "GET") .register(registry); }

public void handleRequest() { requestCounter.increment(); }

public String scrapeMetrics() { return registry.scrape(); // returns metrics in Prometheus format }}


Micrometer makes it easy to switch between monitoring systems without changing code.



2. Prometheus Java Client — Direct Metric Collection



Prometheus Java Client is the official library for exporting metrics in Prometheus format. It is less abstract than Micrometer but provides full control over data collection.



Key components:

  • CollectorRegistry — the registry for all metrics.
  • Counter, Gauge, Histogram, Summary — metric types.
  • Built-in HTTP server for the /metrics endpoint.


Example using a simple HTTP server:

import io.prometheus.client.Counter;import io.prometheus.client.exporter.HTTPServer;import io.prometheus.client.hotspot.DefaultExports;

public class PrometheusExample { static final Counter requests = Counter.build() .name("requests_total") .help("Total requests.") .register();

public static void main(String[] args) throws Exception { DefaultExports.initialize(); // adds JVM metrics (memory, GC, threads) HTTPServer server = new HTTPServer(8080); // endpoint /metrics

while (true) { requests.inc(); Thread.sleep(1000); } }}


This library is ideal for cases where you need to quickly set up monitoring without extra dependencies.



3. JMX (Java Management Extensions)



JMX is a built-in mechanism for managing and monitoring the JVM. It allows you to obtain information about memory, threads, classes, and also manage

Recommendations