Skip to content
This repository was archived by the owner on Jun 16, 2023. It is now read-only.

Commit

Permalink
using_available_mem_and_forward_compatibility_free_mem
Browse files Browse the repository at this point in the history
  • Loading branch information
superwood committed Feb 10, 2017
1 parent 6eb7e18 commit 3e515df
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class LinuxResource {
private static final Pattern CPU_TIME_FORMAT = Pattern.compile("^cpu[ \t]+([0-9]+)[ \t]+([0-9]+)[ \t]+([0-9]+)");

private static final String PROCFS_MEMINFO = "/proc/meminfo";
private static final String MEMINFO_MEMAVAILABLE = "MemAvailable";
public static final long JIFFY_LENGTH_IN_MILLIS;
static {
long jiffiesPerSecond = getJiffies();
Expand Down Expand Up @@ -190,8 +191,13 @@ public static Long getAvailablePhysicalMem() {
return 0L;
}
try {

List<String> lines = IOUtils.readLines(new FileInputStream(PROCFS_MEMINFO));
String free = lines.get(2).split("\\s+")[1];
String name = lines.get(2).split(":")[0].trim();
if( ! MEMINFO_MEMAVAILABLE.equals(name) ){

This comment has been minimized.

Copy link
@longdafeng

longdafeng Feb 10, 2017

Contributor

这个地方推荐使用 StringUtils.indexOfIgnoreCase(lines.get(2), MEMINFO_MEMAVAILABLE) < 0

free = lines.get(1).split("\\s+")[1];
}
return Long.valueOf(free);
} catch (Exception ignored) {
LOG.warn("failed to get total free memory.");
Expand Down

0 comments on commit 3e515df

Please sign in to comment.