首页改造完成,待添加系统信息

This commit is contained in:
648540858
2022-10-24 15:20:35 +08:00
parent 3ffe205082
commit ca891f367c
38 changed files with 882 additions and 168 deletions

View File

@@ -8,6 +8,10 @@ public class SystemAllInfo {
private List<Object> mem;
private List<Object> net;
private long netTotal;
private Object disk;
public List<Object> getCpu() {
return cpu;
}
@@ -31,4 +35,20 @@ public class SystemAllInfo {
public void setNet(List<Object> net) {
this.net = net;
}
public Object getDisk() {
return disk;
}
public void setDisk(Object disk) {
this.disk = disk;
}
public long getNetTotal() {
return netTotal;
}
public void setNetTotal(long netTotal) {
this.netTotal = netTotal;
}
}

View File

@@ -1,22 +0,0 @@
package com.genersoft.iot.vmp.common;
public class SystemInfoDto<T> {
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;
}
}

View File

@@ -27,11 +27,9 @@ public class VideoManagerConstants {
public static final String KEEPLIVEKEY_PREFIX = "VMP_KEEPALIVE_";
// 此处多了一个_暂不修改
// TODO 此处多了一个_暂不修改
public static final String PLAYER_PREFIX = "VMP_PLAYER_";
public static final String PLAY_BLACK_PREFIX = "VMP_PLAYBACK_";
public static final String PLAY_INFO_PREFIX = "VMP_PLAY_INFO_";
public static final String DOWNLOAD_PREFIX = "VMP_DOWNLOAD_";
public static final String PLATFORM_KEEPALIVE_PREFIX = "VMP_PLATFORM_KEEPALIVE_";
@@ -70,6 +68,8 @@ public class VideoManagerConstants {
public static final String SYSTEM_INFO_NET_PREFIX = "VMP_SYSTEM_INFO_NET_";
public static final String SYSTEM_INFO_DISK_PREFIX = "VMP_SYSTEM_INFO_DISK_";

View File

@@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;
/**
@@ -31,6 +32,8 @@ public class SystemInfoTimerTask {
redisCatchStorage.addMemInfo(memInfo);
Map<String, Double> networkInterfaces = SystemInfoUtils.getNetworkInterfaces();
redisCatchStorage.addNetInfo(networkInterfaces);
List<Map<String, Object>> diskInfo =SystemInfoUtils.getDiskInfo();
redisCatchStorage.addDiskInfo(diskInfo);
} catch (InterruptedException e) {
logger.error("[获取系统信息失败] {}", e.getMessage());
}

View File

@@ -1,51 +0,0 @@
package com.genersoft.iot.vmp.gb28181.task;
import com.genersoft.iot.vmp.conf.UserSetting;
import com.genersoft.iot.vmp.gb28181.bean.Device;
import com.genersoft.iot.vmp.service.IDeviceService;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
/**
* 系统启动时控制设备
* @author lin
*/
@Component
@Order(value=4)
public class SipDeviceRunner implements CommandLineRunner {
@Autowired
private IVideoManagerStorage storager;
@Autowired
private IRedisCatchStorage redisCatchStorage;
@Autowired
private UserSetting userSetting;
@Autowired
private IDeviceService deviceService;
@Override
public void run(String... args) throws Exception {
List<Device> deviceList = deviceService.getAllOnlineDevice();
for (Device device : deviceList) {
if (deviceService.expire(device)){
deviceService.offline(device.getDeviceId());
}else {
deviceService.online(device);
}
}
// 重置cseq计数
redisCatchStorage.resetAllCSEQ();
}
}

View File

@@ -0,0 +1,95 @@
package com.genersoft.iot.vmp.gb28181.task;
import com.alibaba.fastjson.JSONObject;
import com.genersoft.iot.vmp.conf.UserSetting;
import com.genersoft.iot.vmp.gb28181.bean.Device;
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils;
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
import com.genersoft.iot.vmp.service.IDeviceService;
import com.genersoft.iot.vmp.service.IMediaServerService;
import com.genersoft.iot.vmp.service.IPlatformService;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 系统启动时控制设备
* @author lin
*/
@Component
@Order(value=4)
public class SipRunner implements CommandLineRunner {
@Autowired
private IVideoManagerStorage storager;
@Autowired
private IRedisCatchStorage redisCatchStorage;
@Autowired
private UserSetting userSetting;
@Autowired
private IDeviceService deviceService;
@Autowired
private ZLMRESTfulUtils zlmresTfulUtils;
@Autowired
private IMediaServerService mediaServerService;
@Autowired
private IPlatformService platformService;
@Autowired
private ISIPCommanderForPlatform commanderForPlatform;
@Override
public void run(String... args) throws Exception {
List<Device> deviceList = deviceService.getAllOnlineDevice();
for (Device device : deviceList) {
if (deviceService.expire(device)){
deviceService.offline(device.getDeviceId());
}else {
deviceService.online(device);
}
}
// 重置cseq计数
redisCatchStorage.resetAllCSEQ();
// 清理redis
// 查找国标推流
List<SendRtpItem> sendRtpItems = redisCatchStorage.queryAllSendRTPServer();
if (sendRtpItems.size() > 0) {
for (SendRtpItem sendRtpItem : sendRtpItems) {
MediaServerItem mediaServerItem = mediaServerService.getOne(sendRtpItem.getMediaServerId());
redisCatchStorage.deleteSendRTPServer(sendRtpItem.getPlatformId(),sendRtpItem.getChannelId(), sendRtpItem.getCallId(),sendRtpItem.getStreamId());
if (mediaServerItem != null) {
Map<String, Object> param = new HashMap<>();
param.put("vhost","__defaultVhost__");
param.put("app",sendRtpItem.getApp());
param.put("stream",sendRtpItem.getStreamId());
param.put("ssrc",sendRtpItem.getSsrc());
JSONObject jsonObject = zlmresTfulUtils.stopSendRtp(mediaServerItem, param);
if (jsonObject != null && jsonObject.getInteger("code") == 0) {
ParentPlatform platform = platformService.queryPlatformByServerGBId(sendRtpItem.getPlatformId());
if (platform != null) {
commanderForPlatform.streamByeCmd(platform, sendRtpItem.getCallId());
}
}
}
}
}
}
}

View File

@@ -2,6 +2,7 @@ package com.genersoft.iot.vmp.service;
import com.genersoft.iot.vmp.gb28181.bean.Device;
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
import com.genersoft.iot.vmp.vmanager.bean.ResourceBaceInfo;
import java.util.List;
@@ -32,4 +33,9 @@ public interface IDeviceChannelService {
*/
int updateChannels(String deviceId, List<DeviceChannel> channels);
/**
* 获取统计信息
* @return
*/
ResourceBaceInfo getOverview();
}

View File

@@ -4,6 +4,7 @@ import com.genersoft.iot.vmp.gb28181.bean.Device;
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
import com.genersoft.iot.vmp.gb28181.bean.SyncStatus;
import com.genersoft.iot.vmp.vmanager.bean.BaseTree;
import com.genersoft.iot.vmp.vmanager.bean.ResourceBaceInfo;
import java.util.List;
@@ -155,4 +156,11 @@ public interface IDeviceService {
* @return
*/
boolean delete(String deviceId);
/**
* 获取统计信息
* @return
*/
ResourceBaceInfo getOverview();
}

View File

@@ -4,10 +4,12 @@ import com.alibaba.fastjson.JSONObject;
import com.genersoft.iot.vmp.gb28181.bean.Device;
import com.genersoft.iot.vmp.media.zlm.ZLMServerConfig;
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
import com.genersoft.iot.vmp.service.bean.MediaServerLoad;
import com.genersoft.iot.vmp.service.bean.SSRCInfo;
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
import java.util.List;
import java.util.Map;
/**
* 媒体服务节点
@@ -87,4 +89,10 @@ public interface IMediaServerService {
void updateMediaServerKeepalive(String mediaServerId, JSONObject data);
boolean checkRtpServer(MediaServerItem mediaServerItem, String rtp, String stream);
/**
* 获取负载信息
* @return
*/
MediaServerLoad getLoad(MediaServerItem mediaServerItem);
}

View File

@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
import com.genersoft.iot.vmp.common.StreamInfo;
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem;
import com.genersoft.iot.vmp.vmanager.bean.ResourceBaceInfo;
import com.github.pagehelper.PageInfo;
public interface IStreamProxyService {
@@ -102,4 +103,11 @@ public interface IStreamProxyService {
* 更新代理流
*/
boolean updateStreamProxy(StreamProxyItem streamProxyItem);
/**
* 获取统计信息
* @return
*/
ResourceBaceInfo getOverview();
}

View File

@@ -6,6 +6,7 @@ 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.StreamPushItem;
import com.genersoft.iot.vmp.service.bean.StreamPushItemFromRedis;
import com.genersoft.iot.vmp.vmanager.bean.ResourceBaceInfo;
import com.genersoft.iot.vmp.vmanager.bean.StreamPushExcelDto;
import com.github.pagehelper.PageInfo;
@@ -106,4 +107,10 @@ public interface IStreamPushService {
* @return
*/
List<String> getAllAppAndStream();
/**
* 获取统计信息
* @return
*/
ResourceBaceInfo getOverview();
}

View File

@@ -0,0 +1,50 @@
package com.genersoft.iot.vmp.service.bean;
public class MediaServerLoad {
private String id;
private int push;
private int proxy;
private int gbReceive;
private int gbSend;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public int getPush() {
return push;
}
public void setPush(int push) {
this.push = push;
}
public int getProxy() {
return proxy;
}
public void setProxy(int proxy) {
this.proxy = proxy;
}
public int getGbReceive() {
return gbReceive;
}
public void setGbReceive(int gbReceive) {
this.gbReceive = gbReceive;
}
public int getGbSend() {
return gbSend;
}
public void setGbSend(int gbSend) {
this.gbSend = gbSend;
}
}

View File

@@ -9,6 +9,7 @@ import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import com.genersoft.iot.vmp.storager.dao.DeviceChannelMapper;
import com.genersoft.iot.vmp.storager.dao.DeviceMapper;
import com.genersoft.iot.vmp.utils.DateUtil;
import com.genersoft.iot.vmp.vmanager.bean.ResourceBaceInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -162,4 +163,9 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService {
}
return addChannels.size() + updateChannels.size();
}
@Override
public ResourceBaceInfo getOverview() {
return channelMapper.getOverview();
}
}

