1、优化tcpdump解析速度。
2、补充tcpdump晚8点默认策略下发。 3、服务器管理列表增加出省流量占比列。
This commit is contained in:
+10
-4
@@ -3,10 +3,7 @@ package com.tongran.system.api;
|
|||||||
import com.tongran.common.core.constant.SecurityConstants;
|
import com.tongran.common.core.constant.SecurityConstants;
|
||||||
import com.tongran.common.core.constant.ServiceNameConstants;
|
import com.tongran.common.core.constant.ServiceNameConstants;
|
||||||
import com.tongran.common.core.domain.R;
|
import com.tongran.common.core.domain.R;
|
||||||
import com.tongran.system.api.domain.RmAlarmRecordRemote;
|
import com.tongran.system.api.domain.*;
|
||||||
import com.tongran.system.api.domain.RmDeployScriptRemote;
|
|
||||||
import com.tongran.system.api.domain.RmMonitorPolicyRemote;
|
|
||||||
import com.tongran.system.api.domain.RmNetworkInterfaceRemote;
|
|
||||||
import com.tongran.system.api.factory.RemoteRocketMqFallbackFactory;
|
import com.tongran.system.api.factory.RemoteRocketMqFallbackFactory;
|
||||||
import org.springframework.cloud.openfeign.FeignClient;
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
@@ -106,4 +103,13 @@ public interface RemoteRocketMqService {
|
|||||||
*/
|
*/
|
||||||
@PostMapping("/networkInterfaceChild/innerGetChildList")
|
@PostMapping("/networkInterfaceChild/innerGetChildList")
|
||||||
public R<List<RmNetworkInterfaceRemote>> innerGetChildList(@RequestBody RmNetworkInterfaceRemote rmNetworkInterfaceRemote, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
public R<List<RmNetworkInterfaceRemote>> innerGetChildList(@RequestBody RmNetworkInterfaceRemote rmNetworkInterfaceRemote, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下发TCPDUMP默认策略
|
||||||
|
* @param rmTcpdumpConfigRemote
|
||||||
|
* @param source
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping("/rmTcpdumpConfig/innerInsertRmTcpdumpConfig")
|
||||||
|
public R<Integer> innerInsertRmTcpdumpConfig(@RequestBody RmTcpdumpConfigRemote rmTcpdumpConfigRemote, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||||
}
|
}
|
||||||
|
|||||||
+3
@@ -5,6 +5,7 @@ import com.tongran.common.core.annotation.Excel;
|
|||||||
import com.tongran.common.core.web.domain.BaseEntity;
|
import com.tongran.common.core.web.domain.BaseEntity;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -186,5 +187,7 @@ public class RmResourceRegistrationRemote extends BaseEntity
|
|||||||
private String frpcRemotePort;
|
private String frpcRemotePort;
|
||||||
/** FRPC服务器地址 */
|
/** FRPC服务器地址 */
|
||||||
private String frpcServerAddr;
|
private String frpcServerAddr;
|
||||||
|
/** 出省流量占比 */
|
||||||
|
private BigDecimal outboundRate;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+39
@@ -0,0 +1,39 @@
|
|||||||
|
package com.tongran.system.api.domain;
|
||||||
|
|
||||||
|
import com.tongran.common.core.annotation.Excel;
|
||||||
|
import com.tongran.common.core.web.domain.BaseEntity;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* tcpdump探测策略对象 rm_tcpdump_config
|
||||||
|
*
|
||||||
|
* @author tongran
|
||||||
|
* @date 2026-01-21
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class RmTcpdumpConfigRemote extends BaseEntity
|
||||||
|
{
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/** 主键ID */
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/** 客户端ID */
|
||||||
|
@Excel(name = "客户端ID")
|
||||||
|
private String clientId;
|
||||||
|
|
||||||
|
/** 开启探测(0:否,1:是) */
|
||||||
|
@Excel(name = "开启探测(0:否,1:是)")
|
||||||
|
private Integer detectFlag;
|
||||||
|
|
||||||
|
/** 探测频率 */
|
||||||
|
@Excel(name = "探测频率")
|
||||||
|
private String frequency;
|
||||||
|
|
||||||
|
/** 探测时间列表(多个时间用,分隔) */
|
||||||
|
@Excel(name = "探测时间列表(多个时间用,分隔)")
|
||||||
|
private String detectTimes;
|
||||||
|
|
||||||
|
private String clientIds;
|
||||||
|
|
||||||
|
}
|
||||||
+6
-4
@@ -2,10 +2,7 @@ package com.tongran.system.api.factory;
|
|||||||
|
|
||||||
import com.tongran.common.core.domain.R;
|
import com.tongran.common.core.domain.R;
|
||||||
import com.tongran.system.api.RemoteRocketMqService;
|
import com.tongran.system.api.RemoteRocketMqService;
|
||||||
import com.tongran.system.api.domain.RmAlarmRecordRemote;
|
import com.tongran.system.api.domain.*;
|
||||||
import com.tongran.system.api.domain.RmDeployScriptRemote;
|
|
||||||
import com.tongran.system.api.domain.RmMonitorPolicyRemote;
|
|
||||||
import com.tongran.system.api.domain.RmNetworkInterfaceRemote;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||||
@@ -88,6 +85,11 @@ public class RemoteRocketMqFallbackFactory implements FallbackFactory<RemoteRock
|
|||||||
public R<List<RmNetworkInterfaceRemote>> innerGetChildList(RmNetworkInterfaceRemote rmNetworkInterfaceRemote, String source) {
|
public R<List<RmNetworkInterfaceRemote>> innerGetChildList(RmNetworkInterfaceRemote rmNetworkInterfaceRemote, String source) {
|
||||||
return R.fail(throwable.getMessage());
|
return R.fail(throwable.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public R<Integer> innerInsertRmTcpdumpConfig(RmTcpdumpConfigRemote rmTcpdumpConfigRemote, String source) {
|
||||||
|
return R.fail(throwable.getMessage());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
@@ -88,6 +88,9 @@ public class RmResourceRegistration extends BaseEntity
|
|||||||
*/
|
*/
|
||||||
@Excel(name = "心跳时间间隔")
|
@Excel(name = "心跳时间间隔")
|
||||||
private Integer heartbeatInterval;
|
private Integer heartbeatInterval;
|
||||||
|
/** 出省流量占比 */
|
||||||
|
@Excel(name = "出省流量占比")
|
||||||
|
private BigDecimal outboundRate;
|
||||||
|
|
||||||
/** 需要绑定的网卡信息 */
|
/** 需要绑定的网卡信息 */
|
||||||
private List<Map> bindNetworkMsg;
|
private List<Map> bindNetworkMsg;
|
||||||
@@ -258,10 +261,12 @@ public class RmResourceRegistration extends BaseEntity
|
|||||||
/** 昨日95值排序 1正序 2倒叙 3不排序 4 cpu内存倒叙*/
|
/** 昨日95值排序 1正序 2倒叙 3不排序 4 cpu内存倒叙*/
|
||||||
private Integer bandwidthResultSort;
|
private Integer bandwidthResultSort;
|
||||||
/** cpu利用率 */
|
/** cpu利用率 */
|
||||||
|
@Excel(name = "cpu利用率")
|
||||||
private BigDecimal cpuUtil;
|
private BigDecimal cpuUtil;
|
||||||
/** cpu核数 */
|
/** cpu核数 */
|
||||||
private BigDecimal cpuCores;
|
private BigDecimal cpuCores;
|
||||||
/** 内存使用率 */
|
/** 内存使用率 */
|
||||||
|
@Excel(name = "内存使用率")
|
||||||
private BigDecimal memUtil;
|
private BigDecimal memUtil;
|
||||||
/** 总内存 */
|
/** 总内存 */
|
||||||
private Integer memTotalSize;
|
private Integer memTotalSize;
|
||||||
|
|||||||
+13
@@ -1063,6 +1063,11 @@ public class RmResourceRegistrationServiceImpl implements IRmResourceRegistratio
|
|||||||
updateData.setHardwareSn(rmResourceRegistration.getHardwareSn());
|
updateData.setHardwareSn(rmResourceRegistration.getHardwareSn());
|
||||||
needUpdate = true;
|
needUpdate = true;
|
||||||
}
|
}
|
||||||
|
if(rmResourceRegistration.getOutboundRate()!=null){
|
||||||
|
// 设置出省流量百分比
|
||||||
|
updateData.setOutboundRate(rmResourceRegistration.getOutboundRate());
|
||||||
|
needUpdate = true;
|
||||||
|
}
|
||||||
if(needUpdate){
|
if(needUpdate){
|
||||||
updateData.setId(exits.getId());
|
updateData.setId(exits.getId());
|
||||||
rmResourceRegistrationMapper.updateRmResourceRegistration(updateData);
|
rmResourceRegistrationMapper.updateRmResourceRegistration(updateData);
|
||||||
@@ -1193,6 +1198,14 @@ public class RmResourceRegistrationServiceImpl implements IRmResourceRegistratio
|
|||||||
|
|
||||||
// 注册成功,下发优先级为0的策略
|
// 注册成功,下发优先级为0的策略
|
||||||
remoteRocketMqService.issueDefaultPolicyByClientId(clientId, SecurityConstants.INNER);
|
remoteRocketMqService.issueDefaultPolicyByClientId(clientId, SecurityConstants.INNER);
|
||||||
|
// 下发tcpdump默认策略
|
||||||
|
String detectTimes = "20:00:00";
|
||||||
|
RmTcpdumpConfigRemote tcpdumpInsertData = new RmTcpdumpConfigRemote();
|
||||||
|
tcpdumpInsertData.setClientId(clientId);
|
||||||
|
tcpdumpInsertData.setDetectFlag(1);
|
||||||
|
tcpdumpInsertData.setFrequency("1");
|
||||||
|
tcpdumpInsertData.setDetectTimes(detectTimes);
|
||||||
|
remoteRocketMqService.innerInsertRmTcpdumpConfig(tcpdumpInsertData, SecurityConstants.INNER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+9
-1
@@ -25,13 +25,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<result property="updateBy" column="update_by" />
|
<result property="updateBy" column="update_by" />
|
||||||
<result property="reportedBandwidth" column="reported_bandwidth" />
|
<result property="reportedBandwidth" column="reported_bandwidth" />
|
||||||
<result property="delAlarmTime" column="del_alarm_time" />
|
<result property="delAlarmTime" column="del_alarm_time" />
|
||||||
|
<result property="outboundRate" column="outbound_rate" />
|
||||||
<result property="frpcConnectionStatus" column="frpc_connection_status" />
|
<result property="frpcConnectionStatus" column="frpc_connection_status" />
|
||||||
<result property="frpcRemotePort" column="frpc_remote_port" />
|
<result property="frpcRemotePort" column="frpc_remote_port" />
|
||||||
<result property="frpcServerAddr" column="frpc_server_addr" />
|
<result property="frpcServerAddr" column="frpc_server_addr" />
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<sql id="selectRmResourceRegistrationVo">
|
<sql id="selectRmResourceRegistrationVo">
|
||||||
select id, client_id, hardware_sn, business_name, logical_node_id, multi_public_ip_status, registration_status, online_status, resource_type, agent_version, create_time, update_time, heartbeat_count, heartbeat_interval, onboard_time, remark, create_by, update_by, reported_bandwidth, del_alarm_time from rm_resource_registration
|
select id, client_id, hardware_sn, business_name, logical_node_id, multi_public_ip_status, registration_status, online_status, resource_type, agent_version, create_time, update_time, heartbeat_count, heartbeat_interval, onboard_time, remark, create_by, update_by, reported_bandwidth, del_alarm_time, outbound_rate from rm_resource_registration
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
<select id="selectRmResourceRegistrationList" parameterType="RmResourceRegistration" resultMap="RmResourceRegistrationResult">
|
<select id="selectRmResourceRegistrationList" parameterType="RmResourceRegistration" resultMap="RmResourceRegistrationResult">
|
||||||
@@ -73,6 +74,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
a.remark as remark,
|
a.remark as remark,
|
||||||
a.reported_bandwidth as reportedBandwidth,
|
a.reported_bandwidth as reportedBandwidth,
|
||||||
a.del_alarm_time as delAlarmTime,
|
a.del_alarm_time as delAlarmTime,
|
||||||
|
a.outbound_rate as outboundRate,
|
||||||
b.machine_code as machineCode,
|
b.machine_code as machineCode,
|
||||||
(select bandwidth_result from eps_node_bandwidth
|
(select bandwidth_result from eps_node_bandwidth
|
||||||
where client_id=a.client_id and calculation_mode='1000' and bandwidth_type=1
|
where client_id=a.client_id and calculation_mode='1000' and bandwidth_type=1
|
||||||
@@ -101,6 +103,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
a.remark as remark,
|
a.remark as remark,
|
||||||
a.reported_bandwidth as reportedBandwidth,
|
a.reported_bandwidth as reportedBandwidth,
|
||||||
a.del_alarm_time as delAlarmTime,
|
a.del_alarm_time as delAlarmTime,
|
||||||
|
a.outbound_rate as outboundRate,
|
||||||
b.machine_code as machineCode,
|
b.machine_code as machineCode,
|
||||||
(select bandwidth_result from eps_node_bandwidth
|
(select bandwidth_result from eps_node_bandwidth
|
||||||
where client_id=a.client_id and calculation_mode='1000' and bandwidth_type=1
|
where client_id=a.client_id and calculation_mode='1000' and bandwidth_type=1
|
||||||
@@ -133,6 +136,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<if test="updateBy != null">update_by,</if>
|
<if test="updateBy != null">update_by,</if>
|
||||||
<if test="reportedBandwidth != null">reported_bandwidth,</if>
|
<if test="reportedBandwidth != null">reported_bandwidth,</if>
|
||||||
<if test="delAlarmTime != null">del_alarm_time,</if>
|
<if test="delAlarmTime != null">del_alarm_time,</if>
|
||||||
|
<if test="outboundRate != null">outbound_rate,</if>
|
||||||
</trim>
|
</trim>
|
||||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||||
<if test="clientId != null">#{clientId},</if>
|
<if test="clientId != null">#{clientId},</if>
|
||||||
@@ -154,6 +158,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<if test="updateBy != null">#{updateBy},</if>
|
<if test="updateBy != null">#{updateBy},</if>
|
||||||
<if test="reportedBandwidth != null">#{reportedBandwidth},</if>
|
<if test="reportedBandwidth != null">#{reportedBandwidth},</if>
|
||||||
<if test="delAlarmTime != null">#{delAlarmTime},</if>
|
<if test="delAlarmTime != null">#{delAlarmTime},</if>
|
||||||
|
<if test="outboundRate != null">#{outboundRate},</if>
|
||||||
</trim>
|
</trim>
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
@@ -179,6 +184,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<if test="updateBy != null">update_by = #{updateBy},</if>
|
<if test="updateBy != null">update_by = #{updateBy},</if>
|
||||||
<if test="reportedBandwidth != null">reported_bandwidth = #{reportedBandwidth},</if>
|
<if test="reportedBandwidth != null">reported_bandwidth = #{reportedBandwidth},</if>
|
||||||
<if test="delAlarmTime != null">del_alarm_time = #{delAlarmTime},</if>
|
<if test="delAlarmTime != null">del_alarm_time = #{delAlarmTime},</if>
|
||||||
|
<if test="outboundRate != null">outbound_rate = #{outboundRate},</if>
|
||||||
</trim>
|
</trim>
|
||||||
where id = #{id}
|
where id = #{id}
|
||||||
</update>
|
</update>
|
||||||
@@ -218,6 +224,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<if test="createBy != null">create_by = #{createBy},</if>
|
<if test="createBy != null">create_by = #{createBy},</if>
|
||||||
<if test="updateBy != null">update_by = #{updateBy},</if>
|
<if test="updateBy != null">update_by = #{updateBy},</if>
|
||||||
<if test="reportedBandwidth != null">reported_bandwidth = #{reportedBandwidth},</if>
|
<if test="reportedBandwidth != null">reported_bandwidth = #{reportedBandwidth},</if>
|
||||||
|
<if test="outboundRate != null">outbound_rate = #{outboundRate},</if>
|
||||||
</trim>
|
</trim>
|
||||||
<where>
|
<where>
|
||||||
<choose>
|
<choose>
|
||||||
@@ -271,6 +278,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
a.remark as remark,
|
a.remark as remark,
|
||||||
a.reported_bandwidth as reportedBandwidth,
|
a.reported_bandwidth as reportedBandwidth,
|
||||||
a.del_alarm_time as delAlarmTime,
|
a.del_alarm_time as delAlarmTime,
|
||||||
|
a.outbound_rate as outboundRate,
|
||||||
b.machine_code as machineCode,
|
b.machine_code as machineCode,
|
||||||
c.frpc_connection_status frpcConnectionStatus,
|
c.frpc_connection_status frpcConnectionStatus,
|
||||||
c.frpc_remote_port frpcRemotePort,
|
c.frpc_remote_port frpcRemotePort,
|
||||||
|
|||||||
+18
-1
@@ -4,6 +4,7 @@ import com.tongran.common.core.web.controller.BaseController;
|
|||||||
import com.tongran.common.core.web.domain.AjaxResult;
|
import com.tongran.common.core.web.domain.AjaxResult;
|
||||||
import com.tongran.common.log.annotation.Log;
|
import com.tongran.common.log.annotation.Log;
|
||||||
import com.tongran.common.log.enums.BusinessType;
|
import com.tongran.common.log.enums.BusinessType;
|
||||||
|
import com.tongran.common.security.annotation.InnerAuth;
|
||||||
import com.tongran.common.security.annotation.RequiresPermissions;
|
import com.tongran.common.security.annotation.RequiresPermissions;
|
||||||
import com.tongran.rocketmq.domain.RmTcpdumpConfig;
|
import com.tongran.rocketmq.domain.RmTcpdumpConfig;
|
||||||
import com.tongran.rocketmq.service.IRmTcpdumpConfigService;
|
import com.tongran.rocketmq.service.IRmTcpdumpConfigService;
|
||||||
@@ -55,5 +56,21 @@ public class RmTcpdumpConfigController extends BaseController
|
|||||||
{
|
{
|
||||||
return toAjax(rmTcpdumpConfigService.insertRmTcpdumpConfig(rmTcpdumpConfig));
|
return toAjax(rmTcpdumpConfigService.insertRmTcpdumpConfig(rmTcpdumpConfig));
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 批量新增tcpdump探测策略
|
||||||
|
*/
|
||||||
|
@PostMapping("/batchInsertRmTcpdumpConfig")
|
||||||
|
public AjaxResult batchInsertRmTcpdumpConfig(@RequestBody RmTcpdumpConfig rmTcpdumpConfig)
|
||||||
|
{
|
||||||
|
return toAjax(rmTcpdumpConfigService.batchInsertRmTcpdumpConfig(rmTcpdumpConfig));
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 新增tcpdump探测策略
|
||||||
|
*/
|
||||||
|
@InnerAuth
|
||||||
|
@PostMapping("/innerInsertRmTcpdumpConfig")
|
||||||
|
public AjaxResult innerInsertRmTcpdumpConfig(@RequestBody RmTcpdumpConfig rmTcpdumpConfig)
|
||||||
|
{
|
||||||
|
return toAjax(rmTcpdumpConfigService.insertRmTcpdumpConfig(rmTcpdumpConfig));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,4 +34,6 @@ public class RmTcpdumpConfig extends BaseEntity
|
|||||||
@Excel(name = "探测时间列表(多个时间用,分隔)")
|
@Excel(name = "探测时间列表(多个时间用,分隔)")
|
||||||
private String detectTimes;
|
private String detectTimes;
|
||||||
|
|
||||||
|
private String clientIds;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,11 +21,11 @@ import com.tongran.rocketmq.utils.SendAlarmPushUtil;
|
|||||||
import com.tongran.system.api.RemoteRevenueConfigService;
|
import com.tongran.system.api.RemoteRevenueConfigService;
|
||||||
import com.tongran.system.api.domain.*;
|
import com.tongran.system.api.domain.*;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.http.HttpEntity;
|
|
||||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||||
import org.apache.http.client.methods.HttpGet;
|
import org.apache.http.client.methods.HttpGet;
|
||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
import org.apache.http.impl.client.HttpClients;
|
import org.apache.http.impl.client.HttpClients;
|
||||||
|
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
||||||
import org.apache.http.util.EntityUtils;
|
import org.apache.http.util.EntityUtils;
|
||||||
import org.redisson.api.RLock;
|
import org.redisson.api.RLock;
|
||||||
import org.redisson.api.RedissonClient;
|
import org.redisson.api.RedissonClient;
|
||||||
@@ -40,13 +40,11 @@ import org.springframework.scheduling.annotation.Scheduled;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import java.io.IOException;
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.*;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -58,7 +56,23 @@ import java.util.stream.Collectors;
|
|||||||
@Component
|
@Component
|
||||||
@EnableScheduling
|
@EnableScheduling
|
||||||
public class MessageHandler {
|
public class MessageHandler {
|
||||||
|
// 全局HTTP连接池
|
||||||
|
private static final PoolingHttpClientConnectionManager connectionManager =
|
||||||
|
new PoolingHttpClientConnectionManager();
|
||||||
|
private static final CloseableHttpClient httpClient;
|
||||||
|
|
||||||
|
static {
|
||||||
|
connectionManager.setMaxTotal(100); // 最大连接数
|
||||||
|
connectionManager.setDefaultMaxPerRoute(50); // 每个路由最大连接数
|
||||||
|
httpClient = HttpClients.custom()
|
||||||
|
.setConnectionManager(connectionManager)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
// 使用自定义线程池限制并发数
|
||||||
|
private static final ExecutorService DEVICE_PROCESS_POOL =
|
||||||
|
Executors.newFixedThreadPool(40); // 限制40个并发
|
||||||
|
private static final ExecutorService IP_QUERY_POOL =
|
||||||
|
Executors.newFixedThreadPool(100);
|
||||||
private final Map<String, Consumer<DeviceMessage>> messageHandlers = new HashMap<>();
|
private final Map<String, Consumer<DeviceMessage>> messageHandlers = new HashMap<>();
|
||||||
// 硬盘上报状态
|
// 硬盘上报状态
|
||||||
String DISK_COUNT_PREFIX = "disk:count:";
|
String DISK_COUNT_PREFIX = "disk:count:";
|
||||||
@@ -161,6 +175,10 @@ public class MessageHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void handleTcpdumpResultMessage(DeviceMessage message) {
|
private void handleTcpdumpResultMessage(DeviceMessage message) {
|
||||||
|
// 立即提交到专属线程池
|
||||||
|
DEVICE_PROCESS_POOL.execute(() -> processMessage(message));
|
||||||
|
}
|
||||||
|
private void processMessage(DeviceMessage message){
|
||||||
List<TcpdumpVo> tcpdumpVoList = JsonDataParser.parseJsonData(message.getData(), TcpdumpVo.class);
|
List<TcpdumpVo> tcpdumpVoList = JsonDataParser.parseJsonData(message.getData(), TcpdumpVo.class);
|
||||||
if(tcpdumpVoList != null && !tcpdumpVoList.isEmpty()){
|
if(tcpdumpVoList != null && !tcpdumpVoList.isEmpty()){
|
||||||
String localProvince = "";
|
String localProvince = "";
|
||||||
@@ -196,9 +214,15 @@ public class MessageHandler {
|
|||||||
// 在计算百分比之前,先并行查询所有IP归属地
|
// 在计算百分比之前,先并行查询所有IP归属地
|
||||||
Map<String, Map<String, String>> ipLocationCache = new ConcurrentHashMap<>();
|
Map<String, Map<String, String>> ipLocationCache = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
tcpdumpVoList.parallelStream().forEach(vo -> {
|
List<CompletableFuture<Void>> futures = new ArrayList<>();
|
||||||
ipLocationCache.computeIfAbsent(vo.getIp(), ip -> queryIpLocation(ip));
|
for (TcpdumpVo vo : tcpdumpVoList) {
|
||||||
});
|
CompletableFuture<Void> future = CompletableFuture.runAsync(() -> {
|
||||||
|
ipLocationCache.computeIfAbsent(vo.getIp(), ip -> queryIpLocation(ip));
|
||||||
|
}, IP_QUERY_POOL);
|
||||||
|
futures.add(future);
|
||||||
|
}
|
||||||
|
// 等待所有查询完成
|
||||||
|
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();
|
||||||
// 计算总数量
|
// 计算总数量
|
||||||
Double totalCount = 0.0;
|
Double totalCount = 0.0;
|
||||||
|
|
||||||
@@ -319,6 +343,11 @@ public class MessageHandler {
|
|||||||
}
|
}
|
||||||
// 在更新后的位置插入IPv6总计
|
// 在更新后的位置插入IPv6总计
|
||||||
content.insert(insertPosition, "总占比: " + totalRate + "%\n");
|
content.insert(insertPosition, "总占比: " + totalRate + "%\n");
|
||||||
|
// 添加总占比
|
||||||
|
RmResourceRegistrationRemote updateData = new RmResourceRegistrationRemote();
|
||||||
|
updateData.setClientId(message.getClientId());
|
||||||
|
updateData.setOutboundRate(totalRate);
|
||||||
|
remoteRevenueConfigService.innerUpdateRegist(updateData, SecurityConstants.INNER);
|
||||||
RmOutboundTrafficStatistics insertData = new RmOutboundTrafficStatistics();
|
RmOutboundTrafficStatistics insertData = new RmOutboundTrafficStatistics();
|
||||||
insertData.setClientId(message.getClientId());
|
insertData.setClientId(message.getClientId());
|
||||||
insertData.setDescription(content.toString());
|
insertData.setDescription(content.toString());
|
||||||
@@ -1368,7 +1397,7 @@ public class MessageHandler {
|
|||||||
long currentTime = System.currentTimeMillis();
|
long currentTime = System.currentTimeMillis();
|
||||||
log.debug("开始心跳状态检查,当前时间: {}", currentTime);
|
log.debug("开始心跳状态检查,当前时间: {}", currentTime);
|
||||||
|
|
||||||
// 获取所有客户端时间键
|
// 获取所有客户端时间键0
|
||||||
Set<String> timeKeys = redisTemplate.keys(HEARTBEAT_TIME_PREFIX + "*");
|
Set<String> timeKeys = redisTemplate.keys(HEARTBEAT_TIME_PREFIX + "*");
|
||||||
if (timeKeys == null) {
|
if (timeKeys == null) {
|
||||||
log.debug("未找到任何心跳时间键");
|
log.debug("未找到任何心跳时间键");
|
||||||
@@ -2033,35 +2062,19 @@ public class MessageHandler {
|
|||||||
*/
|
*/
|
||||||
private Map<String, String> queryIpLocation(String ip) {
|
private Map<String, String> queryIpLocation(String ip) {
|
||||||
String apiUrl = "http://172.16.15.103:10000/?ip=" + ip;
|
String apiUrl = "http://172.16.15.103:10000/?ip=" + ip;
|
||||||
CloseableHttpClient httpClient = HttpClients.createDefault();
|
|
||||||
HttpGet httpGet = new HttpGet(apiUrl);
|
HttpGet httpGet = new HttpGet(apiUrl);
|
||||||
|
|
||||||
try {
|
try (CloseableHttpResponse response = httpClient.execute(httpGet)) {
|
||||||
CloseableHttpResponse response = httpClient.execute(httpGet);
|
|
||||||
|
|
||||||
if (response.getStatusLine().getStatusCode() == 200) {
|
if (response.getStatusLine().getStatusCode() == 200) {
|
||||||
HttpEntity entity = response.getEntity();
|
String jsonResponse = EntityUtils.toString(response.getEntity(), "UTF-8");
|
||||||
if (entity != null) {
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
String jsonResponse = EntityUtils.toString(entity, "UTF-8");
|
Map<String, Object> resultMap = mapper.readValue(jsonResponse,
|
||||||
|
new TypeReference<Map<String, Object>>() {});
|
||||||
// 使用Jackson解析JSON
|
return extractLocationInfo(resultMap);
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
|
||||||
Map<String, Object> resultMap = mapper.readValue(jsonResponse, new TypeReference<Map<String, Object>>() {});
|
|
||||||
|
|
||||||
return extractLocationInfo(resultMap);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
System.err.println("获取IP归属地信息失败,HTTP状态码: " + response.getStatusLine().getStatusCode());
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("查询IP归属地时发生异常: " + e.getMessage());
|
System.err.println("查询IP归属地时发生异常: " + e.getMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
httpClient.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
+2
@@ -61,4 +61,6 @@ public interface IRmTcpdumpConfigService
|
|||||||
public int deleteRmTcpdumpConfigById(Long id);
|
public int deleteRmTcpdumpConfigById(Long id);
|
||||||
|
|
||||||
RmTcpdumpConfig selectRmTcpdumpConfigByClientId(String clientId);
|
RmTcpdumpConfig selectRmTcpdumpConfigByClientId(String clientId);
|
||||||
|
|
||||||
|
int batchInsertRmTcpdumpConfig(RmTcpdumpConfig rmTcpdumpConfig);
|
||||||
}
|
}
|
||||||
|
|||||||
+33
@@ -129,4 +129,37 @@ public class RmTcpdumpConfigServiceImpl implements IRmTcpdumpConfigService
|
|||||||
public RmTcpdumpConfig selectRmTcpdumpConfigByClientId(String clientId) {
|
public RmTcpdumpConfig selectRmTcpdumpConfigByClientId(String clientId) {
|
||||||
return rmTcpdumpConfigMapper.selectRmTcpdumpConfigByClientId(clientId);
|
return rmTcpdumpConfigMapper.selectRmTcpdumpConfigByClientId(clientId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int batchInsertRmTcpdumpConfig(RmTcpdumpConfig rmTcpdumpConfig)
|
||||||
|
{
|
||||||
|
String clientIds = rmTcpdumpConfig.getClientIds();
|
||||||
|
String[] clientIdArr = clientIds.split(",");
|
||||||
|
for (String clientId : clientIdArr) {
|
||||||
|
rmTcpdumpConfig.setClientId(clientId);
|
||||||
|
rmTcpdumpConfig.setCreateTime(DateUtils.getNowDate());
|
||||||
|
rmTcpdumpConfigMapper.insertRmTcpdumpConfig(rmTcpdumpConfig);
|
||||||
|
// 下发消息给agent
|
||||||
|
PolicyTypeVo policyTypeVo = new PolicyTypeVo();
|
||||||
|
RmTcpdumpVo rmTcpdumpVo = new RmTcpdumpVo();
|
||||||
|
rmTcpdumpVo.setDetectFlag(rmTcpdumpConfig.getDetectFlag());
|
||||||
|
rmTcpdumpVo.setFrequency(rmTcpdumpConfig.getFrequency());
|
||||||
|
rmTcpdumpVo.setDetectTimes(rmTcpdumpConfig.getDetectTimes()==null?"":rmTcpdumpConfig.getDetectTimes());
|
||||||
|
policyTypeVo.setTcpdumpTimes(JSONObject.toJSONString(rmTcpdumpVo));
|
||||||
|
MessageProducer messageProducer = new MessageProducer();
|
||||||
|
String configJson = JSONObject.toJSONString(policyTypeVo);
|
||||||
|
DeviceMessage message = new DeviceMessage();
|
||||||
|
message.setClientId(rmTcpdumpConfig.getClientId());
|
||||||
|
message.setData(configJson);
|
||||||
|
message.setDataType(MsgEnum.获取最新策略应答.getValue());
|
||||||
|
|
||||||
|
messageProducer.sendAsyncProducerMessage(
|
||||||
|
producerMode.getAgentTopic(),
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
JSONObject.toJSONString(message)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user