commit | author | age
|
9bcb19
|
1 |
/* |
I |
2 |
Copyright [2020] [https://www.xiaonuo.vip] |
|
3 |
|
|
4 |
Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 |
you may not use this file except in compliance with the License. |
|
6 |
You may obtain a copy of the License at |
|
7 |
|
|
8 |
http://www.apache.org/licenses/LICENSE-2.0 |
|
9 |
|
|
10 |
Unless required by applicable law or agreed to in writing, software |
|
11 |
distributed under the License is distributed on an "AS IS" BASIS, |
|
12 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 |
See the License for the specific language governing permissions and |
|
14 |
limitations under the License. |
|
15 |
|
|
16 |
Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: |
|
17 |
|
|
18 |
1.请不要删除和修改根目录下的LICENSE文件。 |
|
19 |
2.请不要删除和修改Snowy源码头部的版权声明。 |
|
20 |
3.请保留源码和相关描述文件的项目出处,作者声明等。 |
|
21 |
4.分发源码时候,请注明软件出处 https://gitee.com/xiaonuobase/snowy |
|
22 |
5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/xiaonuobase/snowy |
|
23 |
6.若您的项目无法满足以上几点,可申请商业授权,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip |
|
24 |
*/ |
|
25 |
package vip.xiaonuo.sys.modular.monitor.service.impl; |
|
26 |
|
|
27 |
import cn.hutool.core.io.FileUtil; |
|
28 |
import cn.hutool.core.util.NumberUtil; |
|
29 |
import cn.hutool.system.*; |
|
30 |
import org.springframework.stereotype.Service; |
|
31 |
import vip.xiaonuo.core.consts.SymbolConstant; |
|
32 |
import vip.xiaonuo.sys.modular.monitor.result.SysMachineResult; |
|
33 |
import vip.xiaonuo.sys.modular.monitor.service.SysMachineService; |
|
34 |
|
|
35 |
import java.math.BigDecimal; |
|
36 |
import java.text.DecimalFormat; |
|
37 |
|
|
38 |
/** |
|
39 |
* 系统属性监控service接口实现类 |
|
40 |
* |
|
41 |
* @author xuyuxiang |
|
42 |
* @date 2020/6/5 14:40 |
|
43 |
*/ |
|
44 |
@Service |
|
45 |
public class SysMachineServiceImpl implements SysMachineService { |
|
46 |
|
|
47 |
@Override |
|
48 |
public SysMachineResult query() { |
|
49 |
JvmInfo jvmInfo = SystemUtil.getJvmInfo(); |
|
50 |
JavaRuntimeInfo javaRuntimeInfo = SystemUtil.getJavaRuntimeInfo(); |
|
51 |
OsInfo osInfo = SystemUtil.getOsInfo(); |
|
52 |
HostInfo hostInfo = SystemUtil.getHostInfo(); |
|
53 |
RuntimeInfo runtimeInfo = SystemUtil.getRuntimeInfo(); |
|
54 |
//系统属性结果集 |
|
55 |
SysMachineResult sysMachineResult = new SysMachineResult(); |
|
56 |
|
|
57 |
//系统信息 |
|
58 |
SysMachineResult.SysOsInfo sysOsInfo = new SysMachineResult.SysOsInfo(); |
|
59 |
sysOsInfo.setOsName(osInfo.getName()); |
|
60 |
sysOsInfo.setOsArch(osInfo.getArch()); |
|
61 |
sysOsInfo.setOsVersion(osInfo.getVersion()); |
|
62 |
sysOsInfo.setOsHostName(hostInfo.getName()); |
|
63 |
sysOsInfo.setOsHostAddress(hostInfo.getAddress()); |
|
64 |
sysMachineResult.setSysOsInfo(sysOsInfo); |
|
65 |
|
|
66 |
//Java信息 |
|
67 |
SysMachineResult.SysJavaInfo sysJavaInfo = new SysMachineResult.SysJavaInfo(); |
|
68 |
sysJavaInfo.setJvmName(jvmInfo.getName()); |
|
69 |
sysJavaInfo.setJvmVersion(jvmInfo.getVersion()); |
|
70 |
sysJavaInfo.setJvmVendor(jvmInfo.getVendor()); |
|
71 |
sysJavaInfo.setJavaName(javaRuntimeInfo.getName()); |
|
72 |
sysJavaInfo.setJavaVersion(javaRuntimeInfo.getVersion()); |
|
73 |
sysMachineResult.setSysJavaInfo(sysJavaInfo); |
|
74 |
|
|
75 |
//jvm内存信息 |
|
76 |
SysMachineResult.SysJvmMemInfo sysJvmMemInfo = new SysMachineResult.SysJvmMemInfo(); |
|
77 |
sysJvmMemInfo.setJvmMaxMemory(FileUtil.readableFileSize(runtimeInfo.getMaxMemory())); |
|
78 |
sysJvmMemInfo.setJvmUsableMemory(FileUtil.readableFileSize(runtimeInfo.getUsableMemory())); |
|
79 |
sysJvmMemInfo.setJvmTotalMemory(FileUtil.readableFileSize(runtimeInfo.getTotalMemory())); |
|
80 |
sysJvmMemInfo.setJvmFreeMemory(FileUtil.readableFileSize(runtimeInfo.getFreeMemory())); |
|
81 |
BigDecimal usedMemory = NumberUtil.sub(new BigDecimal(runtimeInfo.getTotalMemory()), new BigDecimal(runtimeInfo.getFreeMemory())); |
|
82 |
sysJvmMemInfo.setJvmUsedMemory(FileUtil.readableFileSize(usedMemory.longValue())); |
|
83 |
BigDecimal rate = NumberUtil.div(usedMemory, runtimeInfo.getTotalMemory()); |
|
84 |
String usedRate = new DecimalFormat("#.00").format(NumberUtil.mul(rate, 100)) + SymbolConstant.PERCENT; |
|
85 |
sysJvmMemInfo.setJvmMemoryUsedRate(usedRate); |
|
86 |
sysMachineResult.setSysJvmMemInfo(sysJvmMemInfo); |
|
87 |
return sysMachineResult; |
|
88 |
} |
|
89 |
} |