Merge remote-tracking branch 'origin/dev' into dev
# Conflicts: # sql/init-4-data.sql
This commit is contained in:
@@ -312,6 +312,19 @@ public class RedisMaps extends RedisUtils {
|
||||
return getJson(key.getKey(), hashKey, (Class<V>) key.getType());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取值 json
|
||||
*
|
||||
* @param define define
|
||||
* @param key key
|
||||
* @param hashKey hashKey
|
||||
* @param <V> V
|
||||
* @return value
|
||||
*/
|
||||
public static <V> V getJson(String key, CacheKeyDefine define, Object hashKey) {
|
||||
return getJson(key, hashKey, (Class<V>) define.getType());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取值 json
|
||||
*
|
||||
@@ -355,9 +368,9 @@ public class RedisMaps extends RedisUtils {
|
||||
/**
|
||||
* 获取值 json
|
||||
*
|
||||
* @param key key
|
||||
* @param hashKeys hashKeys
|
||||
* @param <V> V
|
||||
* @param key key
|
||||
* @param hashKeys hashKeys
|
||||
* @param <V> V
|
||||
* @return values
|
||||
*/
|
||||
public static <V> List<V> multiGetJson(CacheKeyDefine key, List<?> hashKeys) {
|
||||
@@ -367,10 +380,10 @@ public class RedisMaps extends RedisUtils {
|
||||
/**
|
||||
* 获取值 json
|
||||
*
|
||||
* @param key key
|
||||
* @param hashKeys hashKeys
|
||||
* @param clazz clazz
|
||||
* @param <V> V
|
||||
* @param key key
|
||||
* @param hashKeys hashKeys
|
||||
* @param clazz clazz
|
||||
* @param <V> V
|
||||
* @return values
|
||||
*/
|
||||
public static <V> List<V> multiGetJson(String key, List<?> hashKeys, Class<V> clazz) {
|
||||
|
||||
@@ -48,10 +48,10 @@ public interface HostAgentApi {
|
||||
/**
|
||||
* 获取缓存名称
|
||||
*
|
||||
* @param agentKeyList agentKeyList
|
||||
* @param agentKeys agentKeys
|
||||
* @return nameMap
|
||||
*/
|
||||
Map<String, String> getNameCacheByAgentKey(List<String> agentKeyList);
|
||||
Map<String, String> getNameCacheByAgentKey(List<String> agentKeys);
|
||||
|
||||
/**
|
||||
* 获取缓存名称
|
||||
|
||||
@@ -103,11 +103,11 @@ public class HostAgentApiImpl implements HostAgentApi {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getNameCacheByAgentKey(List<String> agentKeyList) {
|
||||
public Map<String, String> getNameCacheByAgentKey(List<String> agentKeys) {
|
||||
Map<String, String> result = new HashMap<>();
|
||||
List<String> queryList = new ArrayList<>();
|
||||
// 查询缓存
|
||||
for (String agentKey : agentKeyList) {
|
||||
for (String agentKey : agentKeys) {
|
||||
HostBaseDTO host = AGENT_HOST_CACHE.get(agentKey);
|
||||
if (host != null) {
|
||||
result.put(agentKey, host.getName());
|
||||
|
||||
@@ -92,14 +92,14 @@ public interface HostDAO extends IMapper<HostDO> {
|
||||
/**
|
||||
* 更新探针信息
|
||||
*
|
||||
* @param keys agentKeyList
|
||||
* @param update update
|
||||
* @param agentKeys agentKeys
|
||||
* @param update update
|
||||
* @return effect
|
||||
*/
|
||||
default int updateByAgentKeys(List<String> keys, HostDO update) {
|
||||
default int updateByAgentKeys(List<String> agentKeys, HostDO update) {
|
||||
update.setUpdateTime(new Date());
|
||||
// 更新
|
||||
return this.update(update, Conditions.in(HostDO::getAgentKey, keys));
|
||||
return this.update(update, Conditions.in(HostDO::getAgentKey, agentKeys));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -212,25 +212,25 @@ public class HostAgentEndpointServiceImpl implements HostAgentEndpointService {
|
||||
/**
|
||||
* 标记在线状态
|
||||
*
|
||||
* @param agentKeyList agentKeyList
|
||||
* @param status status
|
||||
* @param agentKeys agentKeys
|
||||
* @param status status
|
||||
*/
|
||||
private void markOnlineStatus(List<String> agentKeyList, AgentOnlineStatusEnum status) {
|
||||
if (Lists.isEmpty(agentKeyList)) {
|
||||
private void markOnlineStatus(List<String> agentKeys, AgentOnlineStatusEnum status) {
|
||||
if (Lists.isEmpty(agentKeys)) {
|
||||
return;
|
||||
}
|
||||
log.info("HostAgentEndpointService mark {}. count: {}, keys: {}", status, agentKeyList.size(), agentKeyList);
|
||||
log.info("HostAgentEndpointService mark {}. count: {}, keys: {}", status, agentKeys.size(), agentKeys);
|
||||
// 更新数据
|
||||
HostDO update = HostDO.builder()
|
||||
.agentOnlineStatus(status.getValue())
|
||||
.agentOnlineChangeTime(new Date())
|
||||
.build();
|
||||
int effect = hostDAO.updateByAgentKeys(agentKeyList, update);
|
||||
int effect = hostDAO.updateByAgentKeys(agentKeys, update);
|
||||
// 更新缓存
|
||||
agentKeyList.forEach(s -> ONLINE_STATUS_CACHE.put(s, status.getValue()));
|
||||
agentKeys.forEach(s -> ONLINE_STATUS_CACHE.put(s, status.getValue()));
|
||||
log.info("HostAgentEndpointService mark {}. effect: {}", status, effect);
|
||||
// 插入日志
|
||||
List<HostAgentLogDO> logList = hostDAO.selectIdByAgentKeys(agentKeyList)
|
||||
List<HostAgentLogDO> logList = hostDAO.selectIdByAgentKeys(agentKeys)
|
||||
.stream()
|
||||
.map(s -> {
|
||||
HostAgentLogDO agentLog = HostAgentLogDO.builder()
|
||||
@@ -250,7 +250,7 @@ public class HostAgentEndpointServiceImpl implements HostAgentEndpointService {
|
||||
}
|
||||
// 发送已下线事件
|
||||
if (AgentOnlineStatusEnum.OFFLINE.equals(status)) {
|
||||
SpringHolder.publishEvent(new AgentOfflineEvent(agentKeyList));
|
||||
SpringHolder.publishEvent(new AgentOfflineEvent(agentKeys));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -48,13 +48,13 @@ import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 告警记录 api
|
||||
* 告警事件 api
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2025-9-17 21:31
|
||||
*/
|
||||
@Tag(name = "monitor - 告警记录服务")
|
||||
@Tag(name = "monitor - 告警事件服务")
|
||||
@Slf4j
|
||||
@Validated
|
||||
@RestWrapper
|
||||
@@ -67,7 +67,7 @@ public class AlarmEventController {
|
||||
|
||||
@IgnoreLog(IgnoreLogMode.RET)
|
||||
@PostMapping("/query")
|
||||
@Operation(summary = "分页查询告警记录")
|
||||
@Operation(summary = "分页查询告警事件")
|
||||
@PreAuthorize("@ss.hasPermission('monitor:alarm-event:query')")
|
||||
public DataGrid<AlarmEventVO> getAlarmEventPage(@Validated(Page.class) @RequestBody AlarmEventQueryRequest request) {
|
||||
return alarmEventService.getAlarmEventPage(request);
|
||||
@@ -76,7 +76,7 @@ public class AlarmEventController {
|
||||
@IgnoreLog(IgnoreLogMode.RET)
|
||||
@OperatorLog(AlarmEventOperatorType.HANDLE)
|
||||
@PostMapping("/handle")
|
||||
@Operation(summary = "处理告警记录")
|
||||
@Operation(summary = "处理告警事件")
|
||||
@PreAuthorize("@ss.hasPermission('monitor:alarm-event:handle')")
|
||||
public Integer handleAlarmEvent(@Validated @RequestBody AlarmEventHandleRequest request) {
|
||||
return alarmEventService.handleAlarmEvent(request);
|
||||
@@ -92,7 +92,7 @@ public class AlarmEventController {
|
||||
}
|
||||
|
||||
@PostMapping("/count")
|
||||
@Operation(summary = "查询告警记录数量")
|
||||
@Operation(summary = "查询告警事件数量")
|
||||
@PreAuthorize("@ss.hasPermission('monitor:alarm-event:query')")
|
||||
public Long getAlarmEventCount(@Validated @RequestBody AlarmEventQueryRequest request) {
|
||||
return alarmEventService.getAlarmEventCount(request);
|
||||
@@ -101,7 +101,7 @@ public class AlarmEventController {
|
||||
@DemoDisableApi
|
||||
@OperatorLog(AlarmEventOperatorType.DELETE)
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除告警记录")
|
||||
@Operation(summary = "删除告警事件")
|
||||
@Parameter(name = "id", description = "id", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('monitor:alarm-event:delete')")
|
||||
public Integer deleteAlarmEvent(@RequestParam("id") Long id) {
|
||||
@@ -111,7 +111,7 @@ public class AlarmEventController {
|
||||
@DemoDisableApi
|
||||
@OperatorLog(AlarmEventOperatorType.DELETE)
|
||||
@DeleteMapping("/batch-delete")
|
||||
@Operation(summary = "批量删除告警记录")
|
||||
@Operation(summary = "批量删除告警事件")
|
||||
@Parameter(name = "idList", description = "idList", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('monitor:alarm-event:delete')")
|
||||
public Integer batchDeleteAlarmEvent(@RequestParam("idList") List<Long> idList) {
|
||||
@@ -121,7 +121,7 @@ public class AlarmEventController {
|
||||
@DemoDisableApi
|
||||
@OperatorLog(AlarmEventOperatorType.CLEAR)
|
||||
@PostMapping("/clear")
|
||||
@Operation(summary = "清理告警记录")
|
||||
@Operation(summary = "清理告警事件")
|
||||
@PreAuthorize("@ss.hasPermission('monitor:alarm-event:management:clear')")
|
||||
public Integer clearAlarmEvent(@Validated @RequestBody AlarmEventClearRequest request) {
|
||||
return alarmEventService.clearAlarmEvent(request);
|
||||
|
||||
@@ -93,11 +93,11 @@ public class AlarmPolicyRuleController {
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "查询全部监控告警规则")
|
||||
@Parameter(name = "policyId", description = "policyId", required = true)
|
||||
@Parameter(name = "metricsMeasurement", description = "metricsMeasurement")
|
||||
@Parameter(name = "measurement", description = "measurement")
|
||||
@PreAuthorize("@ss.hasPermission('monitor:alarm-policy:query')")
|
||||
public List<AlarmPolicyRuleVO> getAlarmPolicyRuleList(@RequestParam("policyId") Long policyId,
|
||||
@RequestParam(value = "metricsMeasurement", required = false) String metricsMeasurement) {
|
||||
return alarmPolicyRuleService.getAlarmPolicyRuleList(policyId, metricsMeasurement);
|
||||
@RequestParam(value = "measurement", required = false) String measurement) {
|
||||
return alarmPolicyRuleService.getAlarmPolicyRuleList(policyId, measurement);
|
||||
}
|
||||
|
||||
@DemoDisableApi
|
||||
|
||||
@@ -38,10 +38,7 @@ import org.dromara.visor.framework.web.core.annotation.RestWrapper;
|
||||
import org.dromara.visor.module.monitor.define.operator.MonitorHostOperatorType;
|
||||
import org.dromara.visor.module.monitor.engine.MonitorContext;
|
||||
import org.dromara.visor.module.monitor.entity.dto.AgentMetricsDataDTO;
|
||||
import org.dromara.visor.module.monitor.entity.request.host.MonitorHostChartRequest;
|
||||
import org.dromara.visor.module.monitor.entity.request.host.MonitorHostQueryRequest;
|
||||
import org.dromara.visor.module.monitor.entity.request.host.MonitorHostSwitchUpdateRequest;
|
||||
import org.dromara.visor.module.monitor.entity.request.host.MonitorHostUpdateRequest;
|
||||
import org.dromara.visor.module.monitor.entity.request.host.*;
|
||||
import org.dromara.visor.module.monitor.entity.vo.MonitorHostMetricsDataVO;
|
||||
import org.dromara.visor.module.monitor.entity.vo.MonitorHostVO;
|
||||
import org.dromara.visor.module.monitor.service.MonitorHostService;
|
||||
@@ -95,7 +92,7 @@ public class MonitorHostController {
|
||||
@Operation(summary = "查询监控指标")
|
||||
@PreAuthorize("@ss.hasPermission('monitor:monitor-host:query')")
|
||||
public List<MonitorHostMetricsDataVO> getMonitorHostMetrics(@Validated(Key.class) @RequestBody MonitorHostQueryRequest request) {
|
||||
return monitorHostService.getMonitorHostMetrics(request.getAgentKeyList());
|
||||
return monitorHostService.getMonitorHostMetrics(request.getAgentKeys());
|
||||
}
|
||||
|
||||
@IgnoreLog(IgnoreLogMode.RET)
|
||||
@@ -106,6 +103,14 @@ public class MonitorHostController {
|
||||
return monitorHostService.getMonitorHostChart(request);
|
||||
}
|
||||
|
||||
@IgnoreLog(IgnoreLogMode.RET)
|
||||
@PostMapping("/host-tags")
|
||||
@Operation(summary = "查询监控告警标签")
|
||||
@PreAuthorize("@ss.hasPermission('monitor:monitor-host:query')")
|
||||
public List<String> getMonitorHostTags(@RequestBody MonitorHostQueryTagRequest request) {
|
||||
return monitorHostService.getMonitorHostTags(request);
|
||||
}
|
||||
|
||||
@DemoDisableApi
|
||||
@OperatorLog(MonitorHostOperatorType.UPDATE)
|
||||
@PutMapping("/update")
|
||||
|
||||
@@ -34,7 +34,7 @@ import org.mapstruct.factory.Mappers;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 监控告警记录 内部对象转换器
|
||||
* 监控告警事件 内部对象转换器
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
|
||||
@@ -32,7 +32,7 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 监控告警记录 Mapper 接口
|
||||
* 监控告警事件 Mapper 接口
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
|
||||
@@ -95,6 +95,20 @@ public interface MonitorHostDAO extends IMapper<MonitorHostDO> {
|
||||
return this.delete(Conditions.in(MonitorHostDO::getHostId, hostIdList));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过 policyId 查询
|
||||
*
|
||||
* @param policyId policyId
|
||||
* @return row
|
||||
*/
|
||||
default List<MonitorHostDO> selectByPolicyId(Long policyId) {
|
||||
return this.of()
|
||||
.createWrapper()
|
||||
.eq(MonitorHostDO::getPolicyId, policyId)
|
||||
.then()
|
||||
.list();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 policyId 为 null
|
||||
*
|
||||
|
||||
@@ -38,7 +38,7 @@ import java.util.concurrent.TimeUnit;
|
||||
*/
|
||||
public interface AlarmPolicyCacheKeyDefine {
|
||||
|
||||
CacheKeyDefine MONITOR_ALARM_POLICY = new CacheKeyBuilder()
|
||||
CacheKeyDefine ALARM_POLICY = new CacheKeyBuilder()
|
||||
.key("alarm:policy:list")
|
||||
.desc("告警策略")
|
||||
.type(AlarmPolicyCacheDTO.class)
|
||||
@@ -49,6 +49,7 @@ public interface AlarmPolicyCacheKeyDefine {
|
||||
CacheKeyDefine ALARM_RULE_SILENCE = new CacheKeyBuilder()
|
||||
.key("alarm:silence:{}:{}")
|
||||
.desc("告警规则沉默标志 ${agentKey} ${ruleId}")
|
||||
.type(Long.class)
|
||||
.struct(RedisCacheStruct.STRING)
|
||||
.build();
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ import static org.dromara.visor.framework.biz.operator.log.core.enums.OperatorRi
|
||||
import static org.dromara.visor.framework.biz.operator.log.core.enums.OperatorRiskLevel.L;
|
||||
|
||||
/**
|
||||
* 监控告警记录 操作日志类型
|
||||
* 监控告警事件 操作日志类型
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
@@ -51,9 +51,9 @@ public class AlarmEventOperatorType extends InitializingOperatorTypes {
|
||||
public OperatorType[] types() {
|
||||
return new OperatorType[]{
|
||||
new OperatorType(L, HANDLE, "设置告警状态为 ${status} <sb>${count}</sb> 条"),
|
||||
new OperatorType(L, SET_FALSE, "设置告警记录为误报 <sb>${count}</sb> 条"),
|
||||
new OperatorType(H, DELETE, "删除告警记录 <sb>${count}</sb> 条"),
|
||||
new OperatorType(H, CLEAR, "清理告警记录 <sb>${count}</sb> 条"),
|
||||
new OperatorType(L, SET_FALSE, "设置告警事件为误报 <sb>${count}</sb> 条"),
|
||||
new OperatorType(H, DELETE, "删除告警事件 <sb>${count}</sb> 条"),
|
||||
new OperatorType(H, CLEAR, "清理告警事件 <sb>${count}</sb> 条"),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 监控告警记录 实体对象
|
||||
* 监控告警事件 实体对象
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
@@ -48,7 +48,7 @@ import java.util.Date;
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName(value = "monitor_alarm_event", autoResultMap = true)
|
||||
@Schema(name = "AlarmEventDO", description = "监控告警记录 实体对象")
|
||||
@Schema(name = "AlarmEventDO", description = "监控告警事件 实体对象")
|
||||
public class AlarmEventDO extends BaseDO {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -32,7 +32,7 @@ import javax.validation.constraints.Min;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* 监控告警记录 清理请求对象
|
||||
* 监控告警事件 清理请求对象
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
@@ -40,7 +40,7 @@ import javax.validation.constraints.NotNull;
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Schema(name = "AlarmEventClearRequest", description = "监控告警记录 清理请求对象")
|
||||
@Schema(name = "AlarmEventClearRequest", description = "监控告警事件 清理请求对象")
|
||||
public class AlarmEventClearRequest extends AlarmEventQueryRequest implements DataClearRequest {
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -38,7 +38,7 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 监控告警记录 更新请求对象
|
||||
* 监控告警事件 更新请求对象
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
@@ -48,7 +48,7 @@ import java.util.List;
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "AlarmEventUpdateRequest", description = "监控告警记录 更新请求对象")
|
||||
@Schema(name = "AlarmEventUpdateRequest", description = "监控告警事件 更新请求对象")
|
||||
public class AlarmEventHandleRequest implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -31,7 +31,7 @@ import javax.validation.constraints.Size;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 监控告警记录 查询请求对象
|
||||
* 监控告警事件 查询请求对象
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
@@ -42,7 +42,7 @@ import java.util.Date;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Schema(name = "AlarmEventQueryRequest", description = "监控告警记录 查询请求对象")
|
||||
@Schema(name = "AlarmEventQueryRequest", description = "监控告警事件 查询请求对象")
|
||||
public class AlarmEventQueryRequest extends BaseQueryRequest {
|
||||
|
||||
@Schema(description = "id")
|
||||
|
||||
@@ -33,7 +33,7 @@ import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 监控告警记录 设置误报请求对象
|
||||
* 监控告警事件 设置误报请求对象
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
@@ -43,7 +43,7 @@ import java.util.List;
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "AlarmEventSetFalseRequest", description = "监控告警记录 设置误报请求对象")
|
||||
@Schema(name = "AlarmEventSetFalseRequest", description = "监控告警事件 设置误报请求对象")
|
||||
public class AlarmEventSetFalseRequest implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -46,7 +46,7 @@ public class MonitorHostQueryRequest extends BaseQueryRequest {
|
||||
|
||||
@NotEmpty(groups = Key.class)
|
||||
@Schema(description = "agentKey")
|
||||
private List<String> agentKeyList;
|
||||
private List<String> agentKeys;
|
||||
|
||||
@Schema(description = "搜索")
|
||||
private String searchValue;
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2023 - present Dromara, All rights reserved.
|
||||
*
|
||||
* https://visor.dromara.org
|
||||
* https://visor.dromara.org.cn
|
||||
* https://visor.orionsec.cn
|
||||
*
|
||||
* Members:
|
||||
* Jiahang Li - ljh1553488six@139.com - author
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.dromara.visor.module.monitor.entity.request.host;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.dromara.visor.common.entity.BaseQueryRequest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 监控主机标签 查询请求对象
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2025-8-14 16:27
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Schema(name = "MonitorHostQueryTagRequest", description = "监控主机标签 查询请求对象")
|
||||
public class MonitorHostQueryTagRequest extends BaseQueryRequest {
|
||||
|
||||
@Schema(description = "数据集")
|
||||
private String measurement;
|
||||
|
||||
@Schema(description = "策略id")
|
||||
private Long policyId;
|
||||
|
||||
@Schema(description = "agentKey")
|
||||
private List<String> agentKeys;
|
||||
|
||||
}
|
||||
@@ -33,7 +33,7 @@ import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 监控告警记录 视图响应对象
|
||||
* 监控告警事件 视图响应对象
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
@@ -43,7 +43,7 @@ import java.util.Date;
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "AlarmEventVO", description = "监控告警记录 视图响应对象")
|
||||
@Schema(name = "AlarmEventVO", description = "监控告警事件 视图响应对象")
|
||||
public class AlarmEventVO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
package org.dromara.visor.module.monitor.enums;
|
||||
|
||||
/**
|
||||
* 告警记录处理状态
|
||||
* 告警事件处理状态
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
|
||||
@@ -43,7 +43,7 @@ public enum MeasurementEnum {
|
||||
/**
|
||||
* cpu
|
||||
*/
|
||||
CPU("cpu", (s) -> {
|
||||
CPU("cpu", true, (s) -> {
|
||||
s.accept(MetricsConst.CPU_USER_SECONDS_TOTAL, double.class);
|
||||
s.accept(MetricsConst.CPU_SYSTEM_SECONDS_TOTAL, double.class);
|
||||
s.accept(MetricsConst.CPU_TOTAL_SECONDS_TOTAL, double.class);
|
||||
@@ -52,7 +52,7 @@ public enum MeasurementEnum {
|
||||
/**
|
||||
* 内存
|
||||
*/
|
||||
MEMORY("memory", s -> {
|
||||
MEMORY("memory", false, s -> {
|
||||
s.accept(MetricsConst.MEM_USED_BYTES_TOTAL, long.class);
|
||||
s.accept(MetricsConst.MEM_USED_PERCENT, double.class);
|
||||
s.accept(MetricsConst.MEM_SWAP_USED_BYTES_TOTAL, long.class);
|
||||
@@ -62,7 +62,7 @@ public enum MeasurementEnum {
|
||||
/**
|
||||
* 负载
|
||||
*/
|
||||
LOAD("load", s -> {
|
||||
LOAD("load", false, s -> {
|
||||
s.accept(MetricsConst.LOAD1, double.class);
|
||||
s.accept(MetricsConst.LOAD5, double.class);
|
||||
s.accept(MetricsConst.LOAD15, double.class);
|
||||
@@ -74,7 +74,7 @@ public enum MeasurementEnum {
|
||||
/**
|
||||
* 磁盘
|
||||
*/
|
||||
DISK("disk", s -> {
|
||||
DISK("disk", true, s -> {
|
||||
s.accept(MetricsConst.DISK_FS_USED_BYTES_TOTAL, long.class);
|
||||
s.accept(MetricsConst.DISK_FS_USED_PERCENT, double.class);
|
||||
s.accept(MetricsConst.DISK_FS_INODES_USED_PERCENT, double.class);
|
||||
@@ -83,7 +83,7 @@ public enum MeasurementEnum {
|
||||
/**
|
||||
* io
|
||||
*/
|
||||
IO("io", s -> {
|
||||
IO("io", false, s -> {
|
||||
s.accept(MetricsConst.DISK_IO_READ_BYTES_TOTAL, long.class);
|
||||
s.accept(MetricsConst.DISK_IO_WRITE_BYTES_TOTAL, long.class);
|
||||
s.accept(MetricsConst.DISK_IO_READS_TOTAL, long.class);
|
||||
@@ -97,7 +97,7 @@ public enum MeasurementEnum {
|
||||
/**
|
||||
* 网络
|
||||
*/
|
||||
NETWORK("network", s -> {
|
||||
NETWORK("network", true, s -> {
|
||||
s.accept(MetricsConst.NET_SENT_BYTES_TOTAL, long.class);
|
||||
s.accept(MetricsConst.NET_RECV_BYTES_TOTAL, long.class);
|
||||
s.accept(MetricsConst.NET_SENT_PACKETS_TOTAL, long.class);
|
||||
@@ -111,7 +111,7 @@ public enum MeasurementEnum {
|
||||
/**
|
||||
* 连接数
|
||||
*/
|
||||
CONNECTIONS("connections", s -> {
|
||||
CONNECTIONS("connections", false, s -> {
|
||||
s.accept(MetricsConst.NET_TCP_CONNECTIONS, int.class);
|
||||
s.accept(MetricsConst.NET_UDP_CONNECTIONS, int.class);
|
||||
s.accept(MetricsConst.NET_INET_CONNECTIONS, int.class);
|
||||
@@ -121,10 +121,14 @@ public enum MeasurementEnum {
|
||||
;
|
||||
|
||||
private final String measurement;
|
||||
|
||||
private final boolean hasTags;
|
||||
|
||||
private final Map<String, Class<?>> fields;
|
||||
|
||||
MeasurementEnum(String measurement, Consumer<BiConsumer<String, Class<?>>> register) {
|
||||
MeasurementEnum(String measurement, boolean hasTags, Consumer<BiConsumer<String, Class<?>>> register) {
|
||||
this.measurement = measurement;
|
||||
this.hasTags = hasTags;
|
||||
this.fields = new HashedMap<>();
|
||||
register.accept(this.fields::put);
|
||||
}
|
||||
|
||||
@@ -1,159 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2023 - present Dromara, All rights reserved.
|
||||
*
|
||||
* https://visor.dromara.org
|
||||
* https://visor.dromara.org.cn
|
||||
* https://visor.orionsec.cn
|
||||
*
|
||||
* Members:
|
||||
* Jiahang Li - ljh1553488six@139.com - author
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.dromara.visor.module.monitor.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.apache.commons.collections4.map.HashedMap;
|
||||
import org.dromara.visor.module.monitor.constant.MetricsConst;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* 指标度量类型
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2025/8/14 10:27
|
||||
*/
|
||||
@Getter
|
||||
public enum MeasurementFieldEnum {
|
||||
|
||||
/**
|
||||
* cpu
|
||||
*/
|
||||
CPU("cpu", (s) -> {
|
||||
s.accept(MetricsConst.CPU_USER_SECONDS_TOTAL, double.class);
|
||||
s.accept(MetricsConst.CPU_SYSTEM_SECONDS_TOTAL, double.class);
|
||||
s.accept(MetricsConst.CPU_TOTAL_SECONDS_TOTAL, double.class);
|
||||
}),
|
||||
|
||||
/**
|
||||
* 内存
|
||||
*/
|
||||
MEMORY("memory", s -> {
|
||||
s.accept(MetricsConst.MEM_USED_BYTES_TOTAL, long.class);
|
||||
s.accept(MetricsConst.MEM_USED_PERCENT, double.class);
|
||||
s.accept(MetricsConst.MEM_SWAP_USED_BYTES_TOTAL, long.class);
|
||||
s.accept(MetricsConst.MEM_SWAP_USED_PERCENT, double.class);
|
||||
}),
|
||||
|
||||
/**
|
||||
* 负载
|
||||
*/
|
||||
LOAD("load", s -> {
|
||||
s.accept(MetricsConst.LOAD1, double.class);
|
||||
s.accept(MetricsConst.LOAD5, double.class);
|
||||
s.accept(MetricsConst.LOAD15, double.class);
|
||||
s.accept(MetricsConst.LOAD1_CORE_RATIO, double.class);
|
||||
s.accept(MetricsConst.LOAD5_CORE_RATIO, double.class);
|
||||
s.accept(MetricsConst.LOAD15_CORE_RATIO, double.class);
|
||||
}),
|
||||
|
||||
/**
|
||||
* 磁盘
|
||||
*/
|
||||
DISK("disk", s -> {
|
||||
s.accept(MetricsConst.DISK_FS_USED_BYTES_TOTAL, long.class);
|
||||
s.accept(MetricsConst.DISK_FS_USED_PERCENT, double.class);
|
||||
s.accept(MetricsConst.DISK_FS_INODES_USED_PERCENT, double.class);
|
||||
}),
|
||||
|
||||
/**
|
||||
* io
|
||||
*/
|
||||
IO("io", s -> {
|
||||
s.accept(MetricsConst.DISK_IO_READ_BYTES_TOTAL, long.class);
|
||||
s.accept(MetricsConst.DISK_IO_WRITE_BYTES_TOTAL, long.class);
|
||||
s.accept(MetricsConst.DISK_IO_READS_TOTAL, long.class);
|
||||
s.accept(MetricsConst.DISK_IO_WRITES_TOTAL, long.class);
|
||||
s.accept(MetricsConst.DISK_IO_READ_BYTES_PER_SECOND, double.class);
|
||||
s.accept(MetricsConst.DISK_IO_WRITE_BYTES_PER_SECOND, double.class);
|
||||
s.accept(MetricsConst.DISK_IO_READS_PER_SECOND, double.class);
|
||||
s.accept(MetricsConst.DISK_IO_WRITES_PER_SECOND, double.class);
|
||||
}),
|
||||
|
||||
/**
|
||||
* 网络
|
||||
*/
|
||||
NETWORK("network", s -> {
|
||||
s.accept(MetricsConst.NET_SENT_BYTES_TOTAL, long.class);
|
||||
s.accept(MetricsConst.NET_RECV_BYTES_TOTAL, long.class);
|
||||
s.accept(MetricsConst.NET_SENT_PACKETS_TOTAL, long.class);
|
||||
s.accept(MetricsConst.NET_RECV_PACKETS_TOTAL, long.class);
|
||||
s.accept(MetricsConst.NET_SENT_BYTES_PER_SECOND, double.class);
|
||||
s.accept(MetricsConst.NET_RECV_BYTES_PER_SECOND, double.class);
|
||||
s.accept(MetricsConst.NET_SENT_PACKETS_PER_SECOND, double.class);
|
||||
s.accept(MetricsConst.NET_RECV_PACKETS_PER_SECOND, double.class);
|
||||
}),
|
||||
|
||||
/**
|
||||
* 连接数
|
||||
*/
|
||||
CONNECTIONS("connections", s -> {
|
||||
s.accept(MetricsConst.NET_TCP_CONNECTIONS, int.class);
|
||||
s.accept(MetricsConst.NET_UDP_CONNECTIONS, int.class);
|
||||
s.accept(MetricsConst.NET_INET_CONNECTIONS, int.class);
|
||||
s.accept(MetricsConst.NET_ALL_CONNECTIONS, int.class);
|
||||
}),
|
||||
|
||||
;
|
||||
|
||||
private final String measurement;
|
||||
private final Map<String, Class<?>> fields;
|
||||
|
||||
MeasurementFieldEnum(String measurement, Consumer<BiConsumer<String, Class<?>>> register) {
|
||||
this.measurement = measurement;
|
||||
this.fields = new HashedMap<>();
|
||||
register.accept(this.fields::put);
|
||||
}
|
||||
|
||||
public static MeasurementFieldEnum of(String measurement) {
|
||||
if (measurement == null) {
|
||||
return null;
|
||||
}
|
||||
for (MeasurementFieldEnum e : values()) {
|
||||
if (e.measurement.equals(measurement)) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取度量值类型
|
||||
*
|
||||
* @param measurement measurement
|
||||
* @param field field
|
||||
* @return type
|
||||
*/
|
||||
public static Class<?> getMetricsValueType(String measurement, String field) {
|
||||
MeasurementFieldEnum m = of(measurement);
|
||||
if (m == null) {
|
||||
return null;
|
||||
}
|
||||
return m.getFields().get(field);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -35,7 +35,7 @@ import org.dromara.visor.module.monitor.entity.vo.AlarmEventVO;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 监控告警记录 服务类
|
||||
* 监控告警事件 服务类
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
@@ -44,14 +44,14 @@ import java.util.List;
|
||||
public interface AlarmEventService {
|
||||
|
||||
/**
|
||||
* 创建监控告警记录
|
||||
* 创建监控告警事件
|
||||
*
|
||||
* @param record record
|
||||
*/
|
||||
void createAlarmEvent(AlarmEventDO record);
|
||||
|
||||
/**
|
||||
* 处理告警记录
|
||||
* 处理告警事件
|
||||
*
|
||||
* @param request request
|
||||
* @return effect
|
||||
@@ -67,7 +67,7 @@ public interface AlarmEventService {
|
||||
Integer setAlarmEventFalse(AlarmEventSetFalseRequest request);
|
||||
|
||||
/**
|
||||
* 分页查询监控告警记录
|
||||
* 分页查询监控告警事件
|
||||
*
|
||||
* @param request request
|
||||
* @return rows
|
||||
@@ -75,7 +75,7 @@ public interface AlarmEventService {
|
||||
DataGrid<AlarmEventVO> getAlarmEventPage(AlarmEventQueryRequest request);
|
||||
|
||||
/**
|
||||
* 查询监控告警记录数量
|
||||
* 查询监控告警事件数量
|
||||
*
|
||||
* @param request request
|
||||
* @return count
|
||||
@@ -83,7 +83,7 @@ public interface AlarmEventService {
|
||||
Long getAlarmEventCount(AlarmEventQueryRequest request);
|
||||
|
||||
/**
|
||||
* 删除监控告警记录
|
||||
* 删除监控告警事件
|
||||
*
|
||||
* @param id id
|
||||
* @return effect
|
||||
@@ -91,7 +91,7 @@ public interface AlarmEventService {
|
||||
Integer deleteAlarmEventById(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除监控告警记录
|
||||
* 批量删除监控告警事件
|
||||
*
|
||||
* @param idList idList
|
||||
* @return effect
|
||||
@@ -99,7 +99,7 @@ public interface AlarmEventService {
|
||||
Integer deleteAlarmEventByIdList(List<Long> idList);
|
||||
|
||||
/**
|
||||
* 清理监控告警记录
|
||||
* 清理监控告警事件
|
||||
*
|
||||
* @param request request
|
||||
* @return effect
|
||||
@@ -107,7 +107,7 @@ public interface AlarmEventService {
|
||||
Integer clearAlarmEvent(AlarmEventClearRequest request);
|
||||
|
||||
/**
|
||||
* 获取策略告警记录数量
|
||||
* 获取策略告警事件数量
|
||||
*
|
||||
* @param policyIdList policyIdList
|
||||
* @param startDay startDay
|
||||
|
||||
@@ -73,11 +73,11 @@ public interface AlarmPolicyRuleService {
|
||||
/**
|
||||
* 查询全部监控告警规则
|
||||
*
|
||||
* @param policyId policyId
|
||||
* @param metricsMeasurement metricsMeasurement
|
||||
* @param policyId policyId
|
||||
* @param measurement measurement
|
||||
* @return rows
|
||||
*/
|
||||
List<AlarmPolicyRuleVO> getAlarmPolicyRuleList(Long policyId, String metricsMeasurement);
|
||||
List<AlarmPolicyRuleVO> getAlarmPolicyRuleList(Long policyId, String measurement);
|
||||
|
||||
/**
|
||||
* 通过 metricsId 删除监控告警规则
|
||||
|
||||
@@ -24,10 +24,7 @@ package org.dromara.visor.module.monitor.service;
|
||||
|
||||
import cn.orionsec.kit.lang.define.wrapper.DataGrid;
|
||||
import org.dromara.visor.common.entity.chart.TimeChartSeries;
|
||||
import org.dromara.visor.module.monitor.entity.request.host.MonitorHostChartRequest;
|
||||
import org.dromara.visor.module.monitor.entity.request.host.MonitorHostQueryRequest;
|
||||
import org.dromara.visor.module.monitor.entity.request.host.MonitorHostSwitchUpdateRequest;
|
||||
import org.dromara.visor.module.monitor.entity.request.host.MonitorHostUpdateRequest;
|
||||
import org.dromara.visor.module.monitor.entity.request.host.*;
|
||||
import org.dromara.visor.module.monitor.entity.vo.MonitorHostMetricsDataVO;
|
||||
import org.dromara.visor.module.monitor.entity.vo.MonitorHostVO;
|
||||
|
||||
@@ -53,10 +50,10 @@ public interface MonitorHostService {
|
||||
/**
|
||||
* 获取监控主机指标数据
|
||||
*
|
||||
* @param agentKeyList agentKeyList
|
||||
* @param agentKeys agentKeys
|
||||
* @return metrics
|
||||
*/
|
||||
List<MonitorHostMetricsDataVO> getMonitorHostMetrics(List<String> agentKeyList);
|
||||
List<MonitorHostMetricsDataVO> getMonitorHostMetrics(List<String> agentKeys);
|
||||
|
||||
/**
|
||||
* 获取监控主机图表数据
|
||||
@@ -66,6 +63,14 @@ public interface MonitorHostService {
|
||||
*/
|
||||
List<TimeChartSeries> getMonitorHostChart(MonitorHostChartRequest request);
|
||||
|
||||
/**
|
||||
* 查询监控告警标签
|
||||
*
|
||||
* @param request request
|
||||
* @return tags
|
||||
*/
|
||||
List<String> getMonitorHostTags(MonitorHostQueryTagRequest request);
|
||||
|
||||
/**
|
||||
* 更新监控主机
|
||||
*
|
||||
|
||||
@@ -62,7 +62,7 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 监控告警记录 服务实现类
|
||||
* 监控告警事件 服务实现类
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
|
||||
@@ -160,13 +160,13 @@ public class AlarmPolicyRuleServiceImpl implements AlarmPolicyRuleService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AlarmPolicyRuleVO> getAlarmPolicyRuleList(Long policyId, String metricsMeasurement) {
|
||||
public List<AlarmPolicyRuleVO> getAlarmPolicyRuleList(Long policyId, String measurement) {
|
||||
// 查询
|
||||
return alarmPolicyRuleDAO.of()
|
||||
.createWrapper()
|
||||
.eq(AlarmPolicyRuleDO::getPolicyId, policyId)
|
||||
.eq(Strings.isNotBlank(metricsMeasurement), AlarmPolicyRuleDO::getMetricsMeasurement, metricsMeasurement)
|
||||
// 想同的指标在一起
|
||||
.eq(Strings.isNotBlank(measurement), AlarmPolicyRuleDO::getMetricsMeasurement, measurement)
|
||||
// 相同的指标在一起
|
||||
.orderByAsc(AlarmPolicyRuleDO::getMetricsId)
|
||||
// 通过 p0 > p1 排序
|
||||
.orderByAsc(AlarmPolicyRuleDO::getLevel)
|
||||
|
||||
@@ -173,14 +173,14 @@ public class AlarmPolicyServiceImpl implements AlarmPolicyService {
|
||||
@Override
|
||||
public List<AlarmPolicyVO> getAlarmPolicyListByCache() {
|
||||
// 查询缓存
|
||||
List<AlarmPolicyCacheDTO> list = RedisMaps.valuesJson(AlarmPolicyCacheKeyDefine.MONITOR_ALARM_POLICY);
|
||||
List<AlarmPolicyCacheDTO> list = RedisMaps.valuesJson(AlarmPolicyCacheKeyDefine.ALARM_POLICY);
|
||||
if (list.isEmpty()) {
|
||||
// 查询数据库
|
||||
list = alarmPolicyDAO.of().list(AlarmPolicyConvert.MAPPER::toCache);
|
||||
// 设置屏障 防止穿透
|
||||
CacheBarriers.checkBarrier(list, AlarmPolicyCacheDTO::new);
|
||||
// 设置缓存
|
||||
RedisMaps.putAllJson(AlarmPolicyCacheKeyDefine.MONITOR_ALARM_POLICY, s -> s.getId().toString(), list);
|
||||
RedisMaps.putAllJson(AlarmPolicyCacheKeyDefine.ALARM_POLICY, s -> s.getId().toString(), list);
|
||||
}
|
||||
// 删除屏障
|
||||
CacheBarriers.removeBarrier(list);
|
||||
|
||||
@@ -147,7 +147,7 @@ public class MonitorAgentEndpointServiceImpl implements MonitorAgentEndpointServ
|
||||
}
|
||||
monitorHostDAO.updateById(update);
|
||||
}
|
||||
// 设置配置缓存
|
||||
// 重新加载监控主机上下文
|
||||
if (newConfig != null) {
|
||||
monitorContext.reloadMonitorHost(agentKey);
|
||||
}
|
||||
|
||||
@@ -55,10 +55,7 @@ import org.dromara.visor.module.monitor.engine.MonitorContext;
|
||||
import org.dromara.visor.module.monitor.entity.domain.AlarmPolicyDO;
|
||||
import org.dromara.visor.module.monitor.entity.domain.MonitorHostDO;
|
||||
import org.dromara.visor.module.monitor.entity.dto.*;
|
||||
import org.dromara.visor.module.monitor.entity.request.host.MonitorHostChartRequest;
|
||||
import org.dromara.visor.module.monitor.entity.request.host.MonitorHostQueryRequest;
|
||||
import org.dromara.visor.module.monitor.entity.request.host.MonitorHostSwitchUpdateRequest;
|
||||
import org.dromara.visor.module.monitor.entity.request.host.MonitorHostUpdateRequest;
|
||||
import org.dromara.visor.module.monitor.entity.request.host.*;
|
||||
import org.dromara.visor.module.monitor.entity.vo.MonitorHostMetricsDataVO;
|
||||
import org.dromara.visor.module.monitor.entity.vo.MonitorHostVO;
|
||||
import org.dromara.visor.module.monitor.enums.AlarmSwitchEnum;
|
||||
@@ -188,8 +185,8 @@ public class MonitorHostServiceImpl implements MonitorHostService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MonitorHostMetricsDataVO> getMonitorHostMetrics(List<String> agentKeyList) {
|
||||
return agentKeyList.stream()
|
||||
public List<MonitorHostMetricsDataVO> getMonitorHostMetrics(List<String> agentKeys) {
|
||||
return agentKeys.stream()
|
||||
.map(s -> this.getHostMetricsData(s, null))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
@@ -235,6 +232,44 @@ public class MonitorHostServiceImpl implements MonitorHostService {
|
||||
return seriesList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getMonitorHostTags(MonitorHostQueryTagRequest request) {
|
||||
MeasurementEnum measurementEnum = MeasurementEnum.of(request.getMeasurement());
|
||||
if (measurementEnum == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
// 映射数据
|
||||
Function<MonitorHostMetaDTO, List<String>> tagsGetter;
|
||||
if (MeasurementEnum.CPU.equals(measurementEnum)) {
|
||||
tagsGetter = MonitorHostMetaDTO::getCpus;
|
||||
} else if (MeasurementEnum.DISK.equals(measurementEnum)) {
|
||||
tagsGetter = MonitorHostMetaDTO::getDisks;
|
||||
} else if (MeasurementEnum.NETWORK.equals(measurementEnum)) {
|
||||
tagsGetter = MonitorHostMetaDTO::getNets;
|
||||
} else {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
// 查询监控主机元数据
|
||||
List<MonitorHostMetaDTO> metas = monitorHostDAO.of()
|
||||
.createValidateWrapper()
|
||||
.eq(MonitorHostDO::getPolicyId, request.getPolicyId())
|
||||
.in(MonitorHostDO::getAgentKey, request.getAgentKeys())
|
||||
.then()
|
||||
.stream()
|
||||
.map(MonitorHostDO::getMonitorMeta)
|
||||
.filter(Objects::nonNull)
|
||||
.map(s -> JSON.parseObject(s, MonitorHostMetaDTO.class))
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
// 获取 tag
|
||||
return metas.stream()
|
||||
.map(tagsGetter)
|
||||
.flatMap(Collection::stream)
|
||||
.filter(Objects::nonNull)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Integer updateMonitorHostById(MonitorHostUpdateRequest request) {
|
||||
@@ -272,7 +307,7 @@ public class MonitorHostServiceImpl implements MonitorHostService {
|
||||
if (policyId == null) {
|
||||
monitorHostDAO.setPolicyIdWithNullById(id);
|
||||
}
|
||||
// 更新缓存
|
||||
// 重新加载监控主机上下文
|
||||
monitorContext.reloadMonitorHost(host.getAgentKey());
|
||||
log.info("MonitorHostService-updateMonitorHostById effect: {}", effect);
|
||||
return effect;
|
||||
|
||||
@@ -4,7 +4,7 @@ import axios from 'axios';
|
||||
import qs from 'query-string';
|
||||
|
||||
/**
|
||||
* 告警记录处理请求
|
||||
* 告警事件处理请求
|
||||
*/
|
||||
export interface AlarmEventHandleRequest {
|
||||
idList?: Array<number>;
|
||||
@@ -14,14 +14,14 @@ export interface AlarmEventHandleRequest {
|
||||
}
|
||||
|
||||
/**
|
||||
* 告警记录误报请求
|
||||
* 告警事件误报请求
|
||||
*/
|
||||
export interface AlarmEventFalseAlarmRequest {
|
||||
idList?: Array<number>;
|
||||
}
|
||||
|
||||
/**
|
||||
* 告警记录查询请求
|
||||
* 告警事件查询请求
|
||||
*/
|
||||
export interface AlarmEventQueryRequest extends Pagination, OrderDirection {
|
||||
id?: number;
|
||||
@@ -39,13 +39,13 @@ export interface AlarmEventQueryRequest extends Pagination, OrderDirection {
|
||||
}
|
||||
|
||||
/**
|
||||
* 告警记录清理请求
|
||||
* 告警事件清理请求
|
||||
*/
|
||||
export interface AlarmEventClearRequest extends AlarmEventQueryRequest, ClearRequest {
|
||||
}
|
||||
|
||||
/**
|
||||
* 告警记录查询响应
|
||||
* 告警事件查询响应
|
||||
*/
|
||||
export interface AlarmEventQueryResponse extends TableData {
|
||||
id: number;
|
||||
@@ -75,7 +75,7 @@ export interface AlarmEventQueryResponse extends TableData {
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理告警记录
|
||||
* 处理告警事件
|
||||
*/
|
||||
export function handleAlarmEvent(request: AlarmEventHandleRequest) {
|
||||
return axios.post<number>('/monitor/alarm-event/handle', request);
|
||||
@@ -89,28 +89,28 @@ export function setAlarmEventFalse(request: AlarmEventFalseAlarmRequest) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询告警记录
|
||||
* 分页查询告警事件
|
||||
*/
|
||||
export function getAlarmEventPage(request: AlarmEventQueryRequest) {
|
||||
return axios.post<DataGrid<AlarmEventQueryResponse>>('/monitor/alarm-event/query', request);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询告警记录数量
|
||||
* 查询告警事件数量
|
||||
*/
|
||||
export function getAlarmEventCount(request: AlarmEventQueryRequest) {
|
||||
return axios.post<number>('/monitor/alarm-event/count', request);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除告警记录
|
||||
* 删除告警事件
|
||||
*/
|
||||
export function deleteAlarmEvent(id: number) {
|
||||
return axios.delete<number>('/monitor/alarm-event/delete', { params: { id } });
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除告警记录
|
||||
* 批量删除告警事件
|
||||
*/
|
||||
export function batchDeleteAlarmEvent(idList: Array<number>) {
|
||||
return axios.delete<number>('/monitor/alarm-event/batch-delete', {
|
||||
@@ -122,7 +122,7 @@ export function batchDeleteAlarmEvent(idList: Array<number>) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理告警记录
|
||||
* 清理告警事件
|
||||
*/
|
||||
export function clearMonitorAlarmEvent(request: AlarmEventClearRequest) {
|
||||
return axios.post<number>('/monitor/alarm-event/clear', request);
|
||||
|
||||
@@ -72,8 +72,8 @@ export function updateAlarmRuleSwitch(request: AlarmRuleUpdateRequest) {
|
||||
/**
|
||||
* 查询全部监控告警规则
|
||||
*/
|
||||
export function getAlarmRuleList(policyId: number, metricsMeasurement: string = '') {
|
||||
return axios.get<Array<AlarmRuleQueryResponse>>('/monitor/alarm-policy-rule/list', { params: { policyId, metricsMeasurement } });
|
||||
export function getAlarmRuleList(policyId: number, measurement: string = '') {
|
||||
return axios.get<Array<AlarmRuleQueryResponse>>('/monitor/alarm-policy-rule/list', { params: { policyId, measurement } });
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -28,7 +28,7 @@ export interface MonitorHostSwitchUpdateRequest {
|
||||
* 监控主机查询请求
|
||||
*/
|
||||
export interface MonitorHostQueryRequest extends Pagination {
|
||||
agentKeyList?: Array<string>;
|
||||
agentKeys?: Array<string>;
|
||||
searchValue?: string;
|
||||
alarmSwitch?: number;
|
||||
policyId?: number;
|
||||
@@ -43,6 +43,15 @@ export interface MonitorHostQueryRequest extends Pagination {
|
||||
tags?: Array<number>;
|
||||
}
|
||||
|
||||
/**
|
||||
* 监控主机标签查询请求
|
||||
*/
|
||||
export interface MonitorHostQueryTagRequest {
|
||||
measurement?: string;
|
||||
policyId?: number;
|
||||
agentKeys?: Array<string>;
|
||||
}
|
||||
|
||||
/**
|
||||
* 监控主机图表查询请求
|
||||
*/
|
||||
@@ -147,12 +156,12 @@ export interface MonitorHostMetricsData {
|
||||
/**
|
||||
* 查询监控主机指标
|
||||
*/
|
||||
export function getMonitorHostMetrics(agentKeyList: Array<string>) {
|
||||
export function getMonitorHostMetrics(agentKeys: Array<string>) {
|
||||
return axios.post<Array<MonitorHostMetricsData>>('/monitor/monitor-host/metrics', {
|
||||
agentKeyList
|
||||
agentKeys
|
||||
}, {
|
||||
promptBizErrorMessage: false,
|
||||
promptRequestErrorMessage: false,
|
||||
promptRequestErrorMessage: false
|
||||
});
|
||||
}
|
||||
|
||||
@@ -179,6 +188,13 @@ export function getMonitorHostPage(request: MonitorHostQueryRequest) {
|
||||
return axios.post<DataGrid<MonitorHostQueryResponse>>('/monitor/monitor-host/query', request);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询监控主机标签
|
||||
*/
|
||||
export function getMonitorHostTags(request: MonitorHostQueryTagRequest) {
|
||||
return axios.post<Array<string>>('/monitor/monitor-host/host-tags', request);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新监控主机
|
||||
*/
|
||||
|
||||
@@ -95,7 +95,7 @@
|
||||
|
||||
// 标准卡片
|
||||
.general-card {
|
||||
border-radius: 4px;
|
||||
border-radius: 8px;
|
||||
border: none;
|
||||
|
||||
& > .arco-card-header {
|
||||
|
||||
@@ -14,58 +14,6 @@ body {
|
||||
-webkit-font-smoothing: antialiased;
|
||||
}
|
||||
|
||||
// -- echarts
|
||||
.echarts-tooltip-diy {
|
||||
background: linear-gradient(304.17deg,
|
||||
rgba(253, 254, 255, 0.6) -6.04%,
|
||||
rgba(244, 247, 252, 0.6) 85.2%) !important;
|
||||
border: none !important;
|
||||
backdrop-filter: blur(10px) !important;
|
||||
/* Note: backdrop-filter has minimal browser support */
|
||||
|
||||
border-radius: 6px !important;
|
||||
|
||||
.content-panel {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
padding: 0 9px;
|
||||
background: rgba(255, 255, 255, 0.8);
|
||||
width: 164px;
|
||||
height: 32px;
|
||||
line-height: 32px;
|
||||
box-shadow: 6px 0 20px rgba(34, 87, 188, 0.1);
|
||||
border-radius: 4px;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.tooltip-title {
|
||||
margin: 0 0 10px 0;
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.tooltip-title,
|
||||
.tooltip-value {
|
||||
font-size: 13px;
|
||||
line-height: 15px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
text-align: right;
|
||||
color: #1D2129;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.tooltip-item-icon {
|
||||
display: inline-block;
|
||||
margin-right: 8px;
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
border-radius: 50%;
|
||||
}
|
||||
}
|
||||
|
||||
// flex
|
||||
.flex-center {
|
||||
display: flex;
|
||||
|
||||
@@ -162,8 +162,8 @@
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
border-radius: 4px;
|
||||
border: 1px solid var(--color-neutral-3);
|
||||
border-radius: 8px;
|
||||
//border: 1px solid var(--color-neutral-3);
|
||||
transition-property: all;
|
||||
|
||||
& > .arco-card-header {
|
||||
@@ -230,7 +230,7 @@
|
||||
// -- card
|
||||
.simple-card {
|
||||
background: var(--color-bg-2);
|
||||
border-radius: 4px;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
// -- doption
|
||||
|
||||
@@ -27,7 +27,19 @@
|
||||
</div>
|
||||
<!-- 状态 -->
|
||||
<div class="exec-host-item-status">
|
||||
<a-tag :color="getDictValue(execHostStatusKey, item.status, 'execColor')">
|
||||
<!-- 执行结果 -->
|
||||
<a-tag v-if="item.exitCode || item.exitCode === 0"
|
||||
class="exit-code-tag"
|
||||
title="exitCode"
|
||||
:color="item.exitCode === 0 ? 'rgb(var(--arcoblue-4))' : 'rgb(var(--orangered-4))'">
|
||||
<template #icon>
|
||||
<icon-check v-if="item.exitCode === 0" />
|
||||
<icon-exclamation v-else />
|
||||
</template>
|
||||
<span class="exit-code-value">{{ item.exitCode }}</span>
|
||||
</a-tag>
|
||||
<!-- 执行状态 -->
|
||||
<a-tag v-else :color="getDictValue(execHostStatusKey, item.status, 'execColor')">
|
||||
{{ getDictValue(execHostStatusKey, item.status) }}
|
||||
</a-tag>
|
||||
</div>
|
||||
@@ -141,8 +153,16 @@
|
||||
&-status {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
gap: 8px;
|
||||
|
||||
:deep(.exit-code-tag .arco-tag-icon) {
|
||||
color: #FFFFFF;
|
||||
}
|
||||
|
||||
.exit-code-value {
|
||||
font-weight: 600;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<!-- exitCode -->
|
||||
<a-tag v-if="host.exitCode || host.exitCode === 0"
|
||||
:color="host.exitCode === 0 ? 'arcoblue' : 'orangered'"
|
||||
title="exit code">
|
||||
title="exitCode">
|
||||
<template #icon>
|
||||
<icon-check v-if="host.exitCode === 0" />
|
||||
<icon-exclamation v-else />
|
||||
|
||||
@@ -179,7 +179,7 @@
|
||||
&-wrapper {
|
||||
background: var(--color-bg-2);
|
||||
padding: 0 12px;
|
||||
border-radius: 4px;
|
||||
border-radius: 8px;
|
||||
|
||||
.card-list-info {
|
||||
height: var(--header-info-height);
|
||||
|
||||
@@ -17,6 +17,7 @@ export interface TimeSeriesColor {
|
||||
export interface TimeSeriesOption {
|
||||
name: string;
|
||||
type: TimeSeriesType;
|
||||
smooth: boolean;
|
||||
area: boolean;
|
||||
lineColor: string;
|
||||
itemBorderColor: string;
|
||||
@@ -126,7 +127,7 @@ export const createTimeSeries = (option: Partial<TimeSeriesOption>): LineSeriesO
|
||||
name: option.name,
|
||||
data: option.data || [],
|
||||
type: option.type || 'line',
|
||||
smooth: true,
|
||||
smooth: option.smooth ?? true,
|
||||
symbol: 'circle',
|
||||
symbolSize: 10,
|
||||
itemStyle: {
|
||||
|
||||
@@ -12,6 +12,10 @@ export function isString(obj: any): obj is string {
|
||||
return opt.call(obj) === '[object String]';
|
||||
}
|
||||
|
||||
export function isBoolean(obj: any): obj is boolean {
|
||||
return opt.call(obj) === '[object Boolean]';
|
||||
}
|
||||
|
||||
export function isNumber(obj: any): obj is number {
|
||||
return opt.call(obj) === '[object Number]' && obj === obj; // eslint-disable-line
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@
|
||||
|
||||
:deep(.card) {
|
||||
padding: 16px 20px;
|
||||
border-radius: 4px;
|
||||
border-radius: 8px;
|
||||
background-color: var(--color-bg-2);
|
||||
|
||||
&-title {
|
||||
|
||||
@@ -301,7 +301,7 @@
|
||||
.panel-item {
|
||||
height: 100%;
|
||||
padding: 16px;
|
||||
border-radius: 4px;
|
||||
border-radius: 8px;
|
||||
margin-right: 16px;
|
||||
position: relative;
|
||||
background: var(--color-bg-2);
|
||||
|
||||
@@ -295,7 +295,7 @@
|
||||
|
||||
.exec-form-container, .exec-command-container, .exec-history-container {
|
||||
background: var(--color-bg-2);
|
||||
border-radius: 4px;
|
||||
border-radius: 8px;
|
||||
height: 100%;
|
||||
padding: 16px;
|
||||
position: relative;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<div class="table-left-bar-handle">
|
||||
<!-- 标题 -->
|
||||
<div class="table-title">
|
||||
告警记录列表
|
||||
告警事件列表
|
||||
</div>
|
||||
</div>
|
||||
<!-- 右侧操作 -->
|
||||
@@ -229,8 +229,8 @@
|
||||
|
||||
// 获取指标名称
|
||||
const getMetricsField = (metricsId: number, field: string) => {
|
||||
return (monitorMetrics as Array<MetricsQueryResponse>).find(m => m.id === metricsId)?.[field];
|
||||
};
|
||||
return (monitorMetrics as Array<MetricsQueryResponse> || []).find(m => m.id === metricsId)?.[field];
|
||||
};
|
||||
|
||||
// 提取标签
|
||||
const extraTags = (record: AlarmEventQueryResponse) => {
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
allow-clear />
|
||||
</a-form-item>
|
||||
<!-- 数据集 -->
|
||||
<a-form-item field="metricsId" label="数据集">
|
||||
<a-form-item field="metricsMeasurement" label="数据集">
|
||||
<a-select v-model="formModel.metricsMeasurement"
|
||||
:options="toOptions(MetricsMeasurementKey)"
|
||||
placeholder="数据集"
|
||||
|
||||
@@ -14,7 +14,7 @@ export const FalseAlarm = {
|
||||
// 告警条件 字典项
|
||||
export const TriggerConditionKey = 'alarmTriggerCondition';
|
||||
|
||||
// 告警记录处理状态 字典项
|
||||
// 告警事件处理状态 字典项
|
||||
export const HandleStatusKey = 'alarmEventHandleStatus';
|
||||
|
||||
// 是否为误报 字典项
|
||||
|
||||
@@ -30,8 +30,8 @@
|
||||
placeholder="请输入策略描述"
|
||||
allow-clear />
|
||||
</a-form-item>
|
||||
<!-- 通知模板 -->
|
||||
<a-form-item field="notifyIdList" label="通知模板">
|
||||
<!-- 通知渠道 -->
|
||||
<a-form-item field="notifyIdList" label="通知渠道">
|
||||
<notify-template-selector v-model="formModel.notifyIdList"
|
||||
biz-type="ALARM"
|
||||
multiple
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
:unmount-on-close="true"
|
||||
:ok-button-props="{ disabled: loading }"
|
||||
:cancel-button-props="{ disabled: loading }"
|
||||
:on-before-ok="handlerOk"
|
||||
:on-before-ok="handleOk"
|
||||
@cancel="handleClose">
|
||||
<a-spin class="full drawer-form-large" :loading="loading">
|
||||
<a-form :model="formModel"
|
||||
@@ -17,11 +17,12 @@
|
||||
<!-- 监控指标 -->
|
||||
<a-form-item field="metricsId" label="监控指标">
|
||||
<monitor-metrics-selector v-model="formModel.metricsId"
|
||||
class="metrics-selector"
|
||||
:class="[ hasTags ? 'metrics-selector-has-tag' : 'metrics-selector-no-tag']"
|
||||
placeholder="请选择监控指标"
|
||||
allow-clear />
|
||||
<!-- 添加标签 -->
|
||||
<a-button title="添加标签"
|
||||
<a-button v-if="hasTags"
|
||||
title="添加标签"
|
||||
:disabled="formModel.allEffect === 1"
|
||||
@click="addTag">
|
||||
<template #icon>
|
||||
@@ -34,20 +35,26 @@
|
||||
<a-form-item v-if="formModel.allEffect === 0"
|
||||
:field="'tag-' + (index + 1)"
|
||||
:label="'指标标签-' + (index + 1)">
|
||||
<a-space :size="12">
|
||||
<a-space :size="12" class="tag-wrapper">
|
||||
<!-- 标签名称 -->
|
||||
<a-input v-model="tag.key"
|
||||
style="width: 128px;"
|
||||
placeholder="指标标签名称" />
|
||||
style="width: 108px;"
|
||||
placeholder="标签名称" />
|
||||
<!-- 标签值 -->
|
||||
<a-select v-model="tag.value"
|
||||
class="tag-values"
|
||||
style="width: 260px"
|
||||
:max-tag-count="2"
|
||||
placeholder="标签值"
|
||||
tag-nowrap
|
||||
:options="measurementTags[measurement] || []"
|
||||
placeholder="输入或选择标签值"
|
||||
multiple
|
||||
allow-create />
|
||||
allow-create>
|
||||
<template #empty>
|
||||
<a-empty>
|
||||
请输入标签值
|
||||
</a-empty>
|
||||
</template>
|
||||
</a-select>
|
||||
<!-- 移除 -->
|
||||
<a-button title="移除"
|
||||
style="width: 32px"
|
||||
@@ -72,7 +79,7 @@
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<!-- 全部生效 -->
|
||||
<a-col :span="12">
|
||||
<a-col v-if="hasTags" :span="12">
|
||||
<a-form-item field="allEffect"
|
||||
label="全部生效"
|
||||
tooltip="开启后则忽略标签, 并生效与已配置标签的规则 (通常用于默认策略)"
|
||||
@@ -190,16 +197,17 @@
|
||||
import type { MetricsQueryResponse } from '@/api/monitor/metrics';
|
||||
import type { RuleTag } from '../types/const';
|
||||
import type { FormHandle } from '@/types/form';
|
||||
import { ref, computed } from 'vue';
|
||||
import { ref, computed, watch } from 'vue';
|
||||
import useLoading from '@/hooks/loading';
|
||||
import useVisible from '@/hooks/visible';
|
||||
import formRules from '../types/form.rules';
|
||||
import { MetricsUnitKey } from '../types/const';
|
||||
import { MetricsUnitKey, MeasurementKey } from '../types/const';
|
||||
import { assignOmitRecord } from '@/utils';
|
||||
import { TriggerConditionKey, LevelKey, DefaultCondition, DefaultLevel, } from '../types/const';
|
||||
import { createAlarmRule, updateAlarmRule } from '@/api/monitor/alarm-rule';
|
||||
import { Message } from '@arco-design/web-vue';
|
||||
import { useDictStore, useCacheStore } from '@/store';
|
||||
import { getMonitorHostTags } from '@/api/monitor/monitor-host';
|
||||
import MonitorMetricsSelector from '@/components/monitor/metrics/selector/index.vue';
|
||||
|
||||
const emits = defineEmits(['added', 'updated']);
|
||||
@@ -214,6 +222,9 @@
|
||||
const formRef = ref<any>();
|
||||
const formModel = ref<AlarmRuleUpdateRequest>({});
|
||||
const tags = ref<Array<RuleTag>>([]);
|
||||
const hasTags = ref(false);
|
||||
const measurement = ref('');
|
||||
const measurementTags = ref<Record<string, string[]>>({});
|
||||
|
||||
const defaultForm = (): AlarmRuleUpdateRequest => {
|
||||
return {
|
||||
@@ -223,7 +234,7 @@
|
||||
tags: undefined,
|
||||
level: DefaultLevel,
|
||||
ruleSwitch: 1,
|
||||
allEffect: 0,
|
||||
allEffect: 1,
|
||||
triggerCondition: DefaultCondition,
|
||||
threshold: undefined,
|
||||
consecutiveCount: 1,
|
||||
@@ -232,18 +243,28 @@
|
||||
};
|
||||
};
|
||||
|
||||
// 指标单位
|
||||
const metricsUnit = computed(() => {
|
||||
const metricsId = formModel.value.metricsId;
|
||||
// 检查是否有 tags
|
||||
watch(() => formModel.value.metricsId, (metricsId) => {
|
||||
if (!metricsId) {
|
||||
return '';
|
||||
hasTags.value = false;
|
||||
return;
|
||||
}
|
||||
// 读取指标单位
|
||||
const unit = (monitorMetrics as Array<MetricsQueryResponse>).find(m => m.id === metricsId)?.unit;
|
||||
if (!unit) {
|
||||
return '';
|
||||
// 获取数据集
|
||||
const measurementValue = (monitorMetrics as Array<MetricsQueryResponse> || []).find(m => m.id === metricsId)?.measurement;
|
||||
if (!measurementValue) {
|
||||
hasTags.value = false;
|
||||
return;
|
||||
}
|
||||
measurement.value = measurementValue;
|
||||
// 获取标签
|
||||
const value = getDictValue(MeasurementKey, measurementValue, 'hasTags');
|
||||
if (value === true) {
|
||||
hasTags.value = true;
|
||||
// 加载全部标签
|
||||
loadTags();
|
||||
} else {
|
||||
hasTags.value = false;
|
||||
}
|
||||
return getDictValue(MetricsUnitKey, unit, 'alarmUnit');
|
||||
});
|
||||
|
||||
// 打开新增
|
||||
@@ -284,7 +305,8 @@
|
||||
|
||||
// 添加标签
|
||||
const addTag = () => {
|
||||
tags.value.push({ key: '', value: [] });
|
||||
const hasNameTag = tags.value.some(s => s.key === 'name');
|
||||
tags.value.push({ key: hasNameTag ? '' : 'name', value: [] });
|
||||
};
|
||||
|
||||
// 移除标签
|
||||
@@ -292,8 +314,37 @@
|
||||
tags.value.splice(index, 1);
|
||||
};
|
||||
|
||||
// 指标单位
|
||||
const metricsUnit = computed(() => {
|
||||
const metricsId = formModel.value.metricsId;
|
||||
if (!metricsId) {
|
||||
return '';
|
||||
}
|
||||
// 读取指标单位
|
||||
const unit = (monitorMetrics as Array<MetricsQueryResponse> || []).find(m => m.id === metricsId)?.unit;
|
||||
if (!unit) {
|
||||
return '';
|
||||
}
|
||||
return getDictValue(MetricsUnitKey, unit, 'alarmUnit');
|
||||
});
|
||||
|
||||
// 加载全部标签
|
||||
const loadTags = () => {
|
||||
const tags = measurementTags.value[measurement.value];
|
||||
if (tags) {
|
||||
return;
|
||||
}
|
||||
// 加载标签
|
||||
getMonitorHostTags({
|
||||
measurement: measurement.value,
|
||||
policyId: formModel.value.policyId,
|
||||
}).then(({ data }) => {
|
||||
measurementTags.value[measurement.value as any] = data;
|
||||
});
|
||||
};
|
||||
|
||||
// 确定
|
||||
const handlerOk = async () => {
|
||||
const handleOk = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
// 验证参数
|
||||
@@ -301,21 +352,37 @@
|
||||
if (error) {
|
||||
return false;
|
||||
}
|
||||
for (let tag of tags.value) {
|
||||
if (!tag.key) {
|
||||
Message.error('请输入标签名称');
|
||||
return false;
|
||||
}
|
||||
if (!tag.value) {
|
||||
Message.error('请输入标签值');
|
||||
return false;
|
||||
if (!hasTags.value) {
|
||||
// 无 tag
|
||||
formModel.value.allEffect = 1;
|
||||
} else {
|
||||
// 有 tag
|
||||
if (formModel.value.allEffect === 1) {
|
||||
// 全部生效
|
||||
tags.value = [];
|
||||
} else {
|
||||
// 检查 tag
|
||||
if (!tags.value.length) {
|
||||
Message.error('请选择全部生效或添加对应的标签');
|
||||
return false;
|
||||
}
|
||||
for (let tag of tags.value) {
|
||||
if (!tag.key) {
|
||||
Message.error('请输入标签名称');
|
||||
return false;
|
||||
}
|
||||
if (!tag.value) {
|
||||
Message.error('请输入标签值');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (formHandle.value == 'add') {
|
||||
// 新增
|
||||
await createAlarmRule({
|
||||
...formModel.value,
|
||||
tags: formModel.value.allEffect === 1 ? '[]' : JSON.stringify(tags.value)
|
||||
tags: JSON.stringify(tags.value)
|
||||
});
|
||||
Message.success('创建成功');
|
||||
emits('added');
|
||||
@@ -323,13 +390,13 @@
|
||||
// 修改
|
||||
await updateAlarmRule({
|
||||
...formModel.value,
|
||||
tags: formModel.value.allEffect === 1 ? '[]' : JSON.stringify(tags.value)
|
||||
tags: JSON.stringify(tags.value)
|
||||
});
|
||||
Message.success('修改成功');
|
||||
emits('updated');
|
||||
}
|
||||
// 清空
|
||||
handlerClear();
|
||||
handleClose();
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
} finally {
|
||||
@@ -339,22 +406,32 @@
|
||||
|
||||
// 关闭
|
||||
const handleClose = () => {
|
||||
handlerClear();
|
||||
handleClear();
|
||||
setVisible(false);
|
||||
};
|
||||
|
||||
// 清空
|
||||
const handlerClear = () => {
|
||||
const handleClear = () => {
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
:deep(.metrics-selector) {
|
||||
:deep(.metrics-selector-no-tag) {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
:deep(.metrics-selector-has-tag) {
|
||||
width: calc(100% - 42px);
|
||||
margin-right: 12px;
|
||||
}
|
||||
|
||||
.tag-wrapper {
|
||||
width: 100%;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.alarm-level-select, .condition-select {
|
||||
|
||||
:deep(.arco-select-view-suffix) {
|
||||
@@ -365,4 +442,5 @@
|
||||
:deep(.tag-values .arco-select-view-inner) {
|
||||
flex-wrap: nowrap !important;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
@@ -203,7 +203,7 @@
|
||||
|
||||
// 获取指标名称
|
||||
const getMetricsField = (metricsId: number, field: string) => {
|
||||
return (monitorMetrics as Array<MetricsQueryResponse>).find(m => m.id === metricsId)?.[field];
|
||||
return (monitorMetrics as Array<MetricsQueryResponse> || []).find(m => m.id === metricsId)?.[field];
|
||||
};
|
||||
|
||||
// 切换规则开关
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
allow-clear />
|
||||
</a-form-item>
|
||||
<!-- 数据集 -->
|
||||
<a-form-item field="metricsId" label="数据集">
|
||||
<a-form-item field="metricsMeasurement" label="数据集">
|
||||
<a-select v-model="formModel.metricsMeasurement"
|
||||
:options="toOptions(MetricsMeasurementKey)"
|
||||
placeholder="数据集"
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
:hide-content="true">
|
||||
<a-tab-pane :key="TabKeys.OVERVIEW" title="主机概览" />
|
||||
<a-tab-pane :key="TabKeys.CHART" title="监控图表" />
|
||||
<a-tab-pane :key="TabKeys.ALARM" title="告警记录" />
|
||||
<a-tab-pane :key="TabKeys.ALARM" title="告警事件" />
|
||||
</a-tabs>
|
||||
<a-divider direction="vertical"
|
||||
style="height: 22px; margin: 0 16px 0 8px;"
|
||||
@@ -42,7 +42,7 @@
|
||||
</div>
|
||||
<!-- 右侧 -->
|
||||
<div class="header-right">
|
||||
<!-- 告警记录标签 -->
|
||||
<!-- 告警事件标签 -->
|
||||
<div v-if="activeKey === TabKeys.OVERVIEW" class="handle-wrapper">
|
||||
<a-tag v-if="overrideTimestamp">更新时间: {{ dateFormat(new Date(overrideTimestamp)) }}</a-tag>
|
||||
</div>
|
||||
|
||||
@@ -189,6 +189,7 @@
|
||||
return createTimeSeries({
|
||||
name: s.name,
|
||||
type: props.option.type,
|
||||
smooth: props.option.smooth,
|
||||
area: props.option.background,
|
||||
lineColor: colors?.[0],
|
||||
itemBorderColor: colors?.[1],
|
||||
|
||||
@@ -19,6 +19,7 @@ export interface MetricsChartOption {
|
||||
span?: number;
|
||||
legend?: boolean;
|
||||
background?: boolean;
|
||||
smooth?: boolean;
|
||||
colors: Array<[string, string]>;
|
||||
aggregate: string;
|
||||
unit: MetricUnitType;
|
||||
|
||||
@@ -177,6 +177,9 @@
|
||||
if (type === ValueType.BOOLEAN) {
|
||||
extraValue.value[nameKey] = false;
|
||||
continue;
|
||||
} else if (type === ValueType.STRING) {
|
||||
extraValue.value[nameKey] = '';
|
||||
continue;
|
||||
}
|
||||
formRef.value.setFields({
|
||||
[nameKey]: {
|
||||
|
||||
@@ -90,7 +90,7 @@
|
||||
padding: 16px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
border-radius: 4px;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
:deep(.arco-tabs-nav-tab-list) {
|
||||
|
||||
@@ -117,7 +117,7 @@
|
||||
padding: 16px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
border-radius: 4px;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
:deep(.arco-tabs-nav-tab-list) {
|
||||
|
||||
Reference in New Issue
Block a user