diff options
author | Luck <git@lucko.me> | 2022-04-14 23:03:20 +0100 |
---|---|---|
committer | Luck <git@lucko.me> | 2022-04-14 23:03:20 +0100 |
commit | ecc9ac3fdb731ef3beee2ce45ddf4b355b12745f (patch) | |
tree | 1b3f1541a88025cd86e52d11225d3d86b4dfad4a /spark-common/src/main/java/me | |
parent | 4e60e856bd5c0ac5c48a5a312a263fbec3c343a0 (diff) | |
download | spark-ecc9ac3fdb731ef3beee2ce45ddf4b355b12745f.tar.gz spark-ecc9ac3fdb731ef3beee2ce45ddf4b355b12745f.tar.bz2 spark-ecc9ac3fdb731ef3beee2ce45ddf4b355b12745f.zip |
Try to read total physical memory from /proc on linux
Diffstat (limited to 'spark-common/src/main/java/me')
-rw-r--r-- | spark-common/src/main/java/me/lucko/spark/common/monitor/memory/MemoryInfo.java | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/spark-common/src/main/java/me/lucko/spark/common/monitor/memory/MemoryInfo.java b/spark-common/src/main/java/me/lucko/spark/common/monitor/memory/MemoryInfo.java index 4aa52f4..226f75b 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/monitor/memory/MemoryInfo.java +++ b/spark-common/src/main/java/me/lucko/spark/common/monitor/memory/MemoryInfo.java @@ -67,10 +67,24 @@ public enum MemoryInfo { /* Physical Memory */ public static long getUsedPhysicalMemory() { - return BEAN.getTotalPhysicalMemorySize() - getAvailablePhysicalMemory(); + return getTotalPhysicalMemory() - getAvailablePhysicalMemory(); } public static long getTotalPhysicalMemory() { + // try to read from /proc/meminfo on linux systems + for (String line : LinuxProc.MEMINFO.read()) { + Matcher matcher = PROC_MEMINFO_VALUE.matcher(line); + if (matcher.matches()) { + String label = matcher.group(1); + long value = Long.parseLong(matcher.group(2)) * 1024; // kB -> B + + if (label.equals("MemTotal")) { + return value; + } + } + } + + // fallback to JVM measure return BEAN.getTotalPhysicalMemorySize(); } |