diff --git a/like-framework/like-common/src/main/java/com/hxkj/common/core/ServerResult.java b/like-framework/like-common/src/main/java/com/hxkj/common/core/ServerResult.java index 031402dc..250fb496 100644 --- a/like-framework/like-common/src/main/java/com/hxkj/common/core/ServerResult.java +++ b/like-framework/like-common/src/main/java/com/hxkj/common/core/ServerResult.java @@ -3,6 +3,7 @@ package com.hxkj.common.core; import com.hxkj.common.entity.server.*; import com.hxkj.common.utils.ArithUtil; import com.hxkj.common.utils.IpUtil; +import com.hxkj.common.utils.TimeUtil; import oshi.SystemInfo; import oshi.hardware.CentralProcessor; import oshi.hardware.CentralProcessor.TickType; @@ -13,6 +14,8 @@ import oshi.software.os.OSFileStore; import oshi.software.os.OperatingSystem; import oshi.util.Util; +import java.lang.management.ManagementFactory; +import java.text.SimpleDateFormat; import java.util.*; @@ -81,13 +84,13 @@ public class ServerResult { mem.setTotal(ArithUtil.div(memory.getTotal(), number, 2)); mem.setUsed(ArithUtil.div(memory.getTotal() - memory.getAvailable(), number, 2)); mem.setFree(ArithUtil.div(memory.getAvailable(), number, 2)); + mem.setUsage(ArithUtil.mul(ArithUtil.div(mem.getUsed(), memory.getTotal(), 4), 100)); } /** * 设置服务器信息 */ - private void setSysInfo() - { + private void setSysInfo() { Properties props = System.getProperties(); sys.setComputerName(IpUtil.getHostName()); sys.setComputerIp(IpUtil.getHostIp()); @@ -104,8 +107,13 @@ public class ServerResult { jvm.setTotal(Runtime.getRuntime().totalMemory()); jvm.setMax(Runtime.getRuntime().maxMemory()); jvm.setFree(Runtime.getRuntime().freeMemory()); + jvm.setUsage(ArithUtil.mul(ArithUtil.div(jvm.getTotal() - jvm.getFree(), jvm.getTotal(), 4), 100)); jvm.setVersion(props.getProperty("java.version")); jvm.setHome(props.getProperty("java.home")); + jvm.setName(ManagementFactory.getRuntimeMXBean().getVmName()); + jvm.setInputArgs(ManagementFactory.getRuntimeMXBean().getInputArguments().toString()); + jvm.setRunTime(TimeUtil.datePoor(TimeUtil.nowDate(), TimeUtil.serverStartDate())); + jvm.setStartTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(TimeUtil.serverStartDate())); } /** diff --git a/like-framework/like-common/src/main/java/com/hxkj/common/entity/server/Jvm.java b/like-framework/like-common/src/main/java/com/hxkj/common/entity/server/Jvm.java index 3ec0b4fb..82c9a1f4 100644 --- a/like-framework/like-common/src/main/java/com/hxkj/common/entity/server/Jvm.java +++ b/like-framework/like-common/src/main/java/com/hxkj/common/entity/server/Jvm.java @@ -27,6 +27,11 @@ public class Jvm implements Serializable { */ private double free; + /** + * JVM内存使用率 + */ + private double usage; + /** * JDK版本 */ @@ -37,4 +42,23 @@ public class Jvm implements Serializable { */ private String home; + /** + * JDK名称 + */ + private String name; + + /** + * 运行参数 + */ + private String inputArgs; + + /** + * JDK运行时间 + */ + private String runTime; + + /** + * JDK启动时间 + */ + private String startTime; } diff --git a/like-framework/like-common/src/main/java/com/hxkj/common/entity/server/Mem.java b/like-framework/like-common/src/main/java/com/hxkj/common/entity/server/Mem.java index 9cf93afc..dd93a12c 100644 --- a/like-framework/like-common/src/main/java/com/hxkj/common/entity/server/Mem.java +++ b/like-framework/like-common/src/main/java/com/hxkj/common/entity/server/Mem.java @@ -27,4 +27,9 @@ public class Mem implements Serializable { */ private double free; + /** + * 使用率 + */ + private double usage; + } diff --git a/like-framework/like-common/src/main/java/com/hxkj/common/utils/TimeUtil.java b/like-framework/like-common/src/main/java/com/hxkj/common/utils/TimeUtil.java index 1e0a9062..b554b1e3 100644 --- a/like-framework/like-common/src/main/java/com/hxkj/common/utils/TimeUtil.java +++ b/like-framework/like-common/src/main/java/com/hxkj/common/utils/TimeUtil.java @@ -3,6 +3,7 @@ package com.hxkj.common.utils; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import java.lang.management.ManagementFactory; import java.sql.Time; import java.text.DateFormat; import java.text.ParsePosition; @@ -192,6 +193,16 @@ public class TimeUtil { return System.currentTimeMillis() / 1000; } + /** + * 返回当前Date型日期 + * + * @author fzr + * @return Date() 当前日期 + */ + public static Date nowDate() { + return new Date(); + } + /** * 返回今日开始和结束的时间戳 * @@ -494,4 +505,37 @@ public class TimeUtil { return data; } + /** + * 返回服务器启动时间 + */ + public static Date serverStartDate() { + long time = ManagementFactory.getRuntimeMXBean().getStartTime(); + return new Date(time); + } + + /** + * 计算两个时间差 + * + * @author fzr + * @param endDate 结束时间 + * @param nowDate 开始时间 + * @return String + */ + public static String datePoor(Date endDate, Date nowDate) { + long nd = 1000 * 24 * 60 * 60; + long nh = 1000 * 60 * 60; + long nm = 1000 * 60; + // long ns = 1000; + // 获得两个时间的毫秒时间差异 + long diff = endDate.getTime() - nowDate.getTime(); + // 计算差多少天 + long day = diff / nd; + // 计算差多少小时 + long hour = diff % nd / nh; + // 计算差多少分钟 + long min = diff % nd % nh / nm; + // 计算差多少秒//输出结果 + // long sec = diff % nd % nh % nm / ns; + return day + "天" + hour + "小时" + min + "分钟"; + } }