27 lines
829 B
Java
27 lines
829 B
Java
|
|
package com.tongran.agent.client.utils;
|
||
|
|
|
||
|
|
import java.io.BufferedReader;
|
||
|
|
import java.io.FileReader;
|
||
|
|
import java.io.IOException;
|
||
|
|
import java.util.HashMap;
|
||
|
|
import java.util.Map;
|
||
|
|
|
||
|
|
public class AgentDataUtil {
|
||
|
|
|
||
|
|
public static Map<String, Long> parseMemInfo() throws IOException {
|
||
|
|
Map<String, Long> memInfo = new HashMap<>();
|
||
|
|
try (BufferedReader br = new BufferedReader(new FileReader("/proc/meminfo"))) {
|
||
|
|
String line;
|
||
|
|
while ((line = br.readLine()) != null) {
|
||
|
|
String[] parts = line.split("\\s+");
|
||
|
|
if (parts.length >= 2) {
|
||
|
|
String key = parts[0].replace(":", "");
|
||
|
|
long value = Long.parseLong(parts[1]);
|
||
|
|
memInfo.put(key, value);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return memInfo;
|
||
|
|
}
|
||
|
|
}
|