For years, we've been running Java services with modest heap sizes using +UseParallelOldGC
. Now, we're starting to roll out a new service using a larger heap and the G1 collector. This is going pretty well.
For our services that use +UseParallelOldGC
, we monitor for memory leaks by looking at the old generation size after collection and alerting on a threshold. This works quite well, and in fact saved our bacon just two weeks ago.
Specifically, for +UseParallelOldGC
, we do the following:
ManagementFactory.getMemoryPoolMXBeans()
- Search for the
MemoryPoolMXBean
result with the name ending in"Old Gen"
- Compare
getCollectionUsage().getUsed()
(if available) withgetMax()
Unfortunately, it seems like G1 no longer has a concept of getCollectionUsage()
.
Fundamentally, though, we'd like to monitor the G1 heap size following the last mixed collection it chooses to do in a mixed cycle, or something similar.
For example, outside the VM I would be happy with an awk script that merely found the last '(mixed)'
was that's followed by a '(young)'
and look what the final heap size was (e.g., '1540.0M' 'Heap: 3694.5M(9216.0M)->1540.0M(9216.0M)'
)
Is there any way to do this inside the Java VM?