From ea85a620d157bc882e38479c38a30243b6059f40 Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: Fri, 4 Feb 2022 21:46:48 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9C=8D=E5=8A=A1=E5=99=A8?=
=?UTF-8?q?=E4=BF=A1=E6=81=AF=E8=8E=B7=E5=8F=96=E8=83=BD=E5=8A=9B=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 8 +-
.../iot/vmp/common/SystemInfoDto.java | 22 +++++
.../iot/vmp/common/VideoManagerConstants.java | 8 +-
.../iot/vmp/conf/SystemInfoTimerTask.java | 34 +++++++
.../iot/vmp/storager/IRedisCatchStorage.java | 6 ++
.../storager/impl/RedisCatchStorageImpl.java | 46 ++++++++++
.../iot/vmp/utils/SystemInfoUtils.java | 92 +++++++++++++++++++
.../iot/vmp/utils/redis/RedisUtil.java | 18 ++++
8 files changed, 232 insertions(+), 2 deletions(-)
create mode 100644 src/main/java/com/genersoft/iot/vmp/common/SystemInfoDto.java
create mode 100644 src/main/java/com/genersoft/iot/vmp/conf/SystemInfoTimerTask.java
create mode 100644 src/main/java/com/genersoft/iot/vmp/utils/SystemInfoUtils.java
diff --git a/pom.xml b/pom.xml
index 987e76e9..abf4e9cc 100644
--- a/pom.xml
+++ b/pom.xml
@@ -155,7 +155,6 @@
1.7.35
-
org.dom4j
@@ -212,6 +211,13 @@
3.0.4
+
+
+ com.github.oshi
+ oshi-core
+ 6.1.0
+
+
org.springframework.session
spring-session-core
diff --git a/src/main/java/com/genersoft/iot/vmp/common/SystemInfoDto.java b/src/main/java/com/genersoft/iot/vmp/common/SystemInfoDto.java
new file mode 100644
index 00000000..81a93acf
--- /dev/null
+++ b/src/main/java/com/genersoft/iot/vmp/common/SystemInfoDto.java
@@ -0,0 +1,22 @@
+package com.genersoft.iot.vmp.common;
+
+public class SystemInfoDto {
+ private String time;
+ private T data;
+
+ public String getTime() {
+ return time;
+ }
+
+ public void setTime(String time) {
+ this.time = time;
+ }
+
+ public T getData() {
+ return data;
+ }
+
+ public void setData(T data) {
+ this.data = data;
+ }
+}
diff --git a/src/main/java/com/genersoft/iot/vmp/common/VideoManagerConstants.java b/src/main/java/com/genersoft/iot/vmp/common/VideoManagerConstants.java
index ffbed508..923e411e 100644
--- a/src/main/java/com/genersoft/iot/vmp/common/VideoManagerConstants.java
+++ b/src/main/java/com/genersoft/iot/vmp/common/VideoManagerConstants.java
@@ -60,7 +60,13 @@ public class VideoManagerConstants {
public static final String SIP_SN_PREFIX = "VMP_SIP_SN_";
- public static final String SIP_SUBSCRIBE_PREFIX = "SIP_SUBSCRIBE_";
+ public static final String SIP_SUBSCRIBE_PREFIX = "VMP_SIP_SUBSCRIBE_";
+
+ public static final String SYSTEM_INFO_CPU_PREFIX = "VMP_SYSTEM_INFO_CPU_";
+
+ public static final String SYSTEM_INFO_MEM_PREFIX = "VMP_SYSTEM_INFO_MEM_";
+
+ public static final String SYSTEM_INFO_NET_PREFIX = "VMP_SYSTEM_INFO_NET_";
//************************** redis 消息*********************************
public static final String WVP_MSG_STREAM_CHANGE_PREFIX = "WVP_MSG_STREAM_CHANGE_";
diff --git a/src/main/java/com/genersoft/iot/vmp/conf/SystemInfoTimerTask.java b/src/main/java/com/genersoft/iot/vmp/conf/SystemInfoTimerTask.java
new file mode 100644
index 00000000..13ec6927
--- /dev/null
+++ b/src/main/java/com/genersoft/iot/vmp/conf/SystemInfoTimerTask.java
@@ -0,0 +1,34 @@
+package com.genersoft.iot.vmp.conf;
+
+import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
+import com.genersoft.iot.vmp.utils.SystemInfoUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import java.util.Map;
+
+/**
+ * 获取系统信息写入redis
+ */
+@Component
+public class SystemInfoTimerTask {
+
+ @Autowired
+ private IRedisCatchStorage redisCatchStorage;
+
+ @Scheduled(fixedRate = 1000) //每1秒执行一次
+ public void execute(){
+ try {
+ double cpuInfo = SystemInfoUtils.getCpuInfo();
+ redisCatchStorage.addCpuInfo(cpuInfo);
+ double memInfo = SystemInfoUtils.getMemInfo();
+ redisCatchStorage.addMemInfo(memInfo);
+ Map networkInterfaces = SystemInfoUtils.getNetworkInterfaces();
+ redisCatchStorage.addNetInfo(networkInterfaces);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+
+ }
+}
diff --git a/src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java b/src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java
index bf2104c7..edd6cbc0 100644
--- a/src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java
+++ b/src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java
@@ -214,4 +214,10 @@ public interface IRedisCatchStorage {
List getAllSubscribe();
List getAllSubscribePlatform();
+
+ void addCpuInfo(double cpuInfo);
+
+ void addMemInfo(double memInfo);
+
+ void addNetInfo(Map networkInterfaces);
}
diff --git a/src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java b/src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java
index 56789d92..92fdf6c5 100644
--- a/src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java
+++ b/src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java
@@ -2,6 +2,7 @@ package com.genersoft.iot.vmp.storager.impl;
import com.alibaba.fastjson.JSONObject;
import com.genersoft.iot.vmp.common.StreamInfo;
+import com.genersoft.iot.vmp.common.SystemInfoDto;
import com.genersoft.iot.vmp.common.VideoManagerConstants;
import com.genersoft.iot.vmp.conf.UserSetup;
import com.genersoft.iot.vmp.gb28181.bean.*;
@@ -534,4 +535,49 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
}
return result;
}
+
+ @Override
+ public void addCpuInfo(double cpuInfo) {
+ String key = VideoManagerConstants.SYSTEM_INFO_CPU_PREFIX + userSetup.getServerId();
+ SystemInfoDto systemInfoDto = new SystemInfoDto<>();
+ systemInfoDto.setTime(format.format(System.currentTimeMillis()));
+ systemInfoDto.setData(cpuInfo);
+ redis.lSet(key, systemInfoDto);
+ // 每秒一个,最多只存30个
+ if (redis.lGetListSize(key) > 30) {
+ for (int i = 0; i < redis.lGetListSize(key) - 30; i++) {
+ redis.lLeftPop(key);
+ }
+ }
+ }
+
+ @Override
+ public void addMemInfo(double memInfo) {
+ String key = VideoManagerConstants.SYSTEM_INFO_MEM_PREFIX + userSetup.getServerId();
+ SystemInfoDto systemInfoDto = new SystemInfoDto<>();
+ systemInfoDto.setTime(format.format(System.currentTimeMillis()));
+ systemInfoDto.setData(memInfo);
+ redis.lSet(key, systemInfoDto);
+ // 每秒一个,最多只存30个
+ if (redis.lGetListSize(key) > 30) {
+ for (int i = 0; i < redis.lGetListSize(key) - 30; i++) {
+ redis.lLeftPop(key);
+ }
+ }
+ }
+
+ @Override
+ public void addNetInfo(Map networkInterfaces) {
+ String key = VideoManagerConstants.SYSTEM_INFO_NET_PREFIX + userSetup.getServerId();
+ SystemInfoDto