Merge remote-tracking branch 'gitee/dev' into dev

This commit is contained in:
jiangzeyin 2019-03-27 13:49:20 +08:00
commit badec76246
4 changed files with 108 additions and 33 deletions

View File

@ -52,8 +52,9 @@ public class WelcomeController extends BaseController {
JSONArray array = null;
try {
if (AbstractCommander.OS_INFO.isLinux()) {
String head = AbstractCommander.getInstance().execSystemCommand("top -b -n 1 | head -7");
String s = AbstractCommander.getInstance().execSystemCommand("top -b -n 1 | grep java | head -10");
AbstractCommander instance = AbstractCommander.getInstance();
String head = instance.execSystemCommand("top -b -n 1 | head -7");
String s = instance.execSystemCommand("top -b -n 1 | grep java");
array = TopManager.formatLinuxTop(head + s);
} else {
String s = AbstractCommander.getInstance().execSystemCommand("tasklist /V | findstr java");

View File

@ -7,6 +7,7 @@ import cn.hutool.cron.CronUtil;
import cn.hutool.cron.Scheduler;
import cn.jiangzeyin.common.DefaultSystemLog;
import cn.jiangzeyin.common.spring.SpringUtil;
import cn.jiangzeyin.pool.ThreadPoolService;
import cn.keepbx.jpom.common.commander.AbstractCommander;
import cn.keepbx.jpom.service.manage.CommandService;
import cn.keepbx.jpom.socket.SocketSessionUtil;
@ -23,6 +24,7 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ExecutorService;
/**
* top命令管理保证整个服务器只获取一个top命令
@ -77,6 +79,7 @@ public class TopManager {
} else {
topInfo = getWindowsMonitor();
}
sendProcessList();
send(topInfo);
} catch (Exception e) {
DefaultSystemLog.ERROR().error(e.getMessage(), e);
@ -89,6 +92,32 @@ public class TopManager {
watch = true;
}
/**
* 发送首页进程列表信息
*/
private static void sendProcessList() {
ExecutorService executorService = ThreadPoolService.newCachedThreadPool(TopManager.class);
executorService.execute(() -> {
JSONArray array;
try {
if (AbstractCommander.OS_INFO.isLinux()) {
AbstractCommander instance = AbstractCommander.getInstance();
String head = instance.execSystemCommand("top -b -n 1 | head -7");
String s = instance.execSystemCommand("top -b -n 1 | grep java");
array = formatLinuxTop(head + s);
} else {
String s = AbstractCommander.getInstance().execSystemCommand("tasklist /V | findstr java");
array = formatWindowsProcess(s);
}
JSONObject jsonObject = new JSONObject();
jsonObject.put("processList", array);
send(jsonObject.toJSONString());
} catch (Exception e) {
DefaultSystemLog.ERROR().error(e.getMessage(), e);
}
});
}
/**
* 获取windows 监控
*
@ -118,6 +147,11 @@ public class TopManager {
return jsonObject.toJSONString();
}
/**
* 磁盘占用
*
* @return 磁盘占用
*/
private static JSONArray getHardDisk() {
File[] files = File.listRoots();
long freeSpace = 0;

View File

@ -78,8 +78,38 @@
<script>
function loadSuccess() {
var ws, myEcharts;
loadProcessList();
loadFirstEcharts();
var config = {
id: 'tab_monitor',
elem: '#tab_monitor',
// height: 'full-52',
even: true,
cols: [[
{field: 'pid', title: '进程id', sort: true, width: '8%'},
{field: 'USER', title: '所有者', width: '12%'},
{field: 'PR', title: '优先级', width: '8%', sort: true},
{field: 'NI', title: 'nice值', width: '8%', sort: true},
{field: 'VIRT', title: '使用虚拟内存', width: '8%', sort: true},
{field: 'RES', title: '使用物理内存', width: '8%', sort: true},
{field: 'SHR', title: '共享内存', width: '8%', sort: true},
{field: 'S', title: '进程状态', width: '8%', sort: true},
{field: 'CPU', title: '占用CPU', width: '8%', sort: true},
{field: 'MEM', title: '占用物理内存', width: '8%', sort: true},
{field: 'TIME', title: '时间总计', width: '8%', sort: true},
{field: 'COMMAND', title: '进程名称'}
]],
loading: true,
method: 'POST',
response: {
statusCode: 200
},
done: function (data) {
}
};
table.render(config);
function loadFirstEcharts() {
$.ajax({
url: './getTop',
@ -101,34 +131,27 @@
});
}
table.render({
id: 'tab_monitor',
elem: '#tab_monitor',
url: '/processList',
// height: 'full-52',
even: true,
cols: [[
{field: 'pid', title: '进程id', sort: true, width: '8%'},
{field: 'USER', title: '所有者', width: '12%'},
{field: 'PR', title: '优先级', width: '8%'},
{field: 'NI', title: 'nice值', width: '8%'},
{field: 'VIRT', title: '使用虚拟内存', width: '8%'},
{field: 'RES', title: '使用物理内存', width: '8%'},
{field: 'SHR', title: '共享内存', width: '8%'},
{field: 'S', title: '进程状态', width: '8%'},
{field: 'CPU', title: '占用CPU', width: '8%'},
{field: 'MEM', title: '占用物理内存', width: '8%'},
{field: 'TIME', title: '时间总计', width: '8%'},
{field: 'COMMAND', title: '进程名称'}
]],
loading: true,
method: 'POST',
response: {
statusCode: 200
},
done: function (data) {
}
});
function loadProcessList() {
$.ajax({
url: '/processList',
type: 'POST',
dataType: 'json',
async: true,
success: function (data) {
if (200 == data.code) {
if (data.data) {
config.data = data.data;
table.render(config);
}
} else {
layer.alert(data.msg);
}
},
error: function (err) {
layer.alert("监控信息异常!");
}
});
}
function linkSocket(status) {
if (!ws) {
@ -148,6 +171,11 @@
if (top.top) {
loadEcharts(top);
}
if (top.processList) {
var processList = top.processList;
config.data = processList;
table.render(config);
}
}
} catch (e) {
return;

View File

@ -20,12 +20,24 @@ public class DTest {
public static void main(String[] args) throws Exception {
File[] files = File.listRoots();
long freeSpace = 0;
long useAbleSpace = 0;
long totalSpace = 0;
for (File file : files) {
long free = file.getFreeSpace();
freeSpace += free;
long total = file.getTotalSpace();
totalSpace += total;
useAbleSpace += total - free;
System.out.println(file.getPath());
System.out.println(FileUtil.readableFileSize(file.getFreeSpace()));
System.out.println(FileUtil.readableFileSize(file.getTotalSpace()));
System.out.println("---------------------");
System.out.println(FileUtil.readableFileSize(free));
System.out.println(FileUtil.readableFileSize(total - free));
System.out.println(FileUtil.readableFileSize(total));
System.out.println("-------------------------");
}
System.out.println(FileUtil.readableFileSize(freeSpace));
System.out.println(FileUtil.readableFileSize(useAbleSpace));
System.out.println(FileUtil.readableFileSize(totalSpace));
}
private static void printTrack() {