From 3ffe2050827482ba83a1c15afbf346275be86187 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: 星期四, 20 十月 2022 18:03:40 +0800 Subject: [PATCH] 首页改造,完成cpu,内存,网络图 --- src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java | 140 +++++++++++++++++++++++++++++++++++----------- 1 files changed, 105 insertions(+), 35 deletions(-) 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 ff31c11..6178a3b 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 @@ -3,19 +3,20 @@ 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; import com.genersoft.iot.vmp.gb28181.bean.*; import com.genersoft.iot.vmp.media.zlm.dto.MediaItem; import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; -import com.genersoft.iot.vmp.media.zlm.dto.OnPublishHookParam; import com.genersoft.iot.vmp.media.zlm.dto.StreamAuthorityInfo; import com.genersoft.iot.vmp.service.bean.GPSMsgInfo; import com.genersoft.iot.vmp.service.bean.MessageForPushChannel; import com.genersoft.iot.vmp.service.bean.ThirdPartyGB; import com.genersoft.iot.vmp.storager.IRedisCatchStorage; import com.genersoft.iot.vmp.storager.dao.DeviceChannelMapper; +import com.genersoft.iot.vmp.storager.dao.dto.PlatformRegisterInfo; import com.genersoft.iot.vmp.utils.DateUtil; import com.genersoft.iot.vmp.utils.redis.RedisUtil; import org.slf4j.Logger; @@ -125,6 +126,7 @@ } @Override public StreamInfo queryPlayByStreamId(String streamId) { + System.out.println(String.format("%S_%s_%s_*", VideoManagerConstants.PLAYER_PREFIX, userSetting.getServerId(), streamId)); List<Object> playLeys = RedisUtil.scan(String.format("%S_%s_%s_*", VideoManagerConstants.PLAYER_PREFIX, userSetting.getServerId(), streamId)); if (playLeys == null || playLeys.size() == 0) { return null; @@ -163,6 +165,8 @@ @Override public boolean startPlayback(StreamInfo stream, String callId) { + System.out.println(String.format("%S_%s_%s_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, + userSetting.getServerId(), stream.getDeviceID(), stream.getChannelId(), stream.getStream(), callId)); return RedisUtil.set(String.format("%S_%s_%s_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, userSetting.getServerId(), stream.getDeviceID(), stream.getChannelId(), stream.getStream(), callId), stream); } @@ -284,21 +288,37 @@ } @Override + public String queryPlaybackForKey(String deviceId, String channelId, String stream, String callId) { + if (stream == null && callId == null) { + return null; + } + if (deviceId == null) { + deviceId = "*"; + } + if (channelId == null) { + channelId = "*"; + } + if (stream == null) { + stream = "*"; + } + if (callId == null) { + callId = "*"; + } + String key = String.format("%S_%s_%s_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, + userSetting.getServerId(), + deviceId, + channelId, + stream, + callId + ); + List<Object> streamInfoScan = RedisUtil.scan(key); + return (String) streamInfoScan.get(0); + } + + @Override public void updatePlatformCatchInfo(ParentPlatformCatch parentPlatformCatch) { String key = VideoManagerConstants.PLATFORM_CATCH_PREFIX + userSetting.getServerId() + "_" + parentPlatformCatch.getId(); RedisUtil.set(key, parentPlatformCatch); - } - - @Override - public void updatePlatformKeepalive(ParentPlatform parentPlatform) { - String key = VideoManagerConstants.PLATFORM_KEEPALIVE_PREFIX + userSetting.getServerId() + "_" + parentPlatform.getServerGBId(); - RedisUtil.set(key, "", Integer.parseInt(parentPlatform.getKeepTimeout())); - } - - @Override - public void updatePlatformRegister(ParentPlatform parentPlatform) { - String key = VideoManagerConstants.PLATFORM_REGISTER_PREFIX + userSetting.getServerId() + "_" + parentPlatform.getServerGBId(); - RedisUtil.set(key, "", Integer.parseInt(parentPlatform.getExpires())); } @Override @@ -323,15 +343,15 @@ @Override - public void updatePlatformRegisterInfo(String callId, String platformGbId) { + public void updatePlatformRegisterInfo(String callId, PlatformRegisterInfo platformRegisterInfo) { String key = VideoManagerConstants.PLATFORM_REGISTER_INFO_PREFIX + userSetting.getServerId() + "_" + callId; - RedisUtil.set(key, platformGbId, 30); + RedisUtil.set(key, platformRegisterInfo, 30); } @Override - public String queryPlatformRegisterInfo(String callId) { - return (String)RedisUtil.get(VideoManagerConstants.PLATFORM_REGISTER_INFO_PREFIX + userSetting.getServerId() + "_" + callId); + public PlatformRegisterInfo queryPlatformRegisterInfo(String callId) { + return (PlatformRegisterInfo)RedisUtil.get(VideoManagerConstants.PLATFORM_REGISTER_INFO_PREFIX + userSetting.getServerId() + "_" + callId); } @Override @@ -377,6 +397,42 @@ }else { return null; } + } + + @Override + public List<SendRtpItem> querySendRTPServerByChnnelId(String channelId) { + if (channelId == null) { + return null; + } + String platformGbId = "*"; + String callId = "*"; + String streamId = "*"; + String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + userSetting.getServerId() + "_" + platformGbId + + "_" + channelId + "_" + streamId + "_" + callId; + List<Object> scan = RedisUtil.scan(key); + List<SendRtpItem> result = new ArrayList<>(); + for (Object o : scan) { + result.add((SendRtpItem) RedisUtil.get((String) o)); + } + return result; + } + + @Override + public List<SendRtpItem> querySendRTPServerByStream(String stream) { + if (stream == null) { + return null; + } + String platformGbId = "*"; + String callId = "*"; + String channelId = "*"; + String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + userSetting.getServerId() + "_" + platformGbId + + "_" + channelId + "_" + stream + "_" + callId; + List<Object> scan = RedisUtil.scan(key); + List<SendRtpItem> result = new ArrayList<>(); + for (Object o : scan) { + result.add((SendRtpItem) RedisUtil.get((String) o)); + } + return result; } @Override @@ -639,12 +695,12 @@ @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); } @@ -654,12 +710,12 @@ @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); } @@ -667,31 +723,45 @@ } @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; - logger.info("[redis鍙戦�侀�氱煡]绉诲姩浣嶇疆 {}: {}", key, jsonObject.toString()); + logger.info("[redis鍙戦�侀�氱煡] 绉诲姩浣嶇疆 {}: {}", key, jsonObject.toString()); RedisUtil.convertAndSend(key, jsonObject); } @Override public void sendStreamPushRequestedMsg(MessageForPushChannel msg) { String key = VideoManagerConstants.VM_MSG_STREAM_PUSH_REQUESTED; - logger.info("[redis鍙戦�侀�氱煡]鎺ㄦ祦琚姹� {}: {}/{}", key, msg.getApp(), msg.getStream()); + logger.info("[redis鍙戦�侀�氱煡] 鎺ㄦ祦琚姹� {}: {}/{}", key, msg.getApp(), msg.getStream()); RedisUtil.convertAndSend(key, (JSONObject)JSON.toJSON(msg)); } -- Gitblit v1.8.0