|
28 | 28 | import com.flow.platform.util.Logger; |
29 | 29 | import com.google.common.collect.Lists; |
30 | 30 | import com.google.common.collect.Maps; |
| 31 | +import com.sun.management.OperatingSystemMXBean; |
| 32 | +import java.lang.management.ManagementFactory; |
31 | 33 | import java.time.ZonedDateTime; |
32 | 34 | import java.util.ArrayList; |
33 | 35 | import java.util.HashMap; |
@@ -236,16 +238,15 @@ public void run() { |
236 | 238 | private String collectionAgentInfo() { |
237 | 239 | String javaVersion = System.getProperty("java.version"); |
238 | 240 | String osName = System.getProperty("os.name"); |
239 | | - Runtime runtime = Runtime.getRuntime(); |
240 | | - int kb = 1024; |
241 | | - long total = runtime.totalMemory(); |
242 | | - long free = runtime.freeMemory(); |
| 241 | + OperatingSystemMXBean os = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean(); |
| 242 | + long total = os.getTotalPhysicalMemorySize(); |
| 243 | + long free = os.getFreePhysicalMemorySize(); |
243 | 244 | long use = total - free; |
244 | 245 | Map<String, String> dic = new HashMap<>(7); |
245 | 246 | dic.put("javaVersion", javaVersion); |
246 | 247 | dic.put("osName", osName); |
247 | | - dic.put("totalMemory", total / kb + "MB"); |
248 | | - dic.put("useMemory", use / kb + "MB"); |
| 248 | + dic.put("totalMemory", Long.toString(total)); |
| 249 | + dic.put("useMemory", Long.toString(use)); |
249 | 250 | dic.put("zone", Config.zone()); |
250 | 251 | dic.put("name", Config.name()); |
251 | 252 | dic.put("agentVersion", Config.getProperty("version")); |
|
0 commit comments