From 6068735304ad364c632a0c194bfdfaf45cad455b Mon Sep 17 00:00:00 2001
From: weizhiqiang <598748873@qq.com>
Date: Wed, 21 Nov 2018 17:24:11 +0800
Subject: [PATCH] =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=99=A8=E5=8A=A8=E6=80=81?=
=?UTF-8?q?=E4=BF=A1=E6=81=AF=E6=9F=A5=E7=9C=8B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 7 +
.../com/skyeye/common/constans/Constants.java | 7 +
.../java/com/skyeye/common/util/Bytes.java | 25 ++
.../java/com/skyeye/common/util/ToolUtil.java | 101 ++++++-
.../skyeye/authority/dao/SysMonitorDao.java | 14 +
.../authority/service/SysMonitorService.java | 10 +
.../service/impl/SysMonitorServiceImpl.java | 40 +++
skyeye-web/pom.xml | 4 +
.../controller/SysMonitorController.java | 33 +++
.../com/skyeye/start/thread/InitServlet.java | 2 +
.../skyeye/start/thread/MonitorThread.java | 94 ++++++
.../skyeye/websocket/WebSocketContext.java | 109 +++++++
.../resources/dbmapper/SysMonitorMapper.xml | 47 +++
.../src/main/resources/mapping/reqmapping.xml | 7 +
.../src/main/resources/spring/springmvc.xml | 1 +
.../webapp/assets/lib/winui/css/winui.css | 14 +
.../webapp/js/sysmonitor/sysmonitorlist.js | 271 ++++++++++++++++++
skyeye-web/src/main/webapp/toolUtil.txt | 3 +
.../webapp/tpl/sysmonitor/sysmonitorlist.html | 65 +++++
19 files changed, 847 insertions(+), 7 deletions(-)
create mode 100644 skyeye-common/src/main/java/com/skyeye/common/util/Bytes.java
create mode 100644 skyeye-dao/src/main/java/com/skyeye/authority/dao/SysMonitorDao.java
create mode 100644 skyeye-service/src/main/java/com/skyeye/authority/service/SysMonitorService.java
create mode 100644 skyeye-service/src/main/java/com/skyeye/authority/service/impl/SysMonitorServiceImpl.java
create mode 100644 skyeye-web/src/main/java/com/skyeye/authority/controller/SysMonitorController.java
create mode 100644 skyeye-web/src/main/java/com/skyeye/start/thread/MonitorThread.java
create mode 100644 skyeye-web/src/main/java/com/skyeye/websocket/WebSocketContext.java
create mode 100644 skyeye-web/src/main/resources/dbmapper/SysMonitorMapper.xml
create mode 100644 skyeye-web/src/main/webapp/js/sysmonitor/sysmonitorlist.js
create mode 100644 skyeye-web/src/main/webapp/tpl/sysmonitor/sysmonitorlist.html
diff --git a/pom.xml b/pom.xml
index b0bff0031..9f1b7a496 100644
--- a/pom.xml
+++ b/pom.xml
@@ -40,9 +40,16 @@
2.4
1.9.13
1.2.3
+ 7.0
+
+ javax
+ javaee-api
+ ${javaee.version}
+ provided
+
net.sf.json-lib
diff --git a/skyeye-common/src/main/java/com/skyeye/common/constans/Constants.java b/skyeye-common/src/main/java/com/skyeye/common/constans/Constants.java
index 3e6c9f54d..fe8f4f3f4 100644
--- a/skyeye-common/src/main/java/com/skyeye/common/constans/Constants.java
+++ b/skyeye-common/src/main/java/com/skyeye/common/constans/Constants.java
@@ -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;
+
}
diff --git a/skyeye-common/src/main/java/com/skyeye/common/util/Bytes.java b/skyeye-common/src/main/java/com/skyeye/common/util/Bytes.java
new file mode 100644
index 000000000..817118f95
--- /dev/null
+++ b/skyeye-common/src/main/java/com/skyeye/common/util/Bytes.java
@@ -0,0 +1,25 @@
+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;
+ }
+}
diff --git a/skyeye-common/src/main/java/com/skyeye/common/util/ToolUtil.java b/skyeye-common/src/main/java/com/skyeye/common/util/ToolUtil.java
index 5da6d6a62..a70ac3197 100644
--- a/skyeye-common/src/main/java/com/skyeye/common/util/ToolUtil.java
+++ b/skyeye-common/src/main/java/com/skyeye/common/util/ToolUtil.java
@@ -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 {
diff --git a/skyeye-dao/src/main/java/com/skyeye/authority/dao/SysMonitorDao.java b/skyeye-dao/src/main/java/com/skyeye/authority/dao/SysMonitorDao.java
new file mode 100644
index 000000000..a37c86c06
--- /dev/null
+++ b/skyeye-dao/src/main/java/com/skyeye/authority/dao/SysMonitorDao.java
@@ -0,0 +1,14 @@
+package com.skyeye.authority.dao;
+
+import java.util.List;
+import java.util.Map;
+
+public interface SysMonitorDao {
+
+ public int insertMonitorMation(Map bean) throws Exception;
+
+ public List
+
+ javax
+ javaee-api
+
org.springframework
diff --git a/skyeye-web/src/main/java/com/skyeye/authority/controller/SysMonitorController.java b/skyeye-web/src/main/java/com/skyeye/authority/controller/SysMonitorController.java
new file mode 100644
index 000000000..44ffc29be
--- /dev/null
+++ b/skyeye-web/src/main/java/com/skyeye/authority/controller/SysMonitorController.java
@@ -0,0 +1,33 @@
+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);
+ }
+
+}
diff --git a/skyeye-web/src/main/java/com/skyeye/start/thread/InitServlet.java b/skyeye-web/src/main/java/com/skyeye/start/thread/InitServlet.java
index 9452bc8d2..743859eb3 100644
--- a/skyeye-web/src/main/java/com/skyeye/start/thread/InitServlet.java
+++ b/skyeye-web/src/main/java/com/skyeye/start/thread/InitServlet.java
@@ -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
diff --git a/skyeye-web/src/main/java/com/skyeye/start/thread/MonitorThread.java b/skyeye-web/src/main/java/com/skyeye/start/thread/MonitorThread.java
new file mode 100644
index 000000000..70f2121fd
--- /dev/null
+++ b/skyeye-web/src/main/java/com/skyeye/start/thread/MonitorThread.java
@@ -0,0 +1,94 @@
+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 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();
+ }
+ }
+
+}
diff --git a/skyeye-web/src/main/java/com/skyeye/websocket/WebSocketContext.java b/skyeye-web/src/main/java/com/skyeye/websocket/WebSocketContext.java
new file mode 100644
index 000000000..f61cd85b7
--- /dev/null
+++ b/skyeye-web/src/main/java/com/skyeye/websocket/WebSocketContext.java
@@ -0,0 +1,109 @@
+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 webSocketSet = new CopyOnWriteArraySet();
+
+ // 与某个客户端的连接会话,需要通过它来给客户端发送数据
+ 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--;
+ }
+}
diff --git a/skyeye-web/src/main/resources/dbmapper/SysMonitorMapper.xml b/skyeye-web/src/main/resources/dbmapper/SysMonitorMapper.xml
new file mode 100644
index 000000000..da798dd6b
--- /dev/null
+++ b/skyeye-web/src/main/resources/dbmapper/SysMonitorMapper.xml
@@ -0,0 +1,47 @@
+
+
+
+
+
+ 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})
+
+
+
+
+
+ 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
+
+
+
\ No newline at end of file
diff --git a/skyeye-web/src/main/resources/mapping/reqmapping.xml b/skyeye-web/src/main/resources/mapping/reqmapping.xml
index 96daf53a6..c0c7d8983 100644
--- a/skyeye-web/src/main/resources/mapping/reqmapping.xml
+++ b/skyeye-web/src/main/resources/mapping/reqmapping.xml
@@ -711,4 +711,11 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/skyeye-web/src/main/resources/spring/springmvc.xml b/skyeye-web/src/main/resources/spring/springmvc.xml
index 9bd582271..a1cb635b9 100644
--- a/skyeye-web/src/main/resources/spring/springmvc.xml
+++ b/skyeye-web/src/main/resources/spring/springmvc.xml
@@ -27,6 +27,7 @@
+
diff --git a/skyeye-web/src/main/webapp/assets/lib/winui/css/winui.css b/skyeye-web/src/main/webapp/assets/lib/winui/css/winui.css
index b9f72c3bb..801d5d4d5 100644
--- a/skyeye-web/src/main/webapp/assets/lib/winui/css/winui.css
+++ b/skyeye-web/src/main/webapp/assets/lib/winui/css/winui.css
@@ -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********************************************/
diff --git a/skyeye-web/src/main/webapp/js/sysmonitor/sysmonitorlist.js b/skyeye-web/src/main/webapp/js/sysmonitor/sysmonitorlist.js
new file mode 100644
index 000000000..579051cad
--- /dev/null
+++ b/skyeye-web/src/main/webapp/js/sysmonitor/sysmonitorlist.js
@@ -0,0 +1,271 @@
+
+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', {});
+});
diff --git a/skyeye-web/src/main/webapp/toolUtil.txt b/skyeye-web/src/main/webapp/toolUtil.txt
index 026e1951d..e14ca4780 100644
--- a/skyeye-web/src/main/webapp/toolUtil.txt
+++ b/skyeye-web/src/main/webapp/toolUtil.txt
@@ -28,3 +28,6 @@ toLowerCaseFirstOne(); 字符串首字母转小写
writeTxtFile(); 写入内容到文件
getDateStr(); 将日期转化为正常的年月日时分秒
getIpByRequest(); 根据request获取ip
+getCpuRatioForWindows(); 获得CPU使用率
+readCpu(); 读取CPU信息
+
diff --git a/skyeye-web/src/main/webapp/tpl/sysmonitor/sysmonitorlist.html b/skyeye-web/src/main/webapp/tpl/sysmonitor/sysmonitorlist.html
new file mode 100644
index 000000000..330f149eb
--- /dev/null
+++ b/skyeye-web/src/main/webapp/tpl/sysmonitor/sysmonitorlist.html
@@ -0,0 +1,65 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
--
GitLab