Video in progress

Which of the JVM metrics from Micrometer do you watch continuously, and what problems do they show in advance?

Mainly heap and GC: how the old generation's used memory grows after GC, and GC pause time and frequency. Beyond that, the number and state of threads, direct/metaspace memory, RSS relative to the container limit, CPU throttling and pool metrics.

📖 Answer

Spring Boot Actuator provides the jvm.*, process.* and system.* metrics on its own. You have to pick out the useful ones.

Memory:

  • jvm_memory_used_bytes{area="heap"} says little by itself: the "sawtooth" shape is normal. The real signal is the low points left after GC. If they keep climbing over hours, there is a memory leak or cache growth.
  • jvm_gc_live_data_size_bytes / jvm_gc_max_data_size_bytes: how full the old generation is. If it goes past 80–90%, expect an OOM or non-stop full GCs soon.
  • jvm_buffer_memory_used_bytes{id="direct"}: in applications that use Netty or NIO, off-heap leaks show up here.
  • in a container: if the pod's RSS approaches limits.memory, it can be OOMKilled even when the heap looks fine (metaspace, thread stacks, native memory).

GC:

rate(jvm_gc_pause_seconds_sum[5m]) / rate(jvm_gc_pause_seconds_count[5m])  # average pause
rate(jvm_gc_pause_seconds_sum[5m])                                        # time spent in GC per second

If the second goes over 0.1, the application is spending 10% of its time in GC. That affects p99 directly.

Threads:

  • if jvm_threads_live_threads keeps growing, it's a thread leak (a new Thread per request or an unclosed executor);
  • if jvm_threads_states_threads{state="blocked"} spikes, it's lock contention.

CPU: process_cpu_usage and cgroup throttling in a container. If the CPU limit is low, GC threads get throttled too and pauses stretch out sharply.

You don't have to alert on all of these metrics. Alerts usually go on "GC share" and "old gen fullness", and the rest sit on a dashboard you look at during an investigation.