View File

@@ -19,6 +19,7 @@ import com.genersoft.iot.vmp.storager.dao.DeviceMapper;
import com.genersoft.iot.vmp.storager.dao.PlatformChannelMapper;
import com.genersoft.iot.vmp.utils.DateUtil;
import com.genersoft.iot.vmp.vmanager.bean.BaseTree;
import com.genersoft.iot.vmp.vmanager.bean.ResourceBaceInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -620,4 +621,9 @@ public class DeviceServiceImpl implements IDeviceService {
}
return result;
}
@Override
public ResourceBaceInfo getOverview() {
return deviceMapper.getOverview();
}
}

View File

@@ -10,6 +10,8 @@ import java.util.Set;
import com.genersoft.iot.vmp.conf.DynamicTask;
import com.genersoft.iot.vmp.conf.exception.ControllerException;
import com.genersoft.iot.vmp.service.bean.MediaServerLoad;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -90,6 +92,9 @@ public class MediaServerServiceImpl implements IMediaServerService {
@Autowired
private DynamicTask dynamicTask;
@Autowired
private IRedisCatchStorage redisCatchStorage;
/**
* 初始化
*/
@@ -691,4 +696,15 @@ public class MediaServerServiceImpl implements IMediaServerService {
}
return false;
}
@Override
public MediaServerLoad getLoad(MediaServerItem mediaServerItem) {
MediaServerLoad result = new MediaServerLoad();
result.setId(mediaServerItem.getId());
result.setPush(redisCatchStorage.getPushStreamCount(mediaServerItem.getId()));
result.setProxy(redisCatchStorage.getProxyStreamCount(mediaServerItem.getId()));
result.setGbReceive(redisCatchStorage.getGbReceiveCount(mediaServerItem.getId()));
result.setGbSend(redisCatchStorage.getGbSendCount(mediaServerItem.getId()));
return result;
}
}

