mirror of
https://github.com/PowerJob/PowerJob.git
synced 2025-07-17 00:00:04 +08:00
[fix] fix the bug of incorrect memory usafe
This commit is contained in:
parent
50f07e0d47
commit
cc0e982be0
@ -28,10 +28,9 @@ public final class OmsWorkerVersion {
|
||||
* @see Package#getImplementationVersion()
|
||||
*/
|
||||
public static String getVersion() {
|
||||
if (StringUtils.isNotEmpty(CACHE)) {
|
||||
return CACHE;
|
||||
if (StringUtils.isEmpty(CACHE)) {
|
||||
CACHE = determineSpringBootVersion();
|
||||
}
|
||||
CACHE = determineSpringBootVersion();
|
||||
return CACHE;
|
||||
}
|
||||
|
||||
|
@ -47,11 +47,13 @@ public class SystemInfoUtils {
|
||||
|
||||
private static void fillMemoryInfo(SystemMetrics metrics) {
|
||||
// JVM内存信息(maxMemory指JVM能从操作系统获取的最大内存,即-Xmx参数设置的值,totalMemory指JVM当前持久的总内存)
|
||||
metrics.setJvmMaxMemory(bytes2GB(runtime.maxMemory()));
|
||||
long maxMemory = runtime.maxMemory();
|
||||
long usedMemory = runtime.totalMemory() - runtime.freeMemory();
|
||||
metrics.setJvmMaxMemory(bytes2GB(maxMemory));
|
||||
// 已使用内存:当前申请总量 - 当前空余量
|
||||
metrics.setJvmUsedMemory(bytes2GB(runtime.totalMemory() - runtime.freeMemory()));
|
||||
metrics.setJvmUsedMemory(bytes2GB(usedMemory));
|
||||
// 已用内存比例
|
||||
metrics.setJvmMemoryUsage(miniDouble(metrics.getJvmUsedMemory() / runtime.maxMemory()));
|
||||
metrics.setJvmMemoryUsage(miniDouble((double) usedMemory / maxMemory));
|
||||
}
|
||||
|
||||
private static void fillDiskInfo(SystemMetrics metrics) {
|
||||
|
@ -52,4 +52,10 @@ public class MonitorTest {
|
||||
System.out.println("heap used: " + memoryMXBean.getHeapMemoryUsage());
|
||||
System.out.println("noheap used: " + memoryMXBean.getNonHeapMemoryUsage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFetchMetrics() {
|
||||
SystemMetrics systemMetrics = SystemInfoUtils.getSystemMetrics();
|
||||
System.out.println(JsonUtils.toJSONString(systemMetrics));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user