提交 | 用户 | 时间
|
1ac2bc
|
1 |
package cn.stylefeng.guns.base.oshi.model; |
懒 |
2 |
|
|
3 |
import cn.hutool.core.date.DateUnit; |
|
4 |
import cn.hutool.core.date.DateUtil; |
|
5 |
import cn.hutool.core.util.NumberUtil; |
|
6 |
import lombok.Setter; |
|
7 |
|
|
8 |
import java.lang.management.ManagementFactory; |
|
9 |
import java.util.Date; |
|
10 |
|
|
11 |
/** |
|
12 |
* JVM相关信息 |
|
13 |
* |
|
14 |
* @author fengshuonan |
|
15 |
* @Date 2019-07-13 13:42 |
|
16 |
*/ |
|
17 |
@Setter |
|
18 |
public class JvmInfo { |
|
19 |
/** |
|
20 |
* 当前JVM占用的内存总数(M) |
|
21 |
*/ |
|
22 |
private double total; |
|
23 |
|
|
24 |
/** |
|
25 |
* JVM最大可用内存总数(M) |
|
26 |
*/ |
|
27 |
private double max; |
|
28 |
|
|
29 |
/** |
|
30 |
* JVM空闲内存(M) |
|
31 |
*/ |
|
32 |
private double free; |
|
33 |
|
|
34 |
/** |
|
35 |
* JDK版本 |
|
36 |
*/ |
|
37 |
private String version; |
|
38 |
|
|
39 |
/** |
|
40 |
* JDK路径 |
|
41 |
*/ |
|
42 |
private String home; |
|
43 |
|
|
44 |
public double getTotal() { |
|
45 |
return NumberUtil.div(total, (1024 * 1024), 2); |
|
46 |
} |
|
47 |
|
|
48 |
public double getMax() { |
|
49 |
return NumberUtil.div(max, (1024 * 1024), 2); |
|
50 |
} |
|
51 |
|
|
52 |
public double getFree() { |
|
53 |
return NumberUtil.div(free, (1024 * 1024), 2); |
|
54 |
} |
|
55 |
|
|
56 |
public double getUsed() { |
|
57 |
return NumberUtil.div(total - free, (1024 * 1024), 2); |
|
58 |
} |
|
59 |
|
|
60 |
public String getVersion() { |
|
61 |
return version; |
|
62 |
} |
|
63 |
|
|
64 |
public String getHome() { |
|
65 |
return home; |
|
66 |
} |
|
67 |
|
|
68 |
public double getUsage() { |
|
69 |
return NumberUtil.mul(NumberUtil.div(total - free, total, 4), 100); |
|
70 |
} |
|
71 |
|
|
72 |
/** |
|
73 |
* 获取JDK名称 |
|
74 |
*/ |
|
75 |
public String getName() { |
|
76 |
return ManagementFactory.getRuntimeMXBean().getVmName(); |
|
77 |
} |
|
78 |
|
|
79 |
/** |
|
80 |
* JDK启动时间 |
|
81 |
*/ |
|
82 |
public String getStartTime() { |
|
83 |
long time = ManagementFactory.getRuntimeMXBean().getStartTime(); |
|
84 |
Date date = new Date(time); |
|
85 |
return DateUtil.formatDateTime(date); |
|
86 |
} |
|
87 |
|
|
88 |
/** |
|
89 |
* JDK运行时间 |
|
90 |
*/ |
|
91 |
public String getRunTime() { |
|
92 |
|
|
93 |
long time = ManagementFactory.getRuntimeMXBean().getStartTime(); |
|
94 |
Date date = new Date(time); |
|
95 |
|
|
96 |
//运行多少分钟 |
|
97 |
long runMS = DateUtil.between(date, new Date(), DateUnit.MS); |
|
98 |
|
|
99 |
long nd = 1000 * 24 * 60 * 60; |
|
100 |
long nh = 1000 * 60 * 60; |
|
101 |
long nm = 1000 * 60; |
|
102 |
|
|
103 |
long day = runMS / nd; |
|
104 |
long hour = runMS % nd / nh; |
|
105 |
long min = runMS % nd % nh / nm; |
|
106 |
|
|
107 |
return day + "天" + hour + "小时" + min + "分钟"; |
|
108 |
} |
|
109 |
} |