From 606f079a93da4532944749684fe4734dd0304c19 Mon Sep 17 00:00:00 2001 From: JEECG <445654970@qq.com> Date: Wed, 10 Jul 2024 16:00:11 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3jdk17=20=E5=86=85=E5=AD=98?= =?UTF-8?q?=E4=BF=A1=E6=81=AF-=E7=AB=8B=E5=8D=B3=E6=9B=B4=E6=96=B0=20?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E6=8A=A5=E9=94=99=20#6635-?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ActuatorMemoryController.java | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/monitor/controller/ActuatorMemoryController.java b/jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/monitor/controller/ActuatorMemoryController.java index c6c3bc14..69559fe9 100644 --- a/jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/monitor/controller/ActuatorMemoryController.java +++ b/jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/monitor/controller/ActuatorMemoryController.java @@ -26,27 +26,31 @@ public class ActuatorMemoryController { /** * 内存详情 * @return - * @throws Exception */ @GetMapping("/info") - public Result getRedisInfo() throws Exception { - OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean(); - JSONObject operatingSystemJson = JSONObject.parseObject(JSONObject.toJSONString(operatingSystemMXBean)); - long totalPhysicalMemory = operatingSystemJson.getLongValue("totalPhysicalMemorySize"); - long freePhysicalMemory = operatingSystemJson.getLongValue("freePhysicalMemorySize"); - long usedPhysicalMemory = totalPhysicalMemory - freePhysicalMemory; + public Result getRedisInfo() { Runtime runtime = Runtime.getRuntime(); Map result = new HashMap<>(); - result.put("memory.physical.total", totalPhysicalMemory); - result.put("memory.physical.used", freePhysicalMemory); - result.put("memory.physical.free", usedPhysicalMemory); - result.put("memory.physical.usage", NumberUtil.div(usedPhysicalMemory, totalPhysicalMemory)); result.put("memory.runtime.total", runtime.totalMemory()); result.put("memory.runtime.used", runtime.freeMemory()); result.put("memory.runtime.max", runtime.totalMemory() - runtime.freeMemory()); result.put("memory.runtime.free", runtime.maxMemory() - runtime.totalMemory() + runtime.freeMemory()); result.put("memory.runtime.usage", NumberUtil.div(runtime.totalMemory() - runtime.freeMemory(), runtime.totalMemory())); - return Result.ok(result); + //update-begin---author:chenrui ---date:20240705 for:[TV360X-1695]内存信息-立即更新 功能报错 #6635------------ + OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean(); + if (operatingSystemMXBean instanceof com.sun.management.OperatingSystemMXBean) { + com.sun.management.OperatingSystemMXBean opBean = (com.sun.management.OperatingSystemMXBean) operatingSystemMXBean; +// JSONObject operatingSystemJson = JSONObject.parseObject(JSONObject.toJSONString(operatingSystemMXBean)); + long totalPhysicalMemory = opBean.getTotalPhysicalMemorySize(); + long freePhysicalMemory = opBean.getFreePhysicalMemorySize(); + long usedPhysicalMemory = totalPhysicalMemory - freePhysicalMemory; + result.put("memory.physical.total", totalPhysicalMemory); + result.put("memory.physical.used", freePhysicalMemory); + result.put("memory.physical.free", usedPhysicalMemory); + result.put("memory.physical.usage", NumberUtil.div(usedPhysicalMemory, totalPhysicalMemory)); + } + //update-end---author:chenrui ---date:20240705 for:[TV360X-1695]内存信息-立即更新 功能报错 #6635------------ + return Result.ok(result); } }