parent
aa814a87ff
commit
cae29f21a8
@ -0,0 +1,51 @@
|
||||
package com.xjs.servicemonitor.controller;
|
||||
|
||||
import com.ruoyi.common.core.web.domain.AjaxResult;
|
||||
import com.xjs.servicemonitor.domain.ServiceMonitorInfo;
|
||||
import com.xjs.servicemonitor.service.JvmMonitorService;
|
||||
import com.xjs.servicemonitor.service.SystemOSService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @author xiejs
|
||||
* @desc 业务监控控制器
|
||||
* @create 2022-01-02
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("servicemonitor")
|
||||
public class ServiceMonitorController {
|
||||
@Autowired
|
||||
private JvmMonitorService jvmMonitorService;
|
||||
|
||||
@Autowired
|
||||
private SystemOSService systemOSService;
|
||||
|
||||
@GetMapping
|
||||
public AjaxResult getServiceMonitor() {
|
||||
ServiceMonitorInfo serviceMonitorInfo = new ServiceMonitorInfo();
|
||||
serviceMonitorInfo.setFreeMemory(systemOSService.getRuntimeInfo().getFreeMemory());
|
||||
serviceMonitorInfo.setCurrentDir(systemOSService.getUserInfo().getCurrentDir());
|
||||
serviceMonitorInfo.setHomeDir(systemOSService.getUserInfo().getHomeDir());
|
||||
serviceMonitorInfo.setHostAddress(systemOSService.getHostInfo().getAddress());
|
||||
serviceMonitorInfo.setHostName(systemOSService.getHostInfo().getName());
|
||||
serviceMonitorInfo.setJreName(jvmMonitorService.getJavaRuntimeInfo().getName());
|
||||
serviceMonitorInfo.setJreHoneDir(jvmMonitorService.getJavaRuntimeInfo().getHomeDir());
|
||||
serviceMonitorInfo.setMaxMemory(systemOSService.getRuntimeInfo().getMaxMemory());
|
||||
serviceMonitorInfo.setJreVersion(jvmMonitorService.getJavaRuntimeInfo().getVersion());
|
||||
serviceMonitorInfo.setJvmVersion(jvmMonitorService.getJvmInfo().getVersion());
|
||||
serviceMonitorInfo.setUserName(systemOSService.getUserInfo().getName());
|
||||
serviceMonitorInfo.setOsArch(systemOSService.getOsInfo().getArch());
|
||||
serviceMonitorInfo.setOsVersion(systemOSService.getOsInfo().getVersion());
|
||||
serviceMonitorInfo.setTotalMemory(systemOSService.getRuntimeInfo().getTotalMemory());
|
||||
serviceMonitorInfo.setUsableMemory(systemOSService.getRuntimeInfo().getUsableMemory());
|
||||
serviceMonitorInfo.setUserLanguage(systemOSService.getUserInfo().getLanguage());
|
||||
serviceMonitorInfo.setUserCountry(systemOSService.getUserInfo().getCountry());
|
||||
serviceMonitorInfo.setOsName(systemOSService.getOsInfo().getName());
|
||||
return AjaxResult.success(serviceMonitorInfo);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,104 @@
|
||||
package com.xjs.servicemonitor.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author xiejs
|
||||
* @desc 业务监控实体类
|
||||
* @create 2022-01-02
|
||||
*/
|
||||
@Data
|
||||
public class ServiceMonitorInfo {
|
||||
|
||||
|
||||
/**
|
||||
* jvm版本
|
||||
*/
|
||||
private String jvmVersion;
|
||||
|
||||
|
||||
/**
|
||||
* jre安装路径
|
||||
*/
|
||||
private String jreHoneDir;
|
||||
|
||||
/**
|
||||
* jre版本
|
||||
*/
|
||||
private String jreVersion;
|
||||
|
||||
/**
|
||||
* jre名称
|
||||
*/
|
||||
private String jreName;
|
||||
|
||||
|
||||
/**
|
||||
* 系统名称
|
||||
*/
|
||||
private String osName;
|
||||
|
||||
/**
|
||||
* 系统版本
|
||||
*/
|
||||
private String osVersion;
|
||||
|
||||
/**
|
||||
* 当前系统架构
|
||||
*/
|
||||
private String osArch;
|
||||
|
||||
/**
|
||||
* 主机名
|
||||
*/
|
||||
private String hostName;
|
||||
/**
|
||||
* 主机地址
|
||||
*/
|
||||
private String hostAddress;
|
||||
|
||||
/**
|
||||
* 当前系统登录名
|
||||
*/
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 当前用户路径
|
||||
*/
|
||||
private String homeDir;
|
||||
|
||||
/**
|
||||
* current 当前目录
|
||||
*/
|
||||
private String currentDir;
|
||||
|
||||
/**
|
||||
* 当前用户登录语言
|
||||
*/
|
||||
private String userLanguage;
|
||||
|
||||
/**
|
||||
* 当前用户登录区域
|
||||
*/
|
||||
private String userCountry;
|
||||
|
||||
|
||||
/**
|
||||
* 最大jvm内存
|
||||
*/
|
||||
private Long maxMemory;
|
||||
/**
|
||||
* 已分配内存
|
||||
*/
|
||||
private Long totalMemory;
|
||||
/**
|
||||
已分配内存中的剩余空间
|
||||
*/
|
||||
private Long freeMemory;
|
||||
|
||||
/**
|
||||
最大可用内存
|
||||
*/
|
||||
private Long usableMemory;
|
||||
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package com.xjs.servicemonitor.service;
|
||||
|
||||
import cn.hutool.system.JavaRuntimeInfo;
|
||||
import cn.hutool.system.JvmInfo;
|
||||
import cn.hutool.system.JvmSpecInfo;
|
||||
|
||||
/**
|
||||
* @author xiejs
|
||||
* @desc 获取jvm信息
|
||||
* @create 2022-01-02
|
||||
*/
|
||||
public interface JvmMonitorService {
|
||||
|
||||
/**
|
||||
* 获取jvm规格信息
|
||||
* @return JvmSpecInfo
|
||||
*/
|
||||
JvmSpecInfo getJvmSpecInfo();
|
||||
|
||||
/**
|
||||
* 获取jvm基本信息
|
||||
* @return JvmInfo
|
||||
*/
|
||||
JvmInfo getJvmInfo();
|
||||
|
||||
/**
|
||||
* 获取java运行时信息
|
||||
* @return JavaRuntimeInfo
|
||||
*/
|
||||
JavaRuntimeInfo getJavaRuntimeInfo();
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package com.xjs.servicemonitor.service;
|
||||
|
||||
import cn.hutool.system.HostInfo;
|
||||
import cn.hutool.system.OsInfo;
|
||||
import cn.hutool.system.RuntimeInfo;
|
||||
import cn.hutool.system.UserInfo;
|
||||
|
||||
/**
|
||||
* @author xiejs
|
||||
* @desc 电脑系统信息
|
||||
* @create 2022-01-02
|
||||
*/
|
||||
public interface SystemOSService {
|
||||
|
||||
/**
|
||||
* 获取os信息
|
||||
* @return OsInfo
|
||||
*/
|
||||
OsInfo getOsInfo();
|
||||
|
||||
/**
|
||||
* 获取系统的用户信息
|
||||
* @return UserInfo
|
||||
*/
|
||||
UserInfo getUserInfo();
|
||||
|
||||
/**
|
||||
* 获取网络地址信息
|
||||
* @return HostInfo
|
||||
*/
|
||||
HostInfo getHostInfo();
|
||||
|
||||
/**
|
||||
* 获取电脑运行时参数信息
|
||||
* @return RuntimeInfo
|
||||
*/
|
||||
RuntimeInfo getRuntimeInfo();
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package com.xjs.servicemonitor.service.impl;
|
||||
|
||||
import cn.hutool.system.JavaRuntimeInfo;
|
||||
import cn.hutool.system.JvmInfo;
|
||||
import cn.hutool.system.JvmSpecInfo;
|
||||
import cn.hutool.system.SystemUtil;
|
||||
import com.xjs.servicemonitor.service.JvmMonitorService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author xiejs
|
||||
* @desc
|
||||
* @create 2022-01-02
|
||||
*/
|
||||
@Service
|
||||
public class JvmMonitorServiceImpl implements JvmMonitorService {
|
||||
|
||||
|
||||
@Override
|
||||
public JvmSpecInfo getJvmSpecInfo() {
|
||||
return SystemUtil.getJvmSpecInfo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JvmInfo getJvmInfo() {
|
||||
return SystemUtil.getJvmInfo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JavaRuntimeInfo getJavaRuntimeInfo() {
|
||||
return SystemUtil.getJavaRuntimeInfo();
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package com.xjs.servicemonitor.service.impl;
|
||||
|
||||
import cn.hutool.system.*;
|
||||
import com.xjs.servicemonitor.service.SystemOSService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author xiejs
|
||||
* @desc
|
||||
* @create 2022-01-02
|
||||
*/
|
||||
@Service
|
||||
public class SystemOSServiceImpl implements SystemOSService {
|
||||
@Override
|
||||
public OsInfo getOsInfo() {
|
||||
return SystemUtil.getOsInfo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserInfo getUserInfo() {
|
||||
return SystemUtil.getUserInfo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public HostInfo getHostInfo() {
|
||||
return SystemUtil.getHostInfo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RuntimeInfo getRuntimeInfo() {
|
||||
return SystemUtil.getRuntimeInfo();
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package com.xjs.servicemonitor.service;
|
||||
|
||||
import cn.hutool.system.JavaRuntimeInfo;
|
||||
import cn.hutool.system.JvmInfo;
|
||||
import cn.hutool.system.JvmSpecInfo;
|
||||
import com.xjs.XjsMonitorApp;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* @author xiejs
|
||||
* @desc
|
||||
* @create 2022-01-02
|
||||
*/
|
||||
@SpringBootTest(classes = XjsMonitorApp.class)
|
||||
class JvmMonitorServiceTest {
|
||||
|
||||
@Autowired
|
||||
JvmMonitorService jvmMonitorService;
|
||||
|
||||
|
||||
@Test
|
||||
void getJvmSpecInfo() {
|
||||
JvmSpecInfo jvmSpecInfo = jvmMonitorService.getJvmSpecInfo();
|
||||
System.out.println(jvmSpecInfo);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void getJvmInfo() {
|
||||
JvmInfo jvmInfo = jvmMonitorService.getJvmInfo();
|
||||
System.out.println(jvmInfo);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getJavaRuntimeInfo() {
|
||||
JavaRuntimeInfo javaRuntimeInfo = jvmMonitorService.getJavaRuntimeInfo();
|
||||
System.out.println(javaRuntimeInfo);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue