dropwizard/metrics

jvm.memory.total.max calculated incorrectly

J3173 opened this issue · 2 comments

J3173 commented

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

gauges.put("total.max", (Gauge<Long>) () -> mxBean.getHeapMemoryUsage().getMax() +
mxBean.getNonHeapMemoryUsage().getMax());

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 commented

This issue is still present.

related issue with non-heap.usage being negative:

    "non-heap.committed" : 138084352,
    "non-heap.init" : 7667712,
    "non-heap.max" : -1,
    "non-heap.usage" : -134176576,
    "non-heap.used" : 134176576,