首页改造,完成cpu,内存,网络图
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package com.genersoft.iot.vmp.common;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SystemAllInfo {
|
||||
|
||||
private List<Object> cpu;
|
||||
private List<Object> mem;
|
||||
private List<Object> net;
|
||||
|
||||
public List<Object> getCpu() {
|
||||
return cpu;
|
||||
}
|
||||
|
||||
public void setCpu(List<Object> cpu) {
|
||||
this.cpu = cpu;
|
||||
}
|
||||
|
||||
public List<Object> getMem() {
|
||||
return mem;
|
||||
}
|
||||
|
||||
public void setMem(List<Object> mem) {
|
||||
this.mem = mem;
|
||||
}
|
||||
|
||||
public List<Object> getNet() {
|
||||
return net;
|
||||
}
|
||||
|
||||
public void setNet(List<Object> net) {
|
||||
this.net = net;
|
||||
}
|
||||
}
|
||||
@@ -22,14 +22,14 @@ public class SystemInfoTimerTask {
|
||||
@Autowired
|
||||
private IRedisCatchStorage redisCatchStorage;
|
||||
|
||||
@Scheduled(fixedRate = 1000) //每1秒执行一次
|
||||
@Scheduled(fixedRate = 2000) //每1秒执行一次
|
||||
public void execute(){
|
||||
try {
|
||||
double cpuInfo = SystemInfoUtils.getCpuInfo();
|
||||
redisCatchStorage.addCpuInfo(cpuInfo);
|
||||
double memInfo = SystemInfoUtils.getMemInfo();
|
||||
redisCatchStorage.addMemInfo(memInfo);
|
||||
Map<String, String> networkInterfaces = SystemInfoUtils.getNetworkInterfaces();
|
||||
Map<String, Double> networkInterfaces = SystemInfoUtils.getNetworkInterfaces();
|
||||
redisCatchStorage.addNetInfo(networkInterfaces);
|
||||
} catch (InterruptedException e) {
|
||||
logger.error("[获取系统信息失败] {}", e.getMessage());
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.genersoft.iot.vmp.storager;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.common.SystemAllInfo;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.*;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.*;
|
||||
import com.genersoft.iot.vmp.service.bean.GPSMsgInfo;
|
||||
@@ -196,7 +197,7 @@ public interface IRedisCatchStorage {
|
||||
|
||||
void addMemInfo(double memInfo);
|
||||
|
||||
void addNetInfo(Map<String, String> networkInterfaces);
|
||||
void addNetInfo(Map<String, Double> networkInterfaces);
|
||||
|
||||
void sendMobilePositionMsg(JSONObject jsonObject);
|
||||
|
||||
@@ -240,4 +241,7 @@ public interface IRedisCatchStorage {
|
||||
List<SendRtpItem> querySendRTPServerByChnnelId(String channelId);
|
||||
|
||||
List<SendRtpItem> querySendRTPServerByStream(String stream);
|
||||
|
||||
SystemAllInfo getSystemInfo();
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.genersoft.iot.vmp.storager.impl;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.common.SystemAllInfo;
|
||||
import com.genersoft.iot.vmp.common.SystemInfoDto;
|
||||
import com.genersoft.iot.vmp.common.VideoManagerConstants;
|
||||
import com.genersoft.iot.vmp.conf.UserSetting;
|
||||
@@ -694,12 +695,12 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
|
||||
@Override
|
||||
public void addCpuInfo(double cpuInfo) {
|
||||
String key = VideoManagerConstants.SYSTEM_INFO_CPU_PREFIX + userSetting.getServerId();
|
||||
SystemInfoDto<Double> systemInfoDto = new SystemInfoDto<>();
|
||||
systemInfoDto.setTime(DateUtil.getNow());
|
||||
systemInfoDto.setData(cpuInfo);
|
||||
RedisUtil.lSet(key, systemInfoDto);
|
||||
Map<String, String> infoMap = new HashMap<>();
|
||||
infoMap.put("time", DateUtil.getNow());
|
||||
infoMap.put("data", cpuInfo + "");
|
||||
RedisUtil.lSet(key, infoMap);
|
||||
// 每秒一个,最多只存30个
|
||||
if (RedisUtil.lGetListSize(key) > 30) {
|
||||
if (RedisUtil.lGetListSize(key) >= 30) {
|
||||
for (int i = 0; i < RedisUtil.lGetListSize(key) - 30; i++) {
|
||||
RedisUtil.lLeftPop(key);
|
||||
}
|
||||
@@ -709,12 +710,12 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
|
||||
@Override
|
||||
public void addMemInfo(double memInfo) {
|
||||
String key = VideoManagerConstants.SYSTEM_INFO_MEM_PREFIX + userSetting.getServerId();
|
||||
SystemInfoDto<Double> systemInfoDto = new SystemInfoDto<>();
|
||||
systemInfoDto.setTime(DateUtil.getNow());
|
||||
systemInfoDto.setData(memInfo);
|
||||
RedisUtil.lSet(key, systemInfoDto);
|
||||
Map<String, String> infoMap = new HashMap<>();
|
||||
infoMap.put("time", DateUtil.getNow());
|
||||
infoMap.put("data", memInfo + "");
|
||||
RedisUtil.lSet(key, infoMap);
|
||||
// 每秒一个,最多只存30个
|
||||
if (RedisUtil.lGetListSize(key) > 30) {
|
||||
if (RedisUtil.lGetListSize(key) >= 30) {
|
||||
for (int i = 0; i < RedisUtil.lGetListSize(key) - 30; i++) {
|
||||
RedisUtil.lLeftPop(key);
|
||||
}
|
||||
@@ -722,20 +723,34 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addNetInfo(Map<String, String> networkInterfaces) {
|
||||
public void addNetInfo(Map<String, Double> networkInterfaces) {
|
||||
String key = VideoManagerConstants.SYSTEM_INFO_NET_PREFIX + userSetting.getServerId();
|
||||
SystemInfoDto<Map<String, String>> systemInfoDto = new SystemInfoDto<>();
|
||||
systemInfoDto.setTime(DateUtil.getNow());
|
||||
systemInfoDto.setData(networkInterfaces);
|
||||
RedisUtil.lSet(key, systemInfoDto);
|
||||
Map<String, Object> infoMap = new HashMap<>();
|
||||
infoMap.put("time", DateUtil.getNow());
|
||||
for (String netKey : networkInterfaces.keySet()) {
|
||||
infoMap.put(netKey, networkInterfaces.get(netKey));
|
||||
}
|
||||
RedisUtil.lSet(key, infoMap);
|
||||
// 每秒一个,最多只存30个
|
||||
if (RedisUtil.lGetListSize(key) > 30) {
|
||||
if (RedisUtil.lGetListSize(key) >= 30) {
|
||||
for (int i = 0; i < RedisUtil.lGetListSize(key) - 30; i++) {
|
||||
RedisUtil.lLeftPop(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SystemAllInfo getSystemInfo() {
|
||||
String cpuKey = VideoManagerConstants.SYSTEM_INFO_CPU_PREFIX + userSetting.getServerId();
|
||||
String memKey = VideoManagerConstants.SYSTEM_INFO_MEM_PREFIX + userSetting.getServerId();
|
||||
String netKey = VideoManagerConstants.SYSTEM_INFO_NET_PREFIX + userSetting.getServerId();
|
||||
SystemAllInfo systemAllInfo = new SystemAllInfo();
|
||||
systemAllInfo.setCpu(RedisUtil.lGet(cpuKey, 0, -1));
|
||||
systemAllInfo.setMem(RedisUtil.lGet(memKey, 0, -1));
|
||||
systemAllInfo.setNet(RedisUtil.lGet(netKey, 0, -1));
|
||||
return systemAllInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMobilePositionMsg(JSONObject jsonObject) {
|
||||
String key = VideoManagerConstants.VM_MSG_SUBSCRIBE_MOBILE_POSITION;
|
||||
|
||||
@@ -8,6 +8,7 @@ import oshi.hardware.NetworkIF;
|
||||
import oshi.software.os.OperatingSystem;
|
||||
import oshi.util.FormatUtil;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -62,21 +63,32 @@ public class SystemInfoUtils {
|
||||
* 获取网络上传和下载
|
||||
* @return
|
||||
*/
|
||||
public static Map<String,String> getNetworkInterfaces() {
|
||||
public static Map<String,Double> getNetworkInterfaces() {
|
||||
SystemInfo si = new SystemInfo();
|
||||
HardwareAbstractionLayer hal = si.getHardware();
|
||||
List<NetworkIF> networkIFs = hal.getNetworkIFs();
|
||||
int i= networkIFs.size() -1;
|
||||
NetworkIF net= networkIFs.get(i);
|
||||
List<NetworkIF> beforeRecvNetworkIFs = hal.getNetworkIFs();
|
||||
NetworkIF beforeBet= beforeRecvNetworkIFs.get(beforeRecvNetworkIFs.size() - 1);
|
||||
long beforeRecv = beforeBet.getBytesRecv();
|
||||
long beforeSend = beforeBet.getBytesSent();
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
List<NetworkIF> afterNetworkIFs = hal.getNetworkIFs();
|
||||
NetworkIF afterNet = afterNetworkIFs.get(afterNetworkIFs.size() - 1);
|
||||
|
||||
String in = FormatUtil.formatBytes(net.getBytesRecv());
|
||||
String out = FormatUtil.formatBytes(net.getBytesSent());
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
map.put("in",in);
|
||||
map.put("out",out);
|
||||
HashMap<String, Double> map = new HashMap<>();
|
||||
// 速度单位: Mbps
|
||||
map.put("in",formatUnits(afterNet.getBytesRecv()-beforeRecv, 1048576L));
|
||||
map.put("out",formatUnits(afterNet.getBytesSent()-beforeSend, 1048576L));
|
||||
return map;
|
||||
}
|
||||
|
||||
public static double formatUnits(long value, long prefix) {
|
||||
return (double)value / (double)prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取进程数
|
||||
* @return
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.genersoft.iot.vmp.vmanager.server;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.genersoft.iot.vmp.VManageBootstrap;
|
||||
import com.genersoft.iot.vmp.common.SystemAllInfo;
|
||||
import com.genersoft.iot.vmp.common.VersionPo;
|
||||
import com.genersoft.iot.vmp.conf.SipConfig;
|
||||
import com.genersoft.iot.vmp.conf.UserSetting;
|
||||
@@ -12,6 +13,7 @@ import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.IHookSubscribe;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
|
||||
import com.genersoft.iot.vmp.service.IMediaServerService;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import com.genersoft.iot.vmp.utils.SpringBeanFactory;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
|
||||
import gov.nist.javax.sip.SipStackImpl;
|
||||
@@ -60,6 +62,9 @@ public class ServerController {
|
||||
@Autowired
|
||||
private ThreadPoolTaskExecutor taskExecutor;
|
||||
|
||||
@Autowired
|
||||
private IRedisCatchStorage redisCatchStorage;
|
||||
|
||||
|
||||
@GetMapping(value = "/media_server/list")
|
||||
@ResponseBody
|
||||
@@ -202,4 +207,12 @@ public class ServerController {
|
||||
public List<IHookSubscribe> getHooks() {
|
||||
return zlmHttpHookSubscribe.getAll();
|
||||
}
|
||||
|
||||
@GetMapping(value = "/system/info")
|
||||
@ResponseBody
|
||||
@Operation(summary = "获取系统信息")
|
||||
public SystemAllInfo getSystemInfo() {
|
||||
SystemAllInfo systemAllInfo = redisCatchStorage.getSystemInfo();
|
||||
return systemAllInfo;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ public class ApiDeviceController {
|
||||
// private DeviceOffLineDetector offLineDetector;
|
||||
|
||||
/**
|
||||
* 分页获取设备列表 TODO 现在直接返回,尚未实现分页
|
||||
* 分页获取设备列表 现在直接返回,尚未实现分页
|
||||
* @param start
|
||||
* @param limit
|
||||
* @param q
|
||||
@@ -130,11 +130,11 @@ public class ApiDeviceController {
|
||||
deviceJOSNChannel.put("DeviceID", device.getDeviceId());
|
||||
deviceJOSNChannel.put("DeviceName", device.getName());
|
||||
deviceJOSNChannel.put("DeviceOnline", device.getOnline() == 1);
|
||||
deviceJOSNChannel.put("Channel", 0); // TODO 自定义序号
|
||||
deviceJOSNChannel.put("Channel", 0); // 自定义序号
|
||||
deviceJOSNChannel.put("Name", deviceChannel.getName());
|
||||
deviceJOSNChannel.put("Custom", false);
|
||||
deviceJOSNChannel.put("CustomName", "");
|
||||
deviceJOSNChannel.put("SubCount", deviceChannel.getSubCount()); // TODO ? 子节点数, SubCount > 0 表示该通道为子目录
|
||||
deviceJOSNChannel.put("SubCount", deviceChannel.getSubCount()); // 子节点数, SubCount > 0 表示该通道为子目录
|
||||
deviceJOSNChannel.put("SnapURL", "");
|
||||
deviceJOSNChannel.put("Manufacturer ", deviceChannel.getManufacture());
|
||||
deviceJOSNChannel.put("Model", deviceChannel.getModel());
|
||||
|
||||
@@ -57,12 +57,12 @@ public class ApiStreamController {
|
||||
* @param serial 设备编号
|
||||
* @param channel 通道序号 默认值: 1
|
||||
* @param code 通道编号,通过 /api/v1/device/channellist 获取的 ChannelList.ID, 该参数和 channel 二选一传递即可
|
||||
* @param cdn TODO 转推 CDN 地址, 形如: [rtmp|rtsp]://xxx, encodeURIComponent
|
||||
* @param audio TODO 是否开启音频, 默认 开启
|
||||
* @param cdn 转推 CDN 地址, 形如: [rtmp|rtsp]://xxx, encodeURIComponent
|
||||
* @param audio 是否开启音频, 默认 开启
|
||||
* @param transport 流传输模式, 默认 UDP
|
||||
* @param checkchannelstatus TODO 是否检查通道状态, 默认 false, 表示 拉流前不检查通道状态是否在线
|
||||
* @param transportmode TODO 当 transport=TCP 时有效, 指示流传输主被动模式, 默认被动
|
||||
* @param timeout TODO 拉流超时(秒),
|
||||
* @param checkchannelstatus 是否检查通道状态, 默认 false, 表示 拉流前不检查通道状态是否在线
|
||||
* @param transportmode 当 transport=TCP 时有效, 指示流传输主被动模式, 默认被动
|
||||
* @param timeout 拉流超时(秒),
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/start")
|
||||
|
||||
Reference in New Issue
Block a user