服务器注册 agent更新
This commit is contained in:
+1
-1
@@ -97,7 +97,7 @@ public class InitialSystemOtherCollectDataController extends BaseController
|
||||
return toAjax(initialSystemOtherCollectDataService.deleteInitialSystemOtherCollectDataByIds(ids));
|
||||
}
|
||||
/**
|
||||
* 查询交换机系统其他信息采集数据列表
|
||||
* 查询系统其他信息基础数据
|
||||
*/
|
||||
@RequiresPermissions("rocketmq:systemOtherCollectData:list")
|
||||
@PostMapping("/getMontiorMsg")
|
||||
|
||||
+4
-4
@@ -76,13 +76,13 @@ public class RmAgentManagementController extends BaseController
|
||||
|
||||
/**
|
||||
* 手动立即更新
|
||||
* @param id
|
||||
* @param rmAgentManagement
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("rocketmq:management:edit")
|
||||
@GetMapping("/updateAgentNow")
|
||||
public AjaxResult updateAgentNow(Long id){
|
||||
rmAgentManagementService.updateAgentNow(id);
|
||||
@PostMapping("/updateAgentNow")
|
||||
public AjaxResult updateAgentNow(@RequestBody RmAgentManagement rmAgentManagement){
|
||||
rmAgentManagementService.updateAgentNow(rmAgentManagement);
|
||||
return success();
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@ public class RmNetworkInterfaceController extends BaseController
|
||||
*/
|
||||
@RequiresPermissions("rocketmq:networkInterface:list")
|
||||
@PostMapping("/list")
|
||||
public AjaxResult list(RmNetworkInterface rmNetworkInterface)
|
||||
public AjaxResult list(@RequestBody RmNetworkInterface rmNetworkInterface)
|
||||
{
|
||||
List<RmNetworkInterface> list = rmNetworkInterfaceService.selectRmNetworkInterfaceList(rmNetworkInterface);
|
||||
return success(list);
|
||||
|
||||
@@ -80,5 +80,7 @@ public class RmAgentManagement extends BaseEntity
|
||||
private String clientId;
|
||||
/** 部署设备 */
|
||||
private String deployDevice;
|
||||
/** 管理网公网Ip */
|
||||
private String managePublicIp;
|
||||
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ public class MessageHandler {
|
||||
|
||||
// 其他类型消息可以单独注册处理器
|
||||
registerHandler(MsgEnum.注册.getValue(), this::handleRegisterMessage);
|
||||
registerHandler(MsgEnum.获取最新策略.getValue(), this::handleNewPolicyMessage);
|
||||
// registerHandler(MsgEnum.获取最新策略.getValue(), this::handleNewPolicyMessage);
|
||||
// registerHandler(MsgEnum.CPU上报.getValue(), this::handleCpuMessage);
|
||||
// registerHandler(MsgEnum.磁盘上报.getValue(), this::handleDiskMessage);
|
||||
// registerHandler(MsgEnum.容器上报.getValue(), this::handleDockerMessage);
|
||||
@@ -133,7 +133,11 @@ public class MessageHandler {
|
||||
// 自动注册服务器信息
|
||||
RmRegisterMsgRemote rmRegisterMsgRemote = new RmRegisterMsgRemote();
|
||||
BeanUtils.copyProperties(registerMsg, rmRegisterMsgRemote);
|
||||
remoteRevenueConfigService.innerAddRegist(rmRegisterMsgRemote, SecurityConstants.INNER);
|
||||
int rows = remoteRevenueConfigService.innerAddRegist(rmRegisterMsgRemote, SecurityConstants.INNER).getData();
|
||||
if(rows == 2){
|
||||
// 注册成功,下发优先级为0的策略
|
||||
rmMonitorPolicyService.issueDefaultPolicyByClientId(message.getClientId());
|
||||
}
|
||||
// 时间戳转换
|
||||
long timestamp = registerMsg.getTimestamp();
|
||||
long millis = timestamp * 1000;
|
||||
@@ -463,7 +467,7 @@ public class MessageHandler {
|
||||
RmResourceRegistrationRemote updateData = new RmResourceRegistrationRemote();
|
||||
updateData.setClientId(message.getClientId());
|
||||
updateData.setLogicalNodeId(heartbeat.getLogicalNode());
|
||||
remoteRevenueConfigService.innerupdateRegist(updateData, SecurityConstants.INNER);
|
||||
remoteRevenueConfigService.innerUpdateRegist(updateData, SecurityConstants.INNER);
|
||||
// 使用Redis存储状态
|
||||
String statusKey = HEARTBEAT_STATUS_PREFIX + clientId;
|
||||
String timeKey = HEARTBEAT_TIME_PREFIX + clientId;
|
||||
|
||||
+2
-2
@@ -77,10 +77,10 @@ public interface IRmAgentManagementService
|
||||
|
||||
/**
|
||||
* 手动立即更新agent
|
||||
* @param id
|
||||
* @param rmAgentManagement
|
||||
* @return
|
||||
*/
|
||||
int updateAgentNow(Long id);
|
||||
int updateAgentNow(RmAgentManagement rmAgentManagement);
|
||||
|
||||
/**
|
||||
* 配置更新策略
|
||||
|
||||
@@ -90,4 +90,11 @@ public interface IRmMonitorPolicyService
|
||||
* @return
|
||||
*/
|
||||
public int issuePolicyMsgByClientId(String clientId);
|
||||
|
||||
/**
|
||||
* 根据clientId下发优先级为0的监控策略信息
|
||||
* @param clientId
|
||||
* @return
|
||||
*/
|
||||
public int issueDefaultPolicyByClientId(String clientId);
|
||||
}
|
||||
|
||||
-3
@@ -134,7 +134,6 @@ public class InitialDiskInfoServiceImpl implements IInitialDiskInfoService
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> rwSpeedEcharts(InitialDiskInfo initialDiskInfo) {
|
||||
initialDiskInfo.setName("/dev/sda");
|
||||
List<InitialDiskInfo> list = initialDiskInfoMapper.selectInitialDiskInfoList(initialDiskInfo);
|
||||
Map<String, Function<InitialDiskInfo, ?>> extractors = new LinkedHashMap<>();
|
||||
extractors.put("readSpeedData", info -> info.getReadSpeed() / 1024.0);
|
||||
@@ -148,7 +147,6 @@ public class InitialDiskInfoServiceImpl implements IInitialDiskInfoService
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> rwTimesEcharts(InitialDiskInfo initialDiskInfo) {
|
||||
initialDiskInfo.setName("/dev/sda");
|
||||
List<InitialDiskInfo> list = initialDiskInfoMapper.selectInitialDiskInfoList(initialDiskInfo);
|
||||
Map<String, Function<InitialDiskInfo, ?>> extractors = new LinkedHashMap<>();
|
||||
extractors.put("readTimesData", info -> info.getReadTimes());
|
||||
@@ -162,7 +160,6 @@ public class InitialDiskInfoServiceImpl implements IInitialDiskInfoService
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> rwBytesEcharts(InitialDiskInfo initialDiskInfo) {
|
||||
initialDiskInfo.setName("/dev/sda");
|
||||
List<InitialDiskInfo> list = initialDiskInfoMapper.selectInitialDiskInfoList(initialDiskInfo);
|
||||
Map<String, Function<InitialDiskInfo, ?>> extractors = new LinkedHashMap<>();
|
||||
extractors.put("readBytesData", info -> info.getReadBytes());
|
||||
|
||||
+31
-7
@@ -5,8 +5,13 @@ import com.ruoyi.common.core.enums.MsgEnum;
|
||||
import com.ruoyi.common.core.utils.DateUtils;
|
||||
import com.ruoyi.rocketmq.domain.DeviceMessage;
|
||||
import com.ruoyi.rocketmq.domain.RmAgentManagement;
|
||||
import com.ruoyi.rocketmq.domain.vo.*;
|
||||
import com.ruoyi.rocketmq.domain.RmNetworkInterface;
|
||||
import com.ruoyi.rocketmq.domain.vo.AgentUpdateMsgVo;
|
||||
import com.ruoyi.rocketmq.domain.vo.AgentUpdateVo;
|
||||
import com.ruoyi.rocketmq.domain.vo.PolicyTypeVo;
|
||||
import com.ruoyi.rocketmq.domain.vo.PolicyVo;
|
||||
import com.ruoyi.rocketmq.mapper.RmAgentManagementMapper;
|
||||
import com.ruoyi.rocketmq.mapper.RmNetworkInterfaceMapper;
|
||||
import com.ruoyi.rocketmq.model.ProducerMode;
|
||||
import com.ruoyi.rocketmq.producer.MessageProducer;
|
||||
import com.ruoyi.rocketmq.service.IRmAgentManagementService;
|
||||
@@ -19,6 +24,7 @@ import org.springframework.stereotype.Service;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Agent管理Service业务层处理
|
||||
@@ -32,6 +38,8 @@ public class RmAgentManagementServiceImpl implements IRmAgentManagementService
|
||||
{
|
||||
@Autowired
|
||||
private RmAgentManagementMapper rmAgentManagementMapper;
|
||||
@Autowired
|
||||
private RmNetworkInterfaceMapper rmNetworkInterfaceMapper;
|
||||
@Value("${fileDictory.filePath}")
|
||||
private String filePath;
|
||||
|
||||
@@ -61,7 +69,25 @@ public class RmAgentManagementServiceImpl implements IRmAgentManagementService
|
||||
@Override
|
||||
public List<RmAgentManagement> selectRmAgentManagementList(RmAgentManagement rmAgentManagement)
|
||||
{
|
||||
return rmAgentManagementMapper.selectRmAgentManagementList(rmAgentManagement);
|
||||
List<RmAgentManagement> managementList = rmAgentManagementMapper.selectRmAgentManagementList(rmAgentManagement);
|
||||
for (RmAgentManagement agentManagement : managementList) {
|
||||
if(agentManagement.getClientId()!=null){
|
||||
// 设置管理网公网ip
|
||||
RmNetworkInterface queryParam = new RmNetworkInterface();
|
||||
queryParam.setClientId(agentManagement.getClientId());
|
||||
// 使用Optional处理可能的NPE,并筛选bindIp为2或3的接口
|
||||
RmNetworkInterface networkInterface = Optional.ofNullable(rmNetworkInterfaceMapper.selectRmNetworkInterfaceList(queryParam))
|
||||
.map(list -> list.stream()
|
||||
.filter(ni -> "2".equals(ni.getBindIp()) || "3".equals(ni.getBindIp()))
|
||||
.findFirst()
|
||||
.orElse(null))
|
||||
.orElseGet(() -> {
|
||||
return new RmNetworkInterface(); // 返回空对象避免NPE
|
||||
});
|
||||
agentManagement.setManagePublicIp(networkInterface.getPublicIp());
|
||||
}
|
||||
}
|
||||
return managementList;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -146,13 +172,11 @@ public class RmAgentManagementServiceImpl implements IRmAgentManagementService
|
||||
|
||||
/**
|
||||
* 手动立即更新
|
||||
* @param id
|
||||
* @param rmAgentManagement 更新信息
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int updateAgentNow(Long id) {
|
||||
// 根据id查询agent更新信息
|
||||
RmAgentManagement rmAgentManagement = rmAgentManagementMapper.selectRmAgentManagementById(id);
|
||||
public int updateAgentNow(RmAgentManagement rmAgentManagement) {
|
||||
processAgentData(rmAgentManagement);
|
||||
return 1;
|
||||
}
|
||||
@@ -236,7 +260,7 @@ public class RmAgentManagementServiceImpl implements IRmAgentManagementService
|
||||
if("0".equals(rmAgentManagement.getMethod())){
|
||||
currentAgent.setScheduledUpdateTime(null);
|
||||
}
|
||||
rmAgentManagementMapper.updateRmAgentManagementBySn(currentAgent);
|
||||
rmAgentManagementMapper.updateRmAgentManagement(currentAgent);
|
||||
}else{
|
||||
// 如果不存在,添加
|
||||
currentAgent.setLastUpdateTime(DateUtils.getNowDate());
|
||||
|
||||
+48
-11
@@ -24,10 +24,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -289,6 +286,8 @@ public class RmMonitorPolicyServiceImpl implements IRmMonitorPolicyService
|
||||
switchItem.setCollectionCycle(rmMonitorPolicyVo.getCollectionCycle());
|
||||
rmTemplateSwitchMapper.insertRmTemplateSwitch(switchItem);
|
||||
}
|
||||
// 添加交换机策略完成 下发该策略
|
||||
issueSwitchPolicy(rmMonitorPolicy.getId());
|
||||
}else {
|
||||
return 0;
|
||||
}
|
||||
@@ -421,8 +420,6 @@ public class RmMonitorPolicyServiceImpl implements IRmMonitorPolicyService
|
||||
log.error("策略不存在,id: {}", id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// 构建并发送采集配置
|
||||
Map<String, Object> policyDetails = getRmMonitorPolicyMsgById(id);
|
||||
boolean isSwitch = false;
|
||||
@@ -437,11 +434,12 @@ public class RmMonitorPolicyServiceImpl implements IRmMonitorPolicyService
|
||||
startCollectSwitchMsgToDevices(policy.getDeployDevice(), uniqueList, switchOidVo);
|
||||
}
|
||||
// 更新策略状态为已下发
|
||||
// RmMonitorPolicy policyUpdate = new RmMonitorPolicy();
|
||||
// policyUpdate.setId(id);
|
||||
// policyUpdate.setStatus("1");
|
||||
// rmMonitorPolicyMapper.updateRmMonitorPolicy(policyUpdate);
|
||||
|
||||
if("1".equals(policy.getPriority())){
|
||||
RmMonitorPolicy policyUpdate = new RmMonitorPolicy();
|
||||
policyUpdate.setId(id);
|
||||
policyUpdate.setStatus("1");
|
||||
rmMonitorPolicyMapper.updateRmMonitorPolicy(policyUpdate);
|
||||
}
|
||||
return 1;
|
||||
} catch (Exception e) {
|
||||
log.error("下发策略失败,id: {}", id, e);
|
||||
@@ -496,6 +494,45 @@ public class RmMonitorPolicyServiceImpl implements IRmMonitorPolicyService
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 根据clientId下发优先级为0的监控策略信息
|
||||
* @param clientId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int issueDefaultPolicyByClientId(String clientId) {
|
||||
try {
|
||||
// 根据clientId查询未下发的策略信息
|
||||
RmMonitorPolicy queryParam = new RmMonitorPolicy();
|
||||
queryParam.setPriority("0");
|
||||
queryParam.setResourceType("linux");
|
||||
|
||||
// 添加NPE保护
|
||||
List<RmMonitorPolicy> policies = Optional.ofNullable(rmMonitorPolicyMapper.selectRmMonitorPolicyList(queryParam))
|
||||
.orElse(Collections.emptyList());
|
||||
|
||||
if (policies.isEmpty()) {
|
||||
log.warn("未设置默认策略,clientId: {}", clientId);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 构建并发送采集配置
|
||||
Map<String, Object> policyDetails = Optional.ofNullable(getRmMonitorPolicyMsgById(policies.get(0).getId()))
|
||||
.orElse(Collections.emptyMap());
|
||||
|
||||
List<CollectVo> collectVos = Optional.ofNullable(buildCollectConfigurations(policyDetails))
|
||||
.orElse(Collections.emptyList());
|
||||
|
||||
// 去重
|
||||
List<CollectVo> uniqueList = collectVos.stream().distinct().collect(Collectors.toList());
|
||||
String[] clientIdArr = new String[]{clientId};
|
||||
sendMonitorPolicy(clientIdArr, uniqueList);
|
||||
return 1;
|
||||
} catch (Exception e) {
|
||||
log.error("下发策略失败,clientId: {}", clientId, e);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 根据clientId下发监控策略信息
|
||||
* @param clientId
|
||||
|
||||
Reference in New Issue
Block a user