View File

@@ -26,6 +26,7 @@ import com.genersoft.iot.vmp.storager.dao.StreamProxyMapper;
import com.genersoft.iot.vmp.service.IStreamProxyService;
import com.genersoft.iot.vmp.utils.DateUtil;
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
import com.genersoft.iot.vmp.vmanager.bean.ResourceBaceInfo;
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
@@ -454,4 +455,9 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
}
}
@Override
public ResourceBaceInfo getOverview() {
return streamProxyMapper.getOverview();
}
}

View File

@@ -18,6 +18,7 @@ import com.genersoft.iot.vmp.service.bean.StreamPushItemFromRedis;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import com.genersoft.iot.vmp.storager.dao.*;
import com.genersoft.iot.vmp.utils.DateUtil;
import com.genersoft.iot.vmp.vmanager.bean.ResourceBaceInfo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
@@ -507,6 +508,12 @@ public class StreamPushServiceImpl implements IStreamPushService {
@Override
public List<String> getAllAppAndStream() {
return streamPushMapper.getAllAppAndStream();
}
@Override
public ResourceBaceInfo getOverview() {
return streamPushMapper.getOverview(userSetting.isUsePushingAsStatus());
}
}

View File

@@ -244,4 +244,16 @@ public interface IRedisCatchStorage {
SystemAllInfo getSystemInfo();
int getPushStreamCount(String id);
int getProxyStreamCount(String id);
int getGbReceiveCount(String id);
int getGbSendCount(String id);
void addDiskInfo(List<Map<String, Object>> diskInfo);
List<SendRtpItem> queryAllSendRTPServer();
}

