提交 60687353 编写于 作者: doc_wei's avatar doc_wei

服务器动态信息查看

上级 be646d44
......@@ -40,9 +40,16 @@
<netjson.version>2.4</netjson.version>
<jackjson.version>1.9.13</jackjson.version>
<fastjson.version>1.2.3</fastjson.version>
<javaee.version>7.0</javaee.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>${javaee.version}</version>
<scope>provided</scope>
</dependency>
<!--json-lib -->
<dependency>
<groupId>net.sf.json-lib</groupId>
......
......@@ -100,5 +100,12 @@ public class Constants {
public static final String REDIS_PROJECT_PAGE_FILE_PATH_NUM = "1000";//页面路径的序列号默认值
public static final String REDIS_PROJECT_PAGE_FILE_NAME_NUM = "1000";//页面名称的序列号默认值
/**
* 可以设置长些,防止读到运行此次系统检查时的cpu占用率,就不准了
*/
public static final int CPUTIME = 5000;
public static final int PERCENT = 100;
public static final int FAULTLENGTH = 10;
}
package com.skyeye.common.util;
/**
* byte操作类.
* @author Administrator
*
*/
public class Bytes {
/**
* 由于String.subString对汉字处理存在问题(把一个汉字视为一个字节),因此在 包含汉字的字符串时存在隐患,现调整如下:
* @param src 要截取的字符串
* @param start_idx 开始坐标(包括该坐标)
* @param end_idx 截止坐标(包括该坐标)
* @return
*/
public static String substring(String src, int start_idx, int end_idx) {
byte[] b = src.getBytes();
String tgt = "";
for (int i = start_idx; i <= end_idx; i++) {
tgt += (char) b[i];
}
return tgt;
}
}
......@@ -2,6 +2,8 @@ package com.skyeye.common.util;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.io.RandomAccessFile;
import java.security.MessageDigest;
import java.text.DateFormat;
......@@ -16,16 +18,13 @@ import java.util.Random;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.servlet.http.HttpServletRequest;
import com.skyeye.common.constans.Constants;
import com.skyeye.common.object.ObjectConstant;
import org.apache.commons.lang3.StringUtils;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PropertiesLoaderUtils;
import com.skyeye.common.constans.Constants;
import com.skyeye.common.object.ObjectConstant;
public class ToolUtil {
......@@ -627,6 +626,94 @@ public class ToolUtil {
}
return ip;
}
/**
* 获得CPU使用率.
* @return
*/
public static double getCpuRatioForWindows() {
try {
String procCmd = System.getenv("windir") + "//system32//wbem//wmic.exe process get Caption,CommandLine,"
+ "KernelModeTime,ReadOperationCount,ThreadCount,UserModeTime,WriteOperationCount";
// 取进程信息
long[] c0 = readCpu(Runtime.getRuntime().exec(procCmd));
// Thread.sleep(Constants.CPUTIME);
long[] c1 = readCpu(Runtime.getRuntime().exec(procCmd));
if (c0 != null && c1 != null) {
long idletime = c1[0] - c0[0];
long busytime = c1[1] - c0[1];
return Double.valueOf(Constants.PERCENT * (busytime) / (busytime + idletime)).doubleValue();
} else {
return 0.0;
}
} catch (Exception ex) {
ex.printStackTrace();
return 0.0;
}
}
/**
* 读取CPU信息
* @param proc
* @return
*/
public static long[] readCpu(final Process proc) {
long[] retn = new long[2];
try {
proc.getOutputStream().close();
InputStreamReader ir = new InputStreamReader(proc.getInputStream());
LineNumberReader input = new LineNumberReader(ir);
String line = input.readLine();
if (line == null || line.length() < Constants.FAULTLENGTH) {
return null;
}
int capidx = line.indexOf("Caption");
int cmdidx = line.indexOf("CommandLine");
int rocidx = line.indexOf("ReadOperationCount");
int umtidx = line.indexOf("UserModeTime");
int kmtidx = line.indexOf("KernelModeTime");
int wocidx = line.indexOf("WriteOperationCount");
long idletime = 0;
long kneltime = 0;
long usertime = 0;
while ((line = input.readLine()) != null) {
if (line.length() < wocidx) {
continue;
}
// 字段出现顺序:Caption,CommandLine,KernelModeTime,ReadOperationCount,
// ThreadCount,UserModeTime,WriteOperation
String caption = Bytes.substring(line, capidx, cmdidx - 1).trim();
String cmd = Bytes.substring(line, cmdidx, kmtidx - 1).trim();
if (cmd.indexOf("wmic.exe") >= 0) {
continue;
}
// log.info("line="+line);
if (caption.equals("System Idle Process") || caption.equals("System")) {
idletime += Long.valueOf(Bytes.substring(line, kmtidx, rocidx - 1).trim()).longValue();
idletime += Long.valueOf(Bytes.substring(line, umtidx, wocidx - 1).trim()).longValue();
continue;
}
if(!isBlank(Bytes.substring(line, kmtidx, rocidx - 1).trim())){
kneltime += Long.valueOf(Bytes.substring(line, kmtidx, rocidx - 1).trim()).longValue();
}
if(!isBlank(Bytes.substring(line, umtidx, wocidx - 1).trim())){
usertime += Long.valueOf(Bytes.substring(line, umtidx, wocidx - 1).trim()).longValue();
}
}
retn[0] = idletime;
retn[1] = kneltime + usertime;
return retn;
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
proc.getInputStream().close();
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
public static void main(String[] args) throws Exception {
......
package com.skyeye.authority.dao;
import java.util.List;
import java.util.Map;
public interface SysMonitorDao {
public int insertMonitorMation(Map<String, Object> bean) throws Exception;
public List<Map<String, Object>> queryMonitorInfoMationList(Map<String, Object> map) throws Exception;
public int deleteMonitorSaveFiveHandlber(Map<String, Object> bean) throws Exception;
}
package com.skyeye.authority.service;
import com.skyeye.common.object.InputObject;
import com.skyeye.common.object.OutputObject;
public interface SysMonitorService {
public void queryMonitorInfoMation(InputObject inputObject, OutputObject outputObject) throws Exception;
}
package com.skyeye.authority.service.impl;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.skyeye.authority.dao.SysMonitorDao;
import com.skyeye.authority.service.SysMonitorService;
import com.skyeye.common.object.InputObject;
import com.skyeye.common.object.OutputObject;
@Service
public class SysMonitorServiceImpl implements SysMonitorService {
@Autowired
private SysMonitorDao sysMonitorDao;
/**
*
* @Title: queryMonitorInfoMation
* @Description: 获取系统信息的业务逻辑实现类
* @param @param inputObject
* @param @param outputObject
* @param @throws Exception 参数
* @return void 返回类型
* @throws
*/
@Override
public void queryMonitorInfoMation(InputObject inputObject, OutputObject outputObject) throws Exception {
Map<String, Object> map = inputObject.getParams();
List<Map<String, Object>> beans = sysMonitorDao.queryMonitorInfoMationList(map);
if(!beans.isEmpty()){
outputObject.setBeans(beans);
outputObject.settotal(beans.size());
}
}
}
......@@ -24,6 +24,10 @@
<artifactId>fastdfs-client-java</artifactId>
<version>1.27-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
</dependency>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
......
package com.skyeye.authority.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.skyeye.authority.service.SysMonitorService;
import com.skyeye.common.object.InputObject;
import com.skyeye.common.object.OutputObject;
@Controller
public class SysMonitorController {
@Autowired
private SysMonitorService sysMonitorService;
/**
*
* @Title: queryMonitorInfoMation
* @Description: 获取系统信息的业务逻辑实现类
* @param @param inputObject
* @param @param outputObject
* @param @throws Exception 参数
* @return void 返回类型
* @throws
*/
@RequestMapping("/post/SysMonitorController/queryMonitorInfoMation")
@ResponseBody
public void queryMonitorInfoMation(InputObject inputObject, OutputObject outputObject) throws Exception{
sysMonitorService.queryMonitorInfoMation(inputObject, outputObject);
}
}
......@@ -32,6 +32,8 @@ public class InitServlet extends HttpServlet {
//启动线程读取配置文件
new Thread(new TokenThread(REQUEST_URL)).start();
log.info("启动线程读取配置文件成功");
new Thread(new MonitorThread()).start();
log.info("启动系统信息获取成功");
}
@Override
......
package com.skyeye.start.thread;
import java.lang.management.ManagementFactory;
import java.util.HashMap;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.WebApplicationContext;
import com.alibaba.fastjson.JSON;
import com.skyeye.authority.dao.SysMonitorDao;
import com.skyeye.common.constans.Constants;
import com.skyeye.common.util.ToolUtil;
import com.skyeye.jedis.JedisClient;
import com.sun.management.OperatingSystemMXBean;
/**
*
* @ClassName: MonitorThread
* @Description: 通过线程去获取系统的实时信息
* @author 卫志强
* @date 2018年6月8日
*
*/
@SuppressWarnings("restriction")
public class MonitorThread implements Runnable{
private int kb = 1024;
private int count = 1;
private static Logger log = LoggerFactory.getLogger(MonitorThread.class);
@Override
public void run() {
try {
log.info("启动");
while(true){
// 可使用内存
long totalMemory = Runtime.getRuntime().totalMemory() / kb / kb;
// 剩余内存
long freeMemory = Runtime.getRuntime().freeMemory() / kb / kb;
// 最大可使用内存
long maxMemory = Runtime.getRuntime().maxMemory() / kb / kb;
OperatingSystemMXBean osmxb = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
// 操作系统
String osName = System.getProperty("os.name");
// 总的物理内存
long totalMemorySize = osmxb.getTotalPhysicalMemorySize() / kb / kb;
// 剩余的物理内存
long freePhysicalMemorySize = osmxb.getFreePhysicalMemorySize() / kb / kb;
// 已使用的物理内存
long usedMemory = (osmxb.getTotalPhysicalMemorySize() - osmxb.getFreePhysicalMemorySize()) / kb / kb;
// 获得线程总数
ThreadGroup parentThread;
for (parentThread = Thread.currentThread().getThreadGroup(); parentThread.getParent() != null; parentThread = parentThread.getParent());
int totalThread = parentThread.activeCount();
//cpu使用率
double cpuRatio = 0;
if (osName.toLowerCase().startsWith("windows")) {
cpuRatio = ToolUtil.getCpuRatioForWindows();
}
Map<String, Object> bean = new HashMap<>();
bean.put("totalMemory", totalMemory);//可使用内存
bean.put("freeMemory", freeMemory);//剩余内存
bean.put("maxMemory", maxMemory);//最大可使用内存
bean.put("osName", osName);//操作系统
bean.put("totalMemorySize", totalMemorySize);//总的物理内存
bean.put("freePhysicalMemorySize", freePhysicalMemorySize);//剩余的物理内存
bean.put("usedMemory", usedMemory);//已使用的物理内存
bean.put("totalThread", totalThread);//线程总数
bean.put("cpuRatio", cpuRatio);//cpu使用率
bean.put("id", ToolUtil.getSurFaceId());
bean.put("createTime", ToolUtil.getTimeAndToString());
WebApplicationContext context = ContextLoader.getCurrentWebApplicationContext();
SysMonitorDao sysMonitorDao = (SysMonitorDao) context.getBean("sysMonitorDao");
JedisClient jedisClient = (JedisClient) context.getBean("jedisClientCluster");
sysMonitorDao.insertMonitorMation(bean);
jedisClient.set("server_mation", JSON.toJSONString(bean));
jedisClient.expire("server_mation:", 1800);//时间为30分钟
count++;
if(count >= 500){
count = 1;
sysMonitorDao.deleteMonitorSaveFiveHandlber(bean);
}
Thread.sleep(Constants.CPUTIME);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
package com.skyeye.websocket;
import java.io.IOException;
import java.util.concurrent.CopyOnWriteArraySet;
import javax.websocket.*;
import javax.websocket.server.ServerEndpoint;
import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.WebApplicationContext;
import com.skyeye.jedis.JedisClient;
/**
* @ServerEndpoint 注解是一个类层次的注解,它的功能主要是将目前的类定义成一个websocket服务器端,
* 注解的值将被用于监听用户连接的终端访问URL地址,客户端可以通过这个URL来连接到WebSocket服务器端
*/
@ServerEndpoint("/websocket")
public class WebSocketContext {
// 静态变量,用来记录当前在线连接数。应该把它设计成线程安全的。
private static int onlineCount = 0;
// concurrent包的线程安全Set,用来存放每个客户端对应的MyWebSocket对象。若要实现服务端与单一客户端通信的话,可以使用Map来存放,其中Key可以为用户标识
private static CopyOnWriteArraySet<WebSocketContext> webSocketSet = new CopyOnWriteArraySet<WebSocketContext>();
// 与某个客户端的连接会话,需要通过它来给客户端发送数据
private Session session;
/**
* 连接建立成功调用的方法
*
* @param session 可选的参数。session为与某个客户端的连接会话,需要通过它来给客户端发送数据
*/
@OnOpen
public void onOpen(Session session) {
this.session = session;
webSocketSet.add(this); // 加入set中
addOnlineCount(); // 在线数加1
System.out.println("有新连接加入!当前在线人数为" + getOnlineCount());
}
/**
* 连接关闭调用的方法
*/
@OnClose
public void onClose() {
webSocketSet.remove(this); // 从set中删除
subOnlineCount(); // 在线数减1
System.out.println("有一连接关闭!当前在线人数为" + getOnlineCount());
}
/**
* 收到客户端消息后调用的方法
*
* @param message
* 客户端发送过来的消息
* @param session
* 可选的参数
*/
@OnMessage
public void onMessage(String message, Session session) {
// 群发消息
for (WebSocketContext item : webSocketSet) {
try {
WebApplicationContext context = ContextLoader.getCurrentWebApplicationContext();
JedisClient jedisClient = (JedisClient) context.getBean("jedisClientCluster");
if(jedisClient.get("server_mation") != null){
item.sendMessage(jedisClient.get("server_mation"));
}
} catch (IOException e) {
e.printStackTrace();
continue;
}
}
}
/**
* 发生错误时调用
*
* @param session
* @param error
*/
@OnError
public void onError(Session session, Throwable error) {
System.out.println("发生错误");
error.printStackTrace();
}
/**
* 这个方法与上面几个方法不一样。没有用注解,是根据自己需要添加的方法。
*
* @param message
* @throws IOException
*/
public void sendMessage(String message) throws IOException {
this.session.getBasicRemote().sendText(message);
}
public static synchronized int getOnlineCount() {
return onlineCount;
}
public static synchronized void addOnlineCount() {
WebSocketContext.onlineCount++;
}
public static synchronized void subOnlineCount() {
WebSocketContext.onlineCount--;
}
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.skyeye.authority.dao.SysMonitorDao">
<insert id="insertMonitorMation" parameterType="java.util.Map">
INSERT into sys_eve_monitor
(id, total_memory, free_memory, max_memory, os_name, total_memory_size, free_physical_memory_size, used_memory, total_thread, cpu_ratio, create_time)
VALUES
(#{id}, #{totalMemory}, #{freeMemory}, #{maxMemory}, #{osName}, #{totalMemorySize}, #{freePhysicalMemorySize}, #{usedMemory}, #{totalThread}, #{cpuRatio}, #{createTime})
</insert>
<select id="queryMonitorInfoMationList" parameterType="java.util.Map" resultType="java.util.Map">
SELECT
a.total_memory totalMemory,
a.free_memory freeMemory,
a.max_memory maxMemory,
a.os_name osName,
a.total_memory_size totalMemorySize,
a.free_physical_memory_size freePhysicalMemorySize,
a.used_memory usedMemory,
a.total_thread totalThread,
a.cpu_ratio cpuRatio,
CONVERT(a.create_time, char) createTime
FROM
sys_eve_monitor a
ORDER BY a.create_time DESC
LIMIT 50
</select>
<delete id="deleteMonitorSaveFiveHandlber" parameterType="java.util.Map">
DELETE a
FROM
sys_eve_monitor a
LEFT JOIN (
SELECT
b.id
FROM
sys_eve_monitor b
ORDER BY
b.create_time DESC
LIMIT 500
) t1 ON a.id = t1.id
WHERE
t1.id IS NULL
</delete>
</mapper>
\ No newline at end of file
......@@ -711,4 +711,11 @@
</url>
<!-- 系统各部分说明结束 -->
<!-- 系统性能监控开始 -->
<url id="websocket001" path="/websocket" val="WebSocketContext获取服务器信息" allUse="1">
</url>
<url id="sysmonitor001" path="/post/SysMonitorController/queryMonitorInfoMation" val="获取系统信息的业务逻辑实现类" allUse="1">
</url>
<!-- 系统性能监控结束 -->
</controller>
\ No newline at end of file
......@@ -27,6 +27,7 @@
<!-- 配置包扫描器,以便注册带有@Controller、@Service、@repository、@Component等注解的类成为spring的bean -->
<context:component-scan base-package="com.skyeye.*.controller" />
<context:component-scan base-package="com.skyeye.common.filter" />
<context:component-scan base-package="com.skyeye.websocket" />
<!-- 配置资源映射 -->
<mvc:resources location="file:///${IMAGES_PATH}" mapping="/images/**" />
......
......@@ -4027,6 +4027,20 @@ body .layer-ext-winconfirm {
/*** 个人中心样式end ***/
.layui-this li{
height: 100px;
text-align: center;
background-color: ghostwhite;
margin-left: 20px;
margin-top: 15px;
margin-bottom: 15px;
}
.layui-this li a h3{
font-size: 21px;
margin-top: 20px;
}
/*******************************************自定义样式end********************************************/
layui.config({
base: basePath,
version: skyeyeVersion
}).extend({
echarts: '../echarts/echarts',
echartsTheme: '../echarts/echartsTheme',
}).define(['jquery', 'winui', 'echarts'], function (exports) {
winui.renderColor();
var $ = layui.$;
var ws = null;
var option;
var totalMemoryChart = null, freeMemoryChart = null, freePhysicalMemorySizeChart = null, usedMemoryChart = null, totalThreadChart = null, cpuRatioChart = null,
xdata = [];
totalMemoryYdata = [], freeMemoryYdata = [], freePhysicalMemorySizeYdata = [], usedMemoryYdata = [], totalThreadYdata = [], cpuRatioYdata = [];
initMation();
//服务器信息变化
function initMation(){
option = {
title: {
text: '可使用内存'
},
tooltip: {
trigger: 'axis',
formatter: function (params) {
params = params[0];
return params.name + ' : ' + params.value[1];
},
axisPointer: {
animation: false
}
},
xAxis: {
type: 'category',
data: xdata
},
yAxis: {
type: 'value',
splitLine: {
show: false
}
},
series: [{
name: '模拟数据',
type: 'line',
showSymbol: false,
hoverAnimation: false,
data: totalMemoryYdata
}]
};
AjaxPostUtil.request({url:reqBasePath + "sysmonitor001", params:{}, type:'json', callback:function(json){
if(json.returnCode == 0){
totalMemoryChart = echarts.init($("#totalMemoryLine")[0], layui.echartsTheme);
freeMemoryChart = echarts.init($("#freeMemoryYLine")[0], layui.echartsTheme);
freePhysicalMemorySizeChart = echarts.init($("#freePhysicalMemorySizeLine")[0], layui.echartsTheme);
usedMemoryChart = echarts.init($("#usedMemoryLine")[0], layui.echartsTheme);
totalThreadChart = echarts.init($("#totalThreadLine")[0], layui.echartsTheme);
cpuRatioChart = echarts.init($("#cpuRatioLine")[0], layui.echartsTheme);
if (option && typeof option === "object") {
totalMemoryChart.setOption(option);
freeMemoryChart.setOption(option);
freePhysicalMemorySizeChart.setOption(option);
usedMemoryChart.setOption(option);
totalThreadChart.setOption(option);
cpuRatioChart.setOption(option);
}
$("#osName").html(json.rows[0].osName);
$("#totalMemorySize").html(json.rows[0].totalMemorySize);
$("#maxMemory").html(json.rows[0].maxMemory);
for(var i in json.rows){
xdata.push(json.rows[i].createTime);
totalMemoryYdata.push({
name: json.rows[i].createTime,
value: [json.rows[i].createTime, json.rows[i].totalMemory],
});
freeMemoryYdata.push({
name: json.rows[i].createTime,
value: [json.rows[i].createTime, json.rows[i].freeMemory],
});
freePhysicalMemorySizeYdata.push({
name: json.rows[i].createTime,
value: [json.rows[i].createTime, json.rows[i].freePhysicalMemorySize],
});
usedMemoryYdata.push({
name: json.rows[i].createTime,
value: [json.rows[i].createTime, json.rows[i].usedMemory],
});
totalThreadYdata.push({
name: json.rows[i].createTime,
value: [json.rows[i].createTime, json.rows[i].totalThread],
});
cpuRatioYdata.push({
name: json.rows[i].createTime,
value: [json.rows[i].createTime, json.rows[i].cpuRatio],
});
}
totalMemoryChart.setOption({
xAxis: {data: xdata},
title: {
text: '当前JVM占用的内存总数(M)'
},
series: [{
data: totalMemoryYdata
}]
});
freeMemoryChart.setOption({
xAxis: {data: xdata},
title: {
text: 'JVM空闲内存(M)'
},
series: [{
data: freeMemoryYdata
}]
});
freePhysicalMemorySizeChart.setOption({
xAxis: {data: xdata},
title: {
text: '剩余的物理内存'
},
series: [{
data: freePhysicalMemorySizeYdata
}]
});
usedMemoryChart.setOption({
xAxis: {data: xdata},
title: {
text: '已使用的物理内存'
},
series: [{
data: usedMemoryYdata
}]
});
totalThreadChart.setOption({
xAxis: {data: xdata},
title: {
text: '线程总数'
},
series: [{
data: totalThreadYdata
}]
});
cpuRatioChart.setOption({
xAxis: {data: xdata},
title: {
text: 'cpu使用率'
},
series: [{
data: cpuRatioYdata
}]
});
if ('WebSocket' in window) {
ws = new WebSocket("ws://localhost:8081/websocket001" + "?userToken=" + getCookie('userToken') + "&loginPCIp=" + returnCitySN["cip"]);
//连接成功建立的回调方法
ws.onopen = function(){
// Web Socket 已连接上,使用 send() 方法发送数据
};
//接收到消息的回调方法
ws.onmessage = function (evt) {
var received_msg = evt.data;
try {
if (typeof JSON.parse(received_msg) == "object") {
var jsonData = JSON.parse(received_msg);
xdata.push(jsonData.createTime);
totalMemoryYdata.push({
name: jsonData.createTime,
value: [jsonData.createTime, jsonData.totalMemory],
});
freeMemoryYdata.push({
name: jsonData.createTime,
value: [jsonData.createTime, jsonData.freeMemory],
});
freePhysicalMemorySizeYdata.push({
name: jsonData.createTime,
value: [jsonData.createTime, jsonData.freePhysicalMemorySize],
});
usedMemoryYdata.push({
name: jsonData.createTime,
value: [jsonData.createTime, jsonData.usedMemory],
});
totalThreadYdata.push({
name: jsonData.createTime,
value: [jsonData.createTime, jsonData.totalThread],
});
cpuRatioYdata.push({
name: jsonData.createTime,
value: [jsonData.createTime, jsonData.cpuRatio],
});
totalMemoryChart.setOption({
xAxis: {data: xdata},
series: [{
data: totalMemoryYdata
}]
});
freeMemoryChart.setOption({
xAxis: {data: xdata},
series: [{
data: freeMemoryYdata
}]
});
freePhysicalMemorySizeChart.setOption({
xAxis: {data: xdata},
series: [{
data: freePhysicalMemorySizeYdata
}]
});
usedMemoryChart.setOption({
xAxis: {data: xdata},
series: [{
data: usedMemoryYdata
}]
});
totalThreadChart.setOption({
xAxis: {data: xdata},
series: [{
data: totalThreadYdata
}]
});
cpuRatioYdata.setOption({
xAxis: {data: xdata},
series: [{
data: cpuRatioYdata
}]
});
}
} catch(e) {
}
};
//连接关闭的回调方法
ws.onclose = function () {
};
//连接发生错误的回调方法
ws.onerror = function () {
};
setInterval(function(){
ws.send("你好");
}, 5000);
} else {
alert('当前浏览器 Not support websocket')
}
}else{
top.winui.window.msg(json.returnMessage, {icon: 2,time: 2000});
}
}});
//页面刷新或者关闭时,关闭socket
window.onbeforeunload = function(){
if (ws != null) {
ws.close();
}
}
}
exports('sysmonitorlist', {});
});
......@@ -28,3 +28,6 @@ toLowerCaseFirstOne(); 字符串首字母转小写
writeTxtFile(); 写入内容到文件
getDateStr(); 将日期转化为正常的年月日时分秒
getIpByRequest(); 根据request获取ip
getCpuRatioForWindows(); 获得CPU使用率
readCpu(); 读取CPU信息
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<link href="../../assets/lib/layui/css/layui.css" rel="stylesheet" />
<link href="../../assets/lib/font-awesome-4.7.0/css/font-awesome.css" rel="stylesheet" />
<link href="../../assets/lib/winui/css/winui.css" rel="stylesheet" />
</head>
<body>
<div style="margin:auto 10px;">
<div class="layui-col-xs12">
<ul class="layui-row layui-col-space10 layui-this">
<li class="layui-col-xs2"><a class="layadmin-backlog-body">
<h3>系统</h3>
<p>
<cite id="osName"></cite>
</p>
</a></li>
<li class="layui-col-xs2"><a class="layadmin-backlog-body">
<h3>总共物理内存(M)</h3>
<p>
<cite id="totalMemorySize"></cite>
</p>
</a></li>
<li class="layui-col-xs2"><a class="layadmin-backlog-body">
<h3>最大可使用内存(M)</h3>
<p>
<cite id="maxMemory"></cite>
</p>
</a></li>
</ul>
</div>
<div class="layui-col-xs12">
<div class="layui-col-xs6">
<div id="totalMemoryLine" style="width:90%;height:500px;"></div>
</div>
<div class="layui-col-xs6">
<div id="freeMemoryYLine" style="width:90%;height:500px;"></div>
</div>
</div>
<div class="layui-col-xs12">
<div class="layui-col-xs6">
<div id="freePhysicalMemorySizeLine" style="width:90%;height:500px;"></div>
</div>
<div class="layui-col-xs6">
<div id="usedMemoryLine" style="width:90%;height:500px;"></div>
</div>
</div>
<div class="layui-col-xs12">
<div class="layui-col-xs6">
<div id="totalThreadLine" style="width:90%;height:500px;"></div>
</div>
<div class="layui-col-xs6">
<div id="cpuRatioLine" style="width:90%;height:500px;"></div>
</div>
</div>
</div>
<script src="../../assets/lib/layui/layui.js"></script>
<script src="../../assets/lib/layui/custom.js"></script>
<script type="text/javascript">
layui.config({base: '../../js/sysmonitor/'}).use('sysmonitorlist');
</script>
</body>
</html>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册