metrics icon indicating copy to clipboard operation
metrics copied to clipboard

jvm.memory.total.max calculated incorrectly

Open J3173 opened this issue 2 years ago • 0 comments

jvm.memory.total.max is calculated by adding the heap maximum and the non-heap maximum:

https://github.com/dropwizard/metrics/blob/7a755288e2290cbcb0caab9d10a07994b4988012/metrics-jvm/src/main/java/com/codahale/metrics/jvm/MemoryUsageGaugeSet.java#L50-L51

This is fine when both the heap maximum and the non-heap maximum are set. But when either is undefined (has value -1) I think this is incorrect. You can end up with a situation where total.use is larger than total.max, see the table below:

type .use .max
heap 210.47M 259.52M
non-heap 256.97M -1
total 467.44M 259.52M

My suggestion would be letting jvm.memory.total.max return -1 when either the heap maximum or the non-heap maximum is -1.

J3173 avatar May 04 '22 12:05 J3173