View File

@@ -3,6 +3,7 @@ package com.genersoft.iot.vmp.storager.dao;
import com.genersoft.iot.vmp.gb28181.bean.Device;
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannelInPlatform;
import com.genersoft.iot.vmp.vmanager.bean.ResourceBaceInfo;
import com.genersoft.iot.vmp.vmanager.gb28181.platform.bean.ChannelReduce;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
@@ -347,4 +348,8 @@ public interface DeviceChannelMapper {
@Select("select * from device_channel where deviceId = #{deviceId}")
List<DeviceChannel> queryAllChannels(String deviceId);
@Select("select count(1) as total, sum(status) as online from device_channel")
ResourceBaceInfo getOverview();
}

View File

@@ -1,6 +1,7 @@
package com.genersoft.iot.vmp.storager.dao;
import com.genersoft.iot.vmp.gb28181.bean.Device;
import com.genersoft.iot.vmp.vmanager.bean.ResourceBaceInfo;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
@@ -251,4 +252,8 @@ public interface DeviceMapper {
"#{online}" +
")")
void addCustomDevice(Device device);
@Select("select count(1) as total, sum(online) as online from device")
ResourceBaceInfo getOverview();
}

View File

@@ -1,6 +1,7 @@
package com.genersoft.iot.vmp.storager.dao;
import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem;
import com.genersoft.iot.vmp.vmanager.bean.ResourceBaceInfo;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
@@ -75,4 +76,7 @@ public interface StreamProxyMapper {
@Select("SELECT st.*, pgs.gbId, pgs.name, pgs.longitude, pgs.latitude FROM stream_proxy st LEFT JOIN gb_stream pgs on st.app = pgs.app AND st.stream = pgs.stream WHERE st.enable_remove_none_reader=true AND st.mediaServerId=#{mediaServerId} order by st.createTime desc")
List<StreamProxyItem> selecAutoRemoveItemByMediaServerId(String mediaServerId);
@Select("select count(1) as total, sum(status) as online from stream_proxy")
ResourceBaceInfo getOverview();
}

View File

@@ -3,6 +3,7 @@ package com.genersoft.iot.vmp.storager.dao;
import com.genersoft.iot.vmp.gb28181.bean.GbStream;
import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem;
import com.genersoft.iot.vmp.service.bean.StreamPushItemFromRedis;
import com.genersoft.iot.vmp.vmanager.bean.ResourceBaceInfo;
import org.apache.ibatis.annotations.*;
// import org.omg.PortableInterceptor.INACTIVE;
import org.springframework.stereotype.Repository;
@@ -171,4 +172,10 @@ public interface StreamPushMapper {
@Select("SELECT CONCAT(app,stream) FROM gb_stream")
List<String> getAllAppAndStream();
@Select(value = {" <script>" +
" <if test='pushIngAsOnline == true'> select count(1) as total, sum(pushIng) as online from stream_push </if>" +
" <if test='pushIngAsOnline == false'> select count(1) as total, sum(status) as online from stream_push </if>" +
" </script>"})
ResourceBaceInfo getOverview(boolean pushIngAsOnline);
}

View File

