Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mismatch between Spring Actuator's "jvm.memory.max" metric and Runtime.getRuntime().maxMemory()

I'm trying out Spring Boot Actuator and looking at the "/actuator/metrics/jvm.memory.max" endpoint.

I am also running my Springboot app with the following JVM option:

-Xmx104m

I created an endpoint ("/memory" which returns the Total, Free, Used & Max memory for the app. I used Runtime.getRuntime().getXXX() methods for this.

The question that I have is that the value Springboot's "jvm.memory.max" shows me in bytes does not match with the -Xmx value and what the "/memory" endpoint shows me.

Any thoughts why this mismatch?

enter image description here

enter image description here

like image 419
vksinghh Avatar asked Feb 08 '19 11:02

vksinghh


Video Answer


1 Answers

Spring Boot uses Micrometer for its metrics support. The jvm.memory.max metrics is produced by Mirometer's JvmMemoryMetrics class using MemoryPoolMXBean.getUsage().getMax().

The MemoyPoolMXBean exposes information about both heap and non-heap memory and Micrometer separates these using tags on the jvm.memory.max metric. In the output shown in the question, the value is the heap and non-heap memory combined which is why it is not the same as the heap-specific value configured with -Xmx.

You can drill down into a metric using its tags and query parameters. This is described in the Actuator's documentation. For example, to get the max heap memory, you would use http://localhost:9001/actuator/metrics/jvm.memory.max?tag=area:heap.

like image 63
Andy Wilkinson Avatar answered Sep 21 '22 16:09

Andy Wilkinson