输出结果
https://vue.ruoyi.vip/monitor/server
实现代码
依赖
<!-- 获取系统信息 -->
<dependency>
<groupId>com.github.oshi</groupId>
<artifactId>oshi-core</artifactId>
<version>6.5.0</version>
</dependency>
代码
package com.study.controller;
import com.study.monitor.Server;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 服务器监控
*/
@RestController
@RequestMapping("/server")
public class ServerController {
@GetMapping("/info")
public Server getInfo() throws Exception {
Server server = new Server();
server.copyTo();
return server;
}
}
复制到本地,可以直接运行。