What is the meaning of mem and mem.free in Spring Boot metrics exposed via /metrics endpoint?
We are load testing a new Spring Boot microservice deployed in three nodes, mem for each box is always around 250M out of 4G total in VM, mem.free under unrealistic load like 100 times of normal load can go down to 15M and slowly recovers after the test.
They are not heap memory because Spring Boot Metrics report them separately and they are not Java process itself because from command line I can see no matter how big the load, it stays at 16% of 4G which is about 900MB. Here is /metrics call response snippet:
{
mem: 227657,
mem.free: 44280,
processors: 2,
instance.uptime: 80393579,
uptime: 80414405,
systemload.average: 0.03,
heap.committed: 133632,
heap.init: 61440,
heap.used: 89351,
heap: 872448,
nonheap.committed: 96688,
nonheap.init: 2496,
nonheap.used: 94025,
nonheap: 0,
threads.peak: 109,
threads.daemon: 34,
threads.totalStarted: 183,
threads: 63,
classes: 10079,
classes.loaded: 10155,
classes.unloaded: 76,
.... }
Grafana mem.free screenshot for last 24 hours, the lowest point is during that heavy load testing (15MB!)
Grafana cpu and memory usage report is shown below which tells me CPU under stressed during that period which is understandable. However Java process memory (only 1 Spring boot running in that box) is stable:
So again what is the meaning of mem and mem.free in Spring Boot metrics?
These actuators provide an easy way to monitor and control just about every aspect of a Spring Boot application. In this tutorial, we'll look at using the metrics actuator to create a self-hosted monitoring solution for Spring Boot applications. 2. Metrics Database
The first part of monitoring Spring Boot applications is choosing a metrics database. By default, Spring Boot will configure a Micrometer metrics registry in every application. This default implementation collects a pre-defined set of application metrics such as memory and CPU usage, HTTP requests, and a few others.
But these metrics are stored in memory only, meaning they will be lost any time the application is restarted. To create a self-hosted monitoring solution, we should first choose a metrics database that lives outside the Spring Boot application.
To enable Spring Boot Actuator, we just need to add the spring-boot-actuator dependency to our package manager. In Maven: <dependency> <groupId> org.springframework.boot </groupId> <artifactId> spring-boot-starter-actuator </artifactId> </dependency>. Note that this remains valid regardless of the Boot version, ...
mem
is the total amount of memory that the JVM is currently using. It is the sum of two values:
Runtime.totalMemory()
The value of getUsed()
from MemoryMXBean.getNonHeapMemoryUsage()
mem.free
is the amount of memory that's available to the JVM. It's a single value:
Runtime.freeMemory()
To see more of the details, take a look at Spring Boot's SystemPublicMetrics
class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With