Created
November 30, 2021 12:04
-
-
Save pedes/e15f90d7420957c1e41483e965af342c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MemoryInfoComponent { | |
private static final long MB = 1048576L; | |
public static Map<String, String> getMemoryStats() throws Exception { | |
Runtime rt = Runtime.getRuntime(); | |
MemoryMXBean mbean = ManagementFactory.getMemoryMXBean(); | |
long usedMemory = rt.totalMemory() - rt.freeMemory(); | |
Map<String, String> memoryStats = new HashMap<>(); | |
memoryStats.put("JVM total memory", (rt.totalMemory() / 1048576L) + " MB"); | |
memoryStats.put("JVM used memory", (usedMemory / 1048576L) + " MB"); | |
memoryStats.put("JVM free memory", (rt.freeMemory() / 1048576L) + " MB"); | |
memoryStats.put("Heap init size", (mbean.getHeapMemoryUsage().getInit() / 1048576L) + " MB"); | |
memoryStats.put("Heap max size", (mbean.getHeapMemoryUsage().getMax() / 1048576L) + " MB"); | |
memoryStats.put("Heap used size", (mbean.getHeapMemoryUsage().getUsed() / 1048576L) + " MB"); | |
memoryStats.put("Heap commited", (mbean.getHeapMemoryUsage().getCommitted() / 1048576L) + " MB"); | |
return memoryStats; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment