服务器管理添加标签功能。
优化mtr探测结果存储。
This commit is contained in:
+4
-4
@@ -114,13 +114,13 @@ public class RmMtrClientRegistrationController extends BaseController
|
||||
return success(list);
|
||||
}
|
||||
/**
|
||||
* 查询MTR客户端注册列表
|
||||
* 查询所有标识
|
||||
*/
|
||||
@RequiresPermissions("mtragent:mtrClientRegistration:list")
|
||||
@PostMapping("/getAllLogicalNode")
|
||||
public AjaxResult getAllLogicalNode(@RequestBody RmMtrClientRegistration rmMtrClientRegistration)
|
||||
@GetMapping("/getAllLogicalNode")
|
||||
public AjaxResult getAllLogicalNode()
|
||||
{
|
||||
List<RmMtrClientRegistration> list = rmMtrClientRegistrationService.getAllLogicalNode(rmMtrClientRegistration);
|
||||
List<RmMtrClientRegistration> list = rmMtrClientRegistrationService.getAllLogicalNode();
|
||||
return success(list);
|
||||
}
|
||||
/**
|
||||
|
||||
+4
-55
@@ -1,9 +1,8 @@
|
||||
package com.tongran.mtragent.domain;
|
||||
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
import com.tongran.common.core.annotation.Excel;
|
||||
import com.tongran.common.core.web.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* mtr探测丢包clinetId记录对象 all_mtr_client
|
||||
@@ -11,6 +10,7 @@ import com.tongran.common.core.web.domain.BaseEntity;
|
||||
* @author gyt
|
||||
* @date 2025-11-24
|
||||
*/
|
||||
@Data
|
||||
public class AllMtrClient extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
@@ -29,58 +29,7 @@ public class AllMtrClient extends BaseEntity
|
||||
/** 公网IP地址 */
|
||||
@Excel(name = "公网IP地址")
|
||||
private String publicIp;
|
||||
/** 失败标志 0成功 1失败 */
|
||||
private Integer failFlag;
|
||||
|
||||
public void setId(Long id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Long getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setMtrClientId(String mtrClientId)
|
||||
{
|
||||
this.mtrClientId = mtrClientId;
|
||||
}
|
||||
|
||||
public String getMtrClientId()
|
||||
{
|
||||
return mtrClientId;
|
||||
}
|
||||
|
||||
public void setClientId(String clientId)
|
||||
{
|
||||
this.clientId = clientId;
|
||||
}
|
||||
|
||||
public String getClientId()
|
||||
{
|
||||
return clientId;
|
||||
}
|
||||
|
||||
public void setPublicIp(String publicIp)
|
||||
{
|
||||
this.publicIp = publicIp;
|
||||
}
|
||||
|
||||
public String getPublicIp()
|
||||
{
|
||||
return publicIp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||
.append("id", getId())
|
||||
.append("mtrClientId", getMtrClientId())
|
||||
.append("clientId", getClientId())
|
||||
.append("publicIp", getPublicIp())
|
||||
.append("createTime", getCreateTime())
|
||||
.append("updateTime", getUpdateTime())
|
||||
.append("createBy", getCreateBy())
|
||||
.append("updateBy", getUpdateBy())
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
|
||||
+2
@@ -89,4 +89,6 @@ public class RmMtrClientRegistration extends BaseEntity
|
||||
private String networkInfo;
|
||||
/** 部署设备 */
|
||||
private String mtrClientIds;
|
||||
/** 多条件 */
|
||||
private String queryName;
|
||||
}
|
||||
|
||||
+21
-16
@@ -93,27 +93,32 @@ public class MessageHandler {
|
||||
List<RmMtrProbeResult> rmMtrProbeResultList = new ArrayList<>();
|
||||
List<AllMtrClient> allMtrClientList = new ArrayList<>();
|
||||
for (MtrResultVo mtrResultVo : mtrResultVoList) {
|
||||
if(mtrResultVo.getFinalLossPercent() != -1.0){
|
||||
// 时间戳转换
|
||||
long timestamp = mtrResultVo.getTimestamp();
|
||||
long millis = timestamp * 1000;
|
||||
Date createTime = new Date(millis / 1000 * 1000); // 去除毫秒
|
||||
RmMtrProbeResult rmMtrProbeResult = new RmMtrProbeResult();
|
||||
rmMtrProbeResult.setCreateTime(createTime);
|
||||
rmMtrProbeResult.setClientId(mtrResultVo.getClientId());
|
||||
rmMtrProbeResult.setMtrClientId(mtrClientId);
|
||||
rmMtrProbeResult.setPublicIp(mtrResultVo.getTargetIp());
|
||||
rmMtrProbeResult.setPacketLossRate(new BigDecimal(mtrResultVo.getFinalLossPercent()));
|
||||
rmMtrProbeResultList.add(rmMtrProbeResult);
|
||||
AllMtrClient allMtrClient = new AllMtrClient();
|
||||
BeanUtils.copyProperties(rmMtrProbeResult, allMtrClient);
|
||||
allMtrClientList.add(allMtrClient);
|
||||
// 时间戳转换
|
||||
long timestamp = mtrResultVo.getTimestamp();
|
||||
long millis = timestamp * 1000;
|
||||
Date createTime = new Date(millis / 1000 * 1000); // 去除毫秒
|
||||
RmMtrProbeResult rmMtrProbeResult = new RmMtrProbeResult();
|
||||
rmMtrProbeResult.setCreateTime(createTime);
|
||||
rmMtrProbeResult.setClientId(mtrResultVo.getClientId());
|
||||
rmMtrProbeResult.setMtrClientId(mtrClientId);
|
||||
rmMtrProbeResult.setPublicIp(mtrResultVo.getTargetIp());
|
||||
rmMtrProbeResult.setPacketLossRate(new BigDecimal(mtrResultVo.getFinalLossPercent()));
|
||||
rmMtrProbeResultList.add(rmMtrProbeResult);
|
||||
AllMtrClient allMtrClient = new AllMtrClient();
|
||||
BeanUtils.copyProperties(rmMtrProbeResult, allMtrClient);
|
||||
if(mtrResultVo.getFinalLossPercent() == -1.0){
|
||||
allMtrClient.setFailFlag(1);
|
||||
}else{
|
||||
log.debug("探测失败,失败原因:{}", mtrResultVo.getErrorMsg());
|
||||
allMtrClient.setFailFlag(0);
|
||||
}
|
||||
allMtrClientList.add(allMtrClient);
|
||||
}
|
||||
RmMtrProbeResult insertData = new RmMtrProbeResult();
|
||||
insertData.setList(rmMtrProbeResultList);
|
||||
if(rmMtrProbeResultList.isEmpty()){
|
||||
log.warn("探测失败,原因可能为mtr命令没安装");
|
||||
return;
|
||||
}
|
||||
// 结果批量入库
|
||||
rmMtrProbeResultService.batchInsertRmMtrProbeResult(insertData);
|
||||
// 记录下发策略的clientId
|
||||
|
||||
+1
-2
@@ -70,10 +70,9 @@ public interface IRmMtrClientRegistrationService
|
||||
|
||||
/**
|
||||
* 获取所有标识
|
||||
* @param rmMtrClientRegistration
|
||||
* @return
|
||||
*/
|
||||
List<RmMtrClientRegistration> getAllLogicalNode(RmMtrClientRegistration rmMtrClientRegistration);
|
||||
List<RmMtrClientRegistration> getAllLogicalNode();
|
||||
/**
|
||||
* 根据mtrClientId查询包含的clientId
|
||||
* @param rmMtrClientRegistration
|
||||
|
||||
+2
-2
@@ -215,8 +215,8 @@ public class RmMtrClientRegistrationServiceImpl implements IRmMtrClientRegistrat
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<RmMtrClientRegistration> getAllLogicalNode(RmMtrClientRegistration rmMtrClientRegistration) {
|
||||
List<RmMtrClientRegistration> list = rmMtrClientRegistrationMapper.getAllLogicalNode(rmMtrClientRegistration);
|
||||
public List<RmMtrClientRegistration> getAllLogicalNode() {
|
||||
List<RmMtrClientRegistration> list = rmMtrClientRegistrationMapper.getAllLogicalNode(new RmMtrClientRegistration());
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,8 +23,8 @@ spring:
|
||||
# 配置中心地址
|
||||
server-addr: 172.16.15.52:8848
|
||||
# server-addr: 172.16.15.103:8848
|
||||
namespace: public
|
||||
# namespace: saas-local
|
||||
# namespace: public
|
||||
namespace: saas-local
|
||||
username: nacos
|
||||
password: nacos
|
||||
# 配置文件格式
|
||||
|
||||
+15
-9
@@ -3,12 +3,13 @@
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.tongran.mtragent.mapper.AllMtrClientMapper">
|
||||
|
||||
|
||||
<resultMap type="AllMtrClient" id="AllMtrClientResult">
|
||||
<result property="id" column="id" />
|
||||
<result property="mtrClientId" column="mtr_client_id" />
|
||||
<result property="clientId" column="client_id" />
|
||||
<result property="publicIp" column="public_ip" />
|
||||
<result property="failFlag" column="fail_flag" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
<result property="createBy" column="create_by" />
|
||||
@@ -16,18 +17,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectAllMtrClientVo">
|
||||
select id, mtr_client_id, client_id, public_ip, create_time, update_time, create_by, update_by from all_mtr_client
|
||||
select id, mtr_client_id, client_id, public_ip, fail_flag, create_time, update_time, create_by, update_by from all_mtr_client
|
||||
</sql>
|
||||
|
||||
<select id="selectAllMtrClientList" parameterType="AllMtrClient" resultMap="AllMtrClientResult">
|
||||
<include refid="selectAllMtrClientVo"/>
|
||||
<where>
|
||||
<where>
|
||||
<if test="mtrClientId != null and mtrClientId != ''"> and mtr_client_id = #{mtrClientId}</if>
|
||||
<if test="clientId != null and clientId != ''"> and client_id = #{clientId}</if>
|
||||
<if test="publicIp != null and publicIp != ''"> and public_ip = #{publicIp}</if>
|
||||
<if test="failFlag != null "> and fail_flag = #{failFlag}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
|
||||
<select id="selectAllMtrClientById" parameterType="Long" resultMap="AllMtrClientResult">
|
||||
<include refid="selectAllMtrClientVo"/>
|
||||
where id = #{id}
|
||||
@@ -39,20 +41,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="mtrClientId != null and mtrClientId != ''">mtr_client_id,</if>
|
||||
<if test="clientId != null and clientId != ''">client_id,</if>
|
||||
<if test="publicIp != null and publicIp != ''">public_ip,</if>
|
||||
<if test="failFlag != null">fail_flag,</if>
|
||||
<if test="createTime != null">create_time,</if>
|
||||
<if test="updateTime != null">update_time,</if>
|
||||
<if test="createBy != null">create_by,</if>
|
||||
<if test="updateBy != null">update_by,</if>
|
||||
</trim>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="mtrClientId != null and mtrClientId != ''">#{mtrClientId},</if>
|
||||
<if test="clientId != null and clientId != ''">#{clientId},</if>
|
||||
<if test="publicIp != null and publicIp != ''">#{publicIp},</if>
|
||||
<if test="failFlag != null">#{failFlag},</if>
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
<if test="updateTime != null">#{updateTime},</if>
|
||||
<if test="createBy != null">#{createBy},</if>
|
||||
<if test="updateBy != null">#{updateBy},</if>
|
||||
</trim>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateAllMtrClient" parameterType="AllMtrClient">
|
||||
@@ -61,6 +65,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="mtrClientId != null and mtrClientId != ''">mtr_client_id = #{mtrClientId},</if>
|
||||
<if test="clientId != null and clientId != ''">client_id = #{clientId},</if>
|
||||
<if test="publicIp != null and publicIp != ''">public_ip = #{publicIp},</if>
|
||||
<if test="failFlag != null">fail_flag = #{failFlag},</if>
|
||||
<if test="createTime != null">create_time = #{createTime},</if>
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
<if test="createBy != null">create_by = #{createBy},</if>
|
||||
@@ -81,12 +86,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</delete>
|
||||
<insert id="batchInsertAllMtrClient" parameterType="java.util.List">
|
||||
insert into all_mtr_client
|
||||
(mtr_client_id, client_id, public_ip, create_by, update_by)
|
||||
(mtr_client_id, client_id, public_ip, fail_flag, create_by, update_by)
|
||||
values
|
||||
<foreach collection="list" item="item" separator=",">
|
||||
(#{item.mtrClientId}, #{item.clientId}, #{item.publicIp}, #{item.createBy}, #{item.updateBy})
|
||||
(#{item.mtrClientId}, #{item.clientId}, #{item.publicIp}, #{item.failFlag}, #{item.createBy}, #{item.updateBy})
|
||||
</foreach>
|
||||
ON DUPLICATE KEY UPDATE
|
||||
public_ip = IF(VALUES(public_ip) != public_ip, VALUES(public_ip), public_ip)
|
||||
public_ip = IF(NOT VALUES(public_ip) <=> public_ip, VALUES(public_ip), public_ip),
|
||||
fail_flag = IF(NOT VALUES(fail_flag) <=> fail_flag, VALUES(fail_flag), fail_flag)
|
||||
</insert>
|
||||
</mapper>
|
||||
+10
@@ -51,6 +51,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="lastUpdateResult != null and lastUpdateResult != ''"> and last_update_result = #{lastUpdateResult}</if>
|
||||
<if test="lastUpdateTime != null "> and last_update_time = #{lastUpdateTime}</if>
|
||||
<if test="networkInfo != null and networkInfo != ''"> and network_info = #{networkInfo}</if>
|
||||
<!-- 新增:多条件查询,queryName可能是mtr_client_id或关联表的client_id -->
|
||||
<if test="queryName != null and queryName != ''">
|
||||
and (
|
||||
mtr_client_id like concat('%',#{queryName},'%')
|
||||
or mtr_client_id in (
|
||||
select distinct mtr_client_id from all_mtr_client
|
||||
where client_id like concat('%',#{queryName},'%')
|
||||
)
|
||||
)
|
||||
</if>
|
||||
</where>
|
||||
order by create_time desc
|
||||
</select>
|
||||
|
||||
+1
-1
@@ -85,7 +85,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</foreach>
|
||||
</delete>
|
||||
<insert id="batchInsertRmMtrProbeResult" parameterType="RmMtrProbeResult">
|
||||
INSERT INTO ${tableName}
|
||||
INSERT IGNORE INTO ${tableName}
|
||||
(
|
||||
mtr_client_id,
|
||||
client_id,
|
||||
|
||||
Reference in New Issue
Block a user