Commit dbd8519e by HlQ

[add]

1.服务监测增加 reqHeaders、reqBody、resBody 字段
2.mqtt server 地址由服务端下发
3.关注项目接口添加指标查询参数
4.添加查看关注 account 的接口
1 parent a21d76bc
...@@ -27,6 +27,13 @@ public class MallController { ...@@ -27,6 +27,13 @@ public class MallController {
return mallService.listAccount(dto); return mallService.listAccount(dto);
} }
@GetMapping("/attention/account")
@SaCheckPermission(value = "mall:attention:account:list", orRole = "admin")
// todo 权限为加
public Page<MAccount> listAttentionAccount(MAccount dto) {
return mallService.listAttentionAccount(dto);
}
@GetMapping @GetMapping
@SaCheckPermission(value = "mall:list", orRole = "admin") @SaCheckPermission(value = "mall:list", orRole = "admin")
public Page<MallVO> list(MallDTO dto) { public Page<MallVO> list(MallDTO dto) {
......
...@@ -4,6 +4,8 @@ import lombok.Getter; ...@@ -4,6 +4,8 @@ import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import vion.dto.BaseDTO; import vion.dto.BaseDTO;
import java.util.List;
/** /**
* 项目mall信息 * 项目mall信息
*/ */
...@@ -48,4 +50,9 @@ public class MallDTO extends BaseDTO { ...@@ -48,4 +50,9 @@ public class MallDTO extends BaseDTO {
*/ */
private Short attention; private Short attention;
/**
* 指标列表
*/
private List<String> eventUidList;
} }
\ No newline at end of file \ No newline at end of file
...@@ -3,6 +3,7 @@ package vion.model.monitor; ...@@ -3,6 +3,7 @@ package vion.model.monitor;
import com.baomidou.mybatisplus.annotation.*; import com.baomidou.mybatisplus.annotation.*;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import vion.config.mp.JsonbTypeHandler;
import java.time.LocalDateTime; import java.time.LocalDateTime;
...@@ -11,7 +12,7 @@ import java.time.LocalDateTime; ...@@ -11,7 +12,7 @@ import java.time.LocalDateTime;
*/ */
@Getter @Getter
@Setter @Setter
@TableName(value = "mr_agent_service") @TableName(value = "mr_agent_service", autoResultMap = true)
public class RAgentService { public class RAgentService {
@TableId(value = "id", type = IdType.AUTO) @TableId(value = "id", type = IdType.AUTO)
...@@ -36,6 +37,24 @@ public class RAgentService { ...@@ -36,6 +37,24 @@ public class RAgentService {
private String method; private String method;
/** /**
* 请求头
*/
@TableField(value = "req_headers", typeHandler = JsonbTypeHandler.class)
private Object reqHeaders;
/**
* 请求体
*/
@TableField(value = "req_body", typeHandler = JsonbTypeHandler.class)
private Object reqBody;
/**
* 响应结果(包含)
*/
@TableField(value = "res_body")
private String resBody;
/**
* 用户名 * 用户名
*/ */
@TableField(value = "username") @TableField(value = "username")
......
...@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.*; ...@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import vion.config.mp.JsonbTypeHandler;
import vion.dto.BaseDTO; import vion.dto.BaseDTO;
import java.time.LocalDateTime; import java.time.LocalDateTime;
...@@ -13,7 +14,7 @@ import java.time.LocalDateTime; ...@@ -13,7 +14,7 @@ import java.time.LocalDateTime;
*/ */
@Getter @Getter
@Setter @Setter
@TableName(value = "m_service") @TableName(value = "m_service", autoResultMap = true)
@JsonInclude(JsonInclude.Include.NON_NULL) @JsonInclude(JsonInclude.Include.NON_NULL)
public class ServiceInfo extends BaseDTO { public class ServiceInfo extends BaseDTO {
@TableId(value = "id", type = IdType.AUTO) @TableId(value = "id", type = IdType.AUTO)
...@@ -44,6 +45,24 @@ public class ServiceInfo extends BaseDTO { ...@@ -44,6 +45,24 @@ public class ServiceInfo extends BaseDTO {
private String method; private String method;
/** /**
* 请求头
*/
@TableField(value = "req_headers", typeHandler = JsonbTypeHandler.class)
private Object reqHeaders;
/**
* 请求体
*/
@TableField(value = "req_body", typeHandler = JsonbTypeHandler.class)
private Object reqBody;
/**
* 响应结果(包含)
*/
@TableField(value = "res_body")
private String resBody;
/**
* 监控类型:HTTP(s) * 监控类型:HTTP(s)
*/ */
@TableField(value = "\"type\"") @TableField(value = "\"type\"")
......
...@@ -41,10 +41,16 @@ public class ServiceRecord { ...@@ -41,10 +41,16 @@ public class ServiceRecord {
private Integer status; private Integer status;
/** /**
* 响应结果的code
*/
@TableField(value = "body_code")
private Integer bodyCode;
/**
* 响应结果的状态 * 响应结果的状态
*/ */
@TableField(value = "body_status") @TableField(value = "body_status")
private Integer bodyStatus; private Boolean bodyStatus;
/** /**
* 监测时间 * 监测时间
......
...@@ -57,7 +57,9 @@ public class AgentServiceImpl extends MPJBaseServiceImpl<AgentMapper, Agent> imp ...@@ -57,7 +57,9 @@ public class AgentServiceImpl extends MPJBaseServiceImpl<AgentMapper, Agent> imp
private final MqttClientTemplate client; private final MqttClientTemplate client;
private final IMAccountService accountService; private final IMAccountService accountService;
private final IMallService mallService; private final IMallService mallService;
@Value(value = "${mqtt.client.server-topic:/MS/receive}") @Value("${mqtt.client.ext.ip}")
private String extIp;
@Value("${mqtt.client.server-topic:/MS/receive}")
private String serverTopic; private String serverTopic;
@Override @Override
...@@ -88,6 +90,9 @@ public class AgentServiceImpl extends MPJBaseServiceImpl<AgentMapper, Agent> imp ...@@ -88,6 +90,9 @@ public class AgentServiceImpl extends MPJBaseServiceImpl<AgentMapper, Agent> imp
var serviceRecordList = serviceRecordService.selectJoinList(ServiceRecord.class, serviceRecordWrapper); var serviceRecordList = serviceRecordService.selectJoinList(ServiceRecord.class, serviceRecordWrapper);
var agentUid2ServiceRecMap = serviceRecordList.stream().collect(Collectors.groupingBy(ServiceRecord::getAgentUid)); var agentUid2ServiceRecMap = serviceRecordList.stream().collect(Collectors.groupingBy(ServiceRecord::getAgentUid));
// httpStatus 不等于200
// 或者响应时间 > 1000ms
// 或者(响应结果 body 里的 code 不等于200或 body 不包含指定字符串)显示异常服务名字
var errorNameMap = agentUid2ServiceRecMap var errorNameMap = agentUid2ServiceRecMap
.entrySet() .entrySet()
.stream() .stream()
...@@ -95,8 +100,8 @@ public class AgentServiceImpl extends MPJBaseServiceImpl<AgentMapper, Agent> imp ...@@ -95,8 +100,8 @@ public class AgentServiceImpl extends MPJBaseServiceImpl<AgentMapper, Agent> imp
Map.Entry::getKey, Map.Entry::getKey,
entry -> entry.getValue().stream() entry -> entry.getValue().stream()
.map(rec -> (rec.getStatus() != 200 .map(rec -> (rec.getStatus() != 200
|| rec.getBodyStatus() != 200 || rec.getResponseTime() > 1000L
|| rec.getResponseTime() > 1000L) ? rec.getName() : "success") || (rec.getBodyCode() != 200 || rec.getBodyStatus())) ? rec.getName() : "success")
.distinct() .distinct()
.filter(StrUtil::isNotBlank) .filter(StrUtil::isNotBlank)
.collect(Collectors.joining(",")) .collect(Collectors.joining(","))
...@@ -300,6 +305,8 @@ public class AgentServiceImpl extends MPJBaseServiceImpl<AgentMapper, Agent> imp ...@@ -300,6 +305,8 @@ public class AgentServiceImpl extends MPJBaseServiceImpl<AgentMapper, Agent> imp
var serviceList = serviceInfoService.selectJoinList(ServiceInfo.class, wrapper); var serviceList = serviceInfoService.selectJoinList(ServiceInfo.class, wrapper);
return JsonUtil.createObj() return JsonUtil.createObj()
.put("ip", extIp)
.put("port", 1883)
.put("clientid", agent.getUid()) .put("clientid", agent.getUid())
.put("username", agent.getUsername()) .put("username", agent.getUsername())
.put("password", agent.getPassword()) .put("password", agent.getPassword())
......
...@@ -50,6 +50,15 @@ public class MallServiceImpl extends MPJBaseServiceImpl<MallMapper, Mall> implem ...@@ -50,6 +50,15 @@ public class MallServiceImpl extends MPJBaseServiceImpl<MallMapper, Mall> implem
} }
@Override @Override
public Page<MAccount> listAttentionAccount(MAccount dto) {
var attentionMallList = this.query().select("distinct account_uid").eq("attention", 1).list();
return accountService.lambdaQuery()
.in(MAccount::getUid, attentionMallList.stream().map(Mall::getAccountUid).toList())
.orderByAsc(MAccount::getName)
.page(Page.of(dto.getPageNum(), dto.getPageSize()));
}
@Override
public Page<MallVO> list(MallDTO dto) { public Page<MallVO> list(MallDTO dto) {
Assert.notNull(dto.getAgentType(), "agentType 不能为空"); Assert.notNull(dto.getAgentType(), "agentType 不能为空");
var wrapper = new MPJLambdaWrapper<>(converter.convert(dto, Mall.class)) var wrapper = new MPJLambdaWrapper<>(converter.convert(dto, Mall.class))
...@@ -109,6 +118,7 @@ public class MallServiceImpl extends MPJBaseServiceImpl<MallMapper, Mall> implem ...@@ -109,6 +118,7 @@ public class MallServiceImpl extends MPJBaseServiceImpl<MallMapper, Mall> implem
var eventRecWrapper = Wrappers.<EventRecord>query() var eventRecWrapper = Wrappers.<EventRecord>query()
.select("DISTINCT on (mall_uid,event_type) *") .select("DISTINCT on (mall_uid,event_type) *")
.eq("agent_type", dto.getAgentType()) .eq("agent_type", dto.getAgentType())
.in(CollUtil.isNotEmpty(dto.getEventUidList()), "event_uid", dto.getEventUidList())
.orderByDesc("mall_uid", "event_type", "create_time"); .orderByDesc("mall_uid", "event_type", "create_time");
var eventRecordList = eventRecordService.list(eventRecWrapper); var eventRecordList = eventRecordService.list(eventRecWrapper);
var mallUidList = eventRecordList.stream().filter(r -> r.getStatus() != 1).map(EventRecord::getMallUid).toList(); var mallUidList = eventRecordList.stream().filter(r -> r.getStatus() != 1).map(EventRecord::getMallUid).toList();
......
...@@ -17,6 +17,8 @@ public interface IMallService extends MPJBaseService<Mall> { ...@@ -17,6 +17,8 @@ public interface IMallService extends MPJBaseService<Mall> {
Page<MAccount> listAccount(MAccount dto); Page<MAccount> listAccount(MAccount dto);
Page<MAccount> listAttentionAccount(MAccount dto);
Page<MallVO> list(MallDTO dto); Page<MallVO> list(MallDTO dto);
MallVO get(Long id); MallVO get(Long id);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!