mirror of
https://gitee.com/dromara/Jpom.git
synced 2024-12-02 20:08:40 +08:00
获取pid
This commit is contained in:
parent
2f17e1a7fb
commit
a144f8259a
@ -2,9 +2,8 @@ package cn.jiangzeyin.controller.manage;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.system.RuntimeInfo;
|
||||
import cn.jiangzeyin.common.JsonMessage;
|
||||
import cn.jiangzeyin.controller.BaseController;
|
||||
import cn.jiangzeyin.service.manage.ManageService;
|
||||
import cn.jiangzeyin.service.manage.CommandService;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@ -20,10 +19,13 @@ import javax.annotation.Resource;
|
||||
public class InternalController extends BaseController {
|
||||
|
||||
@Resource
|
||||
private ManageService manageService;
|
||||
private CommandService commandService;
|
||||
|
||||
@RequestMapping(value = "internal", method = RequestMethod.GET)
|
||||
public String getInternal(String id) {
|
||||
public String getInternal(String tag) {
|
||||
JSONObject internal = commandService.getInternal(tag);
|
||||
|
||||
|
||||
RuntimeInfo runtimeInfo = new RuntimeInfo();
|
||||
JSONObject object = new JSONObject();
|
||||
object.put("total", FileUtil.readableFileSize(runtimeInfo.getMaxMemory()));
|
||||
|
@ -10,6 +10,7 @@ import cn.jiangzeyin.model.ProjectInfoModel;
|
||||
import cn.jiangzeyin.socket.LogWebSocketHandle;
|
||||
import cn.jiangzeyin.socket.SocketSession;
|
||||
import cn.jiangzeyin.socket.TailLogThread;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@ -29,6 +30,7 @@ public class CommandService {
|
||||
@Resource
|
||||
private ManageService manageService;
|
||||
|
||||
|
||||
public enum CommandOp {
|
||||
/**
|
||||
* 启动
|
||||
@ -145,4 +147,62 @@ public class CommandService {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取内存信息
|
||||
*
|
||||
* @param tag tag
|
||||
* @return 内存信息
|
||||
*/
|
||||
public JSONObject getInternal(String tag) {
|
||||
String pid = getPid(tag);
|
||||
String topRam = getTopRam(pid);
|
||||
System.out.println(pid);
|
||||
System.out.println(topRam);
|
||||
return null;
|
||||
}
|
||||
|
||||
private String getTopRam(String pid) {
|
||||
String command = "top -p " + pid;
|
||||
return exe(command);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取进程pid
|
||||
*
|
||||
* @param tag tag
|
||||
* @return pid
|
||||
*/
|
||||
private String getPid(String tag) {
|
||||
CommandService commandService = SpringUtil.getBean(CommandService.class);
|
||||
String commandPath = commandService.getCommandPath();
|
||||
String command = String.format("%s %s %s", commandPath, "pid", tag);
|
||||
return exe(command);
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行命令
|
||||
*
|
||||
* @param command 命令
|
||||
* @return 命令
|
||||
*/
|
||||
private String exe(String command) {
|
||||
String read = "";
|
||||
try {
|
||||
InputStream is;
|
||||
Process process = Runtime.getRuntime().exec(command);
|
||||
int wait = process.waitFor();
|
||||
if (wait == 0) {
|
||||
is = process.getInputStream();
|
||||
} else {
|
||||
is = process.getErrorStream();
|
||||
}
|
||||
read = IoUtil.read(is, CharsetUtil.CHARSET_UTF_8);
|
||||
is.close();
|
||||
process.destroy();
|
||||
} catch (Exception e) {
|
||||
DefaultSystemLog.ERROR().error("执行命令异常", e);
|
||||
}
|
||||
return read;
|
||||
}
|
||||
}
|
||||
|
@ -164,7 +164,7 @@
|
||||
title: '内存',
|
||||
shade: 0.8,
|
||||
area: ['60%', '50%'],
|
||||
content: 'internal?id=' + data.id
|
||||
content: 'internal?tag=' + data.tag
|
||||
});
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user