@@ -4,7 +4,6 @@ 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.*;
@@ -18,6 +17,7 @@ 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.SystemInfoUtils;
import com.genersoft.iot.vmp.utils.redis.RedisUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -89,8 +89,9 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
*/
@Override
public boolean startPlay(StreamInfo stream) {
return RedisUtil.set(String.format("%S_%S_%s_%s_%s", VideoManagerConstants.PLAYER_PREFIX, userSetting.getServerId(),
stream.getStream(), stream.getDeviceID(), stream.getChannelId()),
return RedisUtil.set(String.format("%S_%s_%s_%s_%s_%s", VideoManagerConstants.PLAYER_PREFIX, userSetting.getServerId(),
stream.getMediaServerId(), stream.getStream(), stream.getDeviceID(), stream.getChannelId()),
stream);
}
@@ -104,8 +105,9 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
if (streamInfo == null) {
return false;
}
return RedisUtil.del(String.format("%S_%s_%s_%s_%s", VideoManagerConstants.PLAYER_PREFIX,
return RedisUtil.del(String.format("%S_%s_%s_%s_%s_%s", VideoManagerConstants.PLAYER_PREFIX,
userSetting.getServerId(),
streamInfo.getMediaServerId(),
streamInfo.getStream(),
streamInfo.getDeviceID(),
streamInfo.getChannelId()));
@@ -117,17 +119,17 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
*/
@Override
public StreamInfo queryPlay(StreamInfo streamInfo) {
return (StreamInfo)RedisUtil.get(String.format("%S_%s_%s_%s_%s",
return (StreamInfo)RedisUtil.get(String.format("%S_%s_%s_%s_%s_%s",
VideoManagerConstants.PLAYER_PREFIX,
userSetting.getServerId(),
streamInfo.getMediaServerId(),
streamInfo.getStream(),
streamInfo.getDeviceID(),
streamInfo.getChannelId()));
}
@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));
List<Object> playLeys = RedisUtil.scan(String.format("%S_%s_*_%s_*", VideoManagerConstants.PLAYER_PREFIX, userSetting.getServerId(), streamId));
if (playLeys == null || playLeys.size() == 0) {
return null;
}
@@ -136,7 +138,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
@Override
public StreamInfo queryPlayByDevice(String deviceId, String channelId) {
List<Object> playLeys = RedisUtil.scan(String.format("%S_%s_*_%s_%s", VideoManagerConstants.PLAYER_PREFIX,
List<Object> playLeys = RedisUtil.scan(String.format("%S_%s_*_*_%s_%s", VideoManagerConstants.PLAYER_PREFIX,
userSetting.getServerId(),
deviceId,
channelId));
@@ -149,8 +151,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
@Override
public Map<String, StreamInfo> queryPlayByDeviceId(String deviceId) {
Map<String, StreamInfo> streamInfos = new HashMap<>();
// List<Object> playLeys = RedisUtil.keys(String.format("%S_*_%S_*", VideoManagerConstants.PLAYER_PREFIX, deviceId));
List<Object> players = RedisUtil.scan(String.format("%S_%s_*_%S_*", VideoManagerConstants.PLAYER_PREFIX, userSetting.getServerId(),deviceId));
List<Object> players = RedisUtil.scan(String.format("%S_%s_*_*_%s_*", VideoManagerConstants.PLAYER_PREFIX, userSetting.getServerId(),deviceId));
if (players.size() == 0) {
return streamInfos;
}
@@ -165,21 +166,19 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
@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);
return RedisUtil.set(String.format("%S_%s_%s_%s_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX,
userSetting.getServerId(), stream.getMediaServerId(), stream.getDeviceID(), stream.getChannelId(), stream.getStream(), callId), stream);
}
@Override
public boolean startDownload(StreamInfo stream, String callId) {
boolean result;
if (stream.getProgress() == 1) {
result = RedisUtil.set(String.format("%S_%s_%s_%s_%s_%s", VideoManagerConstants.DOWNLOAD_PREFIX,
userSetting.getServerId(), stream.getDeviceID(), stream.getChannelId(), stream.getStream(), callId), stream);
result = RedisUtil.set(String.format("%S_%s_%s_%s_%s_%s_%s", VideoManagerConstants.DOWNLOAD_PREFIX,
userSetting.getServerId(), stream.getMediaServerId(), stream.getDeviceID(), stream.getChannelId(), stream.getStream(), callId), stream);
}else {
result = RedisUtil.set(String.format("%S_%s_%s_%s_%s_%s", VideoManagerConstants.DOWNLOAD_PREFIX,
userSetting.getServerId(), stream.getDeviceID(), stream.getChannelId(), stream.getStream(), callId), stream, 60*60);
result = RedisUtil.set(String.format("%S_%s_%s_%s_%s_%s_%s", VideoManagerConstants.DOWNLOAD_PREFIX,
userSetting.getServerId(), stream.getMediaServerId(), stream.getDeviceID(), stream.getChannelId(), stream.getStream(), callId), stream, 60*60);
}
return result;
}
@@ -203,7 +202,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
if (callId == null) {
callId = "*";
}
String key = String.format("%S_%s_%s_%s_%s_%s", VideoManagerConstants.DOWNLOAD_PREFIX,
String key = String.format("%S_%s_*_%s_%s_%s_%s", VideoManagerConstants.DOWNLOAD_PREFIX,
userSetting.getServerId(),
deviceId,
channelId,
@@ -239,7 +238,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
if (callId == null) {
callId = "*";
}
String key = String.format("%S_%s_%s_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX,
String key = String.format("%S_%s_*_%s_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX,
userSetting.getServerId(),
deviceId,
channelId,
@@ -272,7 +271,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
if (callId == null) {
callId = "*";
}
String key = String.format("%S_%s_%s_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX,
String key = String.format("%S_%s_*_%s_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX,
userSetting.getServerId(),
deviceId,
channelId,
@@ -304,7 +303,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
if (callId == null) {
callId = "*";
}
String key = String.format("%S_%s_%s_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX,
String key = String.format("%S_%s_*_%s_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX,
userSetting.getServerId(),
deviceId,
channelId,
@@ -369,9 +368,14 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
@Override
public void updateSendRTPSever(SendRtpItem sendRtpItem) {
String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + userSetting.getServerId() + "_"
+ sendRtpItem.getPlatformId() + "_" + sendRtpItem.getChannelId() + "_"
+ sendRtpItem.getStreamId() + "_" + sendRtpItem.getCallId();
String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX +
userSetting.getServerId() + "_"
+ sendRtpItem.getMediaServerId() + "_"
+ sendRtpItem.getPlatformId() + "_"
+ sendRtpItem.getChannelId() + "_"
+ sendRtpItem.getStreamId() + "_"
+ sendRtpItem.getCallId();
RedisUtil.set(key, sendRtpItem);
}
@@ -389,8 +393,12 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
if (callId == null) {
callId = "*";
}
String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + userSetting.getServerId() + "_" + platformGbId
+ "_" + channelId + "_" + streamId + "_" + callId;
String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX
+ userSetting.getServerId() + "_*_"
+ platformGbId + "_"
+ channelId + "_"
+ streamId + "_"
+ callId;
List<Object> scan = RedisUtil.scan(key);
if (scan.size() > 0) {
return (SendRtpItem)RedisUtil.get((String)scan.get(0));
@@ -407,8 +415,12 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
String platformGbId = "*";
String callId = "*";
String streamId = "*";
String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + userSetting.getServerId() + "_" + platformGbId
+ "_" + channelId + "_" + streamId + "_" + callId;
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) {
@@ -425,8 +437,12 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
String platformGbId = "*";
String callId = "*";
String channelId = "*";
String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + userSetting.getServerId() + "_" + platformGbId
+ "_" + channelId + "_" + stream + "_" + callId;
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) {
@@ -440,7 +456,9 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
if (platformGbId == null) {
platformGbId = "*";
}
String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + userSetting.getServerId() + "_" + platformGbId + "_*" + "_*" + "_*";
String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX
+ userSetting.getServerId() + "_*_"
+ platformGbId + "_*" + "_*" + "_*";
List<Object> queryResult = RedisUtil.scan(key);
List<SendRtpItem> result= new ArrayList<>();
@@ -465,8 +483,12 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
if (callId == null) {
callId = "*";
}
String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + userSetting.getServerId() + "_" + platformGbId
+ "_" + channelId + "_" + streamId + "_" + callId;
String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX
+ userSetting.getServerId() + "_*_"
+ platformGbId + "_"
+ channelId + "_"
+ streamId + "_"
+ callId;
List<Object> scan = RedisUtil.scan(key);
if (scan.size() > 0) {
for (Object keyStr : scan) {
@@ -475,7 +497,20 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
}
}
@Override
public List<SendRtpItem> queryAllSendRTPServer() {
String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX
+ userSetting.getServerId() + "_*";
List<Object> queryResult = RedisUtil.scan(key);
List<SendRtpItem> result= new ArrayList<>();
for (Object o : queryResult) {
String keyItem = (String) o;
result.add((SendRtpItem) RedisUtil.get(keyItem));
}
return result;
}
/**
* 查询某个通道是否存在上级点播RTP推送
@@ -483,7 +518,9 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
*/
@Override
public boolean isChannelSendingRTP(String channelId) {
String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + userSetting.getServerId() + "_" + "*_" + channelId + "*_" + "*_";
String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX
+ userSetting.getServerId() + "_*_*_"
+ channelId + "*_" + "*_";
List<Object> RtpStreams = RedisUtil.scan(key);
if (RtpStreams.size() > 0) {
return true;
@@ -503,7 +540,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
}
}
List<Object> playBackers = RedisUtil.scan(String.format("%S_%s_%s_*_*_*", VideoManagerConstants.PLAY_BLACK_PREFIX,
List<Object> playBackers = RedisUtil.scan(String.format("%S_%s_*_%s_*_*_*", VideoManagerConstants.PLAY_BLACK_PREFIX,
userSetting.getServerId(),
deviceId));
if (playBackers.size() > 0) {
@@ -569,7 +606,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
if (callId == null) {
callId = "*";
}
String key = String.format("%S_%s_%s_%s_%s_%s", VideoManagerConstants.DOWNLOAD_PREFIX,
String key = String.format("%S_%s_*_%s_%s_%s_%s", VideoManagerConstants.DOWNLOAD_PREFIX,
userSetting.getServerId(),
deviceId,
channelId,
@@ -739,15 +776,26 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
}
}
@Override
public void addDiskInfo(List<Map<String, Object>> diskInfo) {
String key = VideoManagerConstants.SYSTEM_INFO_DISK_PREFIX + userSetting.getServerId();
RedisUtil.set(key, diskInfo);
}
@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();
String diskKey = VideoManagerConstants.SYSTEM_INFO_DISK_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));
systemAllInfo.setDisk(RedisUtil.get(diskKey));
systemAllInfo.setNetTotal(SystemInfoUtils.getNetworkTotal());
return systemAllInfo;
}
@@ -786,4 +834,32 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
jsonObject.put(key, key);
RedisUtil.convertAndSend(key, jsonObject);
}
@Override
public int getPushStreamCount(String id) {
String key = VideoManagerConstants.WVP_SERVER_STREAM_PREFIX + userSetting.getServerId() + "_PUSH_*_*_" + id;
return RedisUtil.scan(key).size();
}
@Override
public int getProxyStreamCount(String id) {
String key = VideoManagerConstants.WVP_SERVER_STREAM_PREFIX + userSetting.getServerId() + "_PULL_*_*_" + id;
return RedisUtil.scan(key).size();
}
@Override
public int getGbReceiveCount(String id) {
String playKey = VideoManagerConstants.PLAYER_PREFIX + "_" + userSetting.getServerId() + "_" + id + "_*";
String playBackKey = VideoManagerConstants.PLAY_BLACK_PREFIX + "_" + userSetting.getServerId() + "_" + id + "_*";
String downloadKey = VideoManagerConstants.DOWNLOAD_PREFIX + "_" + userSetting.getServerId() + "_" + id + "_*";
return RedisUtil.scan(playKey).size() + RedisUtil.scan(playBackKey).size() + RedisUtil.scan(downloadKey).size();
}
@Override
public int getGbSendCount(String id) {
String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX
+ userSetting.getServerId() + "_*_" + id + "_*";
return RedisUtil.scan(key).size();
}
}

View File

@@ -13,7 +13,7 @@ public class GitUtil {
@Value("${git.branch:}")
private String branch;
@Value("${git.commit.id:}")
@Value("${git.commit.id.abbrev:}")
private String gitCommitId;
@Value("${git.remote.origin.url:}")
private String gitUrl;

View File

@@ -1,14 +1,14 @@
package com.genersoft.iot.vmp.utils;
import org.springframework.util.ObjectUtils;
import oshi.SystemInfo;
import oshi.hardware.CentralProcessor;
import oshi.hardware.GlobalMemory;
import oshi.hardware.HardwareAbstractionLayer;
import oshi.hardware.NetworkIF;
import oshi.hardware.*;
import oshi.software.os.OperatingSystem;
import oshi.util.FormatUtil;
import java.io.File;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -85,6 +85,19 @@ public class SystemInfoUtils {
return map;
}
/**
* 获取带宽总值
* @return
*/
public static long getNetworkTotal() {
SystemInfo si = new SystemInfo();
HardwareAbstractionLayer hal = si.getHardware();
List<NetworkIF> recvNetworkIFs = hal.getNetworkIFs();
NetworkIF networkIF= recvNetworkIFs.get(recvNetworkIFs.size() - 1);
return networkIF.getSpeed()/1048576L/8L;
}
public static double formatUnits(long value, long prefix) {
return (double)value / (double)prefix;
}
@@ -100,4 +113,31 @@ public class SystemInfoUtils {
int processCount = os.getProcessCount();
return processCount;
}
public static List<Map<String, Object>> getDiskInfo() {
List<Map<String, Object>> result = new ArrayList<>();
String osName = System.getProperty("os.name");
List<String> pathArray = new ArrayList<>();
if (osName.startsWith("Mac OS")) {
// 苹果
pathArray.add("/");
} else if (osName.startsWith("Windows")) {
// windows
pathArray.add("C:");
} else {
pathArray.add("/");
pathArray.add("/home");
}
for (String path : pathArray) {
Map<String, Object> infoMap = new HashMap<>();
infoMap.put("path", path);
File partitionFile = new File(path);
// 单位: GB
infoMap.put("use", (partitionFile.getTotalSpace() - partitionFile.getFreeSpace())/1024/1024/1024D);
infoMap.put("free", partitionFile.getFreeSpace()/1024/1024/1024D);
result.add(infoMap);
}
return result;
}
}

View File

@@ -0,0 +1,22 @@
package com.genersoft.iot.vmp.vmanager.bean;
public class ResourceBaceInfo {
private int total;
private int online;
public int getTotal() {
return total;
}
public void setTotal(int total) {
this.total = total;
}
public int getOnline() {
return online;
}
public void setOnline(int online) {
this.online = online;
}
}

View File

@@ -0,0 +1,41 @@
package com.genersoft.iot.vmp.vmanager.bean;
public class ResourceInfo {
private ResourceBaceInfo device;
private ResourceBaceInfo channel;
private ResourceBaceInfo push;
private ResourceBaceInfo proxy;
public ResourceBaceInfo getDevice() {
return device;
}
public void setDevice(ResourceBaceInfo device) {
this.device = device;
}
public ResourceBaceInfo getChannel() {
return channel;
}
public void setChannel(ResourceBaceInfo channel) {
this.channel = channel;
}
public ResourceBaceInfo getPush() {
return push;
}
public void setPush(ResourceBaceInfo push) {
this.push = push;
}
public ResourceBaceInfo getProxy() {
return proxy;
}
public void setProxy(ResourceBaceInfo proxy) {
this.proxy = proxy;
}
}

View File

@@ -12,10 +12,13 @@ import com.genersoft.iot.vmp.conf.exception.ControllerException;
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.service.*;
import com.genersoft.iot.vmp.service.bean.MediaServerLoad;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import com.genersoft.iot.vmp.utils.SpringBeanFactory;
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
import com.genersoft.iot.vmp.vmanager.bean.ResourceBaceInfo;
import com.genersoft.iot.vmp.vmanager.bean.ResourceInfo;
import gov.nist.javax.sip.SipStackImpl;
import io.swagger.v3.oas.annotations.Operation;
@@ -30,8 +33,7 @@ import org.springframework.web.bind.annotation.*;
import javax.sip.ListeningPoint;
import javax.sip.ObjectInUseException;
import javax.sip.SipProvider;
import java.util.Iterator;
import java.util.List;
import java.util.*;
@SuppressWarnings("rawtypes")
@Tag(name = "服务控制")
@@ -55,6 +57,20 @@ public class ServerController {
@Autowired
private UserSetting userSetting;
@Autowired
private IDeviceService deviceService;
@Autowired
private IDeviceChannelService channelService;
@Autowired
private IStreamPushService pushService;
@Autowired
private IStreamProxyService proxyService;
@Value("${server.port}")
private int serverPort;
@@ -213,6 +229,40 @@ public class ServerController {
@Operation(summary = "获取系统信息")
public SystemAllInfo getSystemInfo() {
SystemAllInfo systemAllInfo = redisCatchStorage.getSystemInfo();
return systemAllInfo;
}
@GetMapping(value = "/media_server/load")
@ResponseBody
@Operation(summary = "获取负载信息")
public List<MediaServerLoad> getMediaLoad() {
List<MediaServerLoad> result = new ArrayList<>();
List<MediaServerItem> allOnline = mediaServerService.getAllOnline();
if (allOnline.size() == 0) {
return result;
}else {
for (MediaServerItem mediaServerItem : allOnline) {
result.add(mediaServerService.getLoad(mediaServerItem));
}
}
return result;
}
@GetMapping(value = "/resource/info")
@ResponseBody
@Operation(summary = "获取负载信息")
public ResourceInfo getResourceInfo() {
ResourceInfo result = new ResourceInfo();
ResourceBaceInfo deviceInfo = deviceService.getOverview();
result.setDevice(deviceInfo);
ResourceBaceInfo channelInfo = channelService.getOverview();
result.setChannel(channelInfo);
ResourceBaceInfo pushInfo = pushService.getOverview();
result.setPush(pushInfo);
ResourceBaceInfo proxyInfo = proxyService.getOverview();
result.setProxy(proxyInfo);
return result;
}
}