com.gccloud.starter.common.module.monitor.vo.JvmVo Maven / Gradle / Ivy
package com.gccloud.starter.common.module.monitor.vo;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.NumberUtil;
import lombok.Data;
import java.io.Serializable;
import java.lang.management.ManagementFactory;
import java.util.Date;
/**
* JVM 信息
* @author liuchengbiao
* @date 2021/9/23 11:23 上午
*/
@Data
public class JvmVo implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 当前JVM占用的内存总数(M)
*/
private double total;
/**
* JVM最大可用内存总数(M)
*/
private double max;
/**
* JVM空闲内存(M)
*/
private double free;
/**
* JDK版本
*/
private String version;
/**
* JDK路径
*/
private String home;
public double getTotal() {
return NumberUtil.div(total, (1024 * 1024), 2);
}
public double getMax() {
return NumberUtil.div(max, (1024 * 1024), 2);
}
public double getFree() {
return NumberUtil.div(free, (1024 * 1024), 2);
}
public double getUsed() {
return NumberUtil.div(total - free, (1024 * 1024), 2);
}
public double getUsage() {
return NumberUtil.mul(NumberUtil.div(total - free, total, 4), 100);
}
/**
* 获取JDK名称
*/
public String getName() {
return ManagementFactory.getRuntimeMXBean().getVmName();
}
/**
* JDK启动时间
*/
public String getStartTime() {
long time = ManagementFactory.getRuntimeMXBean().getStartTime();
Date date = new Date(time);
return DateUtil.formatDateTime(date);
}
/**
* JDK运行时间
*/
public String getRunTime() {
long time = ManagementFactory.getRuntimeMXBean().getStartTime();
Date date = new Date(time);
//运行多少分钟
long runMS = DateUtil.between(date, new Date(), DateUnit.MS);
long nd = 1000 * 24 * 60 * 60;
long nh = 1000 * 60 * 60;
long nm = 1000 * 60;
long day = runMS / nd;
long hour = runMS % nd / nh;
long min = runMS % nd % nh / nm;
return day + "天" + hour + "小时" + min + "分钟";
}
}