🔨 修改标签查询逻辑.

This commit is contained in:
lijiahangmax
2025-10-07 16:06:00 +08:00
parent 1d5c579e64
commit 963cd0b227
15 changed files with 97 additions and 112 deletions

View File

@@ -48,10 +48,10 @@ public interface HostAgentApi {
/** /**
* 获取缓存名称 * 获取缓存名称
* *
* @param agentKeyList agentKeyList * @param agentKeys agentKeys
* @return nameMap * @return nameMap
*/ */
Map<String, String> getNameCacheByAgentKey(List<String> agentKeyList); Map<String, String> getNameCacheByAgentKey(List<String> agentKeys);
/** /**
* 获取缓存名称 * 获取缓存名称

View File

@@ -103,11 +103,11 @@ public class HostAgentApiImpl implements HostAgentApi {
} }
@Override @Override
public Map<String, String> getNameCacheByAgentKey(List<String> agentKeyList) { public Map<String, String> getNameCacheByAgentKey(List<String> agentKeys) {
Map<String, String> result = new HashMap<>(); Map<String, String> result = new HashMap<>();
List<String> queryList = new ArrayList<>(); List<String> queryList = new ArrayList<>();
// 查询缓存 // 查询缓存
for (String agentKey : agentKeyList) { for (String agentKey : agentKeys) {
HostBaseDTO host = AGENT_HOST_CACHE.get(agentKey); HostBaseDTO host = AGENT_HOST_CACHE.get(agentKey);
if (host != null) { if (host != null) {
result.put(agentKey, host.getName()); result.put(agentKey, host.getName());

View File

@@ -92,14 +92,14 @@ public interface HostDAO extends IMapper<HostDO> {
/** /**
* 更新探针信息 * 更新探针信息
* *
* @param keys agentKeyList * @param agentKeys agentKeys
* @param update update * @param update update
* @return effect * @return effect
*/ */
default int updateByAgentKeys(List<String> keys, HostDO update) { default int updateByAgentKeys(List<String> agentKeys, HostDO update) {
update.setUpdateTime(new Date()); update.setUpdateTime(new Date());
// 更新 // 更新
return this.update(update, Conditions.in(HostDO::getAgentKey, keys)); return this.update(update, Conditions.in(HostDO::getAgentKey, agentKeys));
} }
} }

View File

@@ -212,25 +212,25 @@ public class HostAgentEndpointServiceImpl implements HostAgentEndpointService {
/** /**
* 标记在线状态 * 标记在线状态
* *
* @param agentKeyList agentKeyList * @param agentKeys agentKeys
* @param status status * @param status status
*/ */
private void markOnlineStatus(List<String> agentKeyList, AgentOnlineStatusEnum status) { private void markOnlineStatus(List<String> agentKeys, AgentOnlineStatusEnum status) {
if (Lists.isEmpty(agentKeyList)) { if (Lists.isEmpty(agentKeys)) {
return; 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() HostDO update = HostDO.builder()
.agentOnlineStatus(status.getValue()) .agentOnlineStatus(status.getValue())
.agentOnlineChangeTime(new Date()) .agentOnlineChangeTime(new Date())
.build(); .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); log.info("HostAgentEndpointService mark {}. effect: {}", status, effect);
// 插入日志 // 插入日志
List<HostAgentLogDO> logList = hostDAO.selectIdByAgentKeys(agentKeyList) List<HostAgentLogDO> logList = hostDAO.selectIdByAgentKeys(agentKeys)
.stream() .stream()
.map(s -> { .map(s -> {
HostAgentLogDO agentLog = HostAgentLogDO.builder() HostAgentLogDO agentLog = HostAgentLogDO.builder()
@@ -250,7 +250,7 @@ public class HostAgentEndpointServiceImpl implements HostAgentEndpointService {
} }
// 发送已下线事件 // 发送已下线事件
if (AgentOnlineStatusEnum.OFFLINE.equals(status)) { if (AgentOnlineStatusEnum.OFFLINE.equals(status)) {
SpringHolder.publishEvent(new AgentOfflineEvent(agentKeyList)); SpringHolder.publishEvent(new AgentOfflineEvent(agentKeys));
} }
} }

View File

@@ -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.define.operator.MonitorHostOperatorType;
import org.dromara.visor.module.monitor.engine.MonitorContext; import org.dromara.visor.module.monitor.engine.MonitorContext;
import org.dromara.visor.module.monitor.entity.dto.AgentMetricsDataDTO; 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.*;
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.vo.MonitorHostMetricsDataVO; import org.dromara.visor.module.monitor.entity.vo.MonitorHostMetricsDataVO;
import org.dromara.visor.module.monitor.entity.vo.MonitorHostVO; import org.dromara.visor.module.monitor.entity.vo.MonitorHostVO;
import org.dromara.visor.module.monitor.service.MonitorHostService; import org.dromara.visor.module.monitor.service.MonitorHostService;
@@ -95,7 +92,7 @@ public class MonitorHostController {
@Operation(summary = "查询监控指标") @Operation(summary = "查询监控指标")
@PreAuthorize("@ss.hasPermission('monitor:monitor-host:query')") @PreAuthorize("@ss.hasPermission('monitor:monitor-host:query')")
public List<MonitorHostMetricsDataVO> getMonitorHostMetrics(@Validated(Key.class) @RequestBody MonitorHostQueryRequest request) { public List<MonitorHostMetricsDataVO> getMonitorHostMetrics(@Validated(Key.class) @RequestBody MonitorHostQueryRequest request) {
return monitorHostService.getMonitorHostMetrics(request.getAgentKeyList()); return monitorHostService.getMonitorHostMetrics(request.getAgentKeys());
} }
@IgnoreLog(IgnoreLogMode.RET) @IgnoreLog(IgnoreLogMode.RET)
@@ -107,14 +104,11 @@ public class MonitorHostController {
} }
@IgnoreLog(IgnoreLogMode.RET) @IgnoreLog(IgnoreLogMode.RET)
@GetMapping("/host-tags") @PostMapping("/host-tags")
@Operation(summary = "查询监控告警标签") @Operation(summary = "查询监控告警标签")
@Parameter(name = "policyId", description = "policyId", required = true)
@Parameter(name = "measurement", description = "measurement")
@PreAuthorize("@ss.hasPermission('monitor:monitor-host:query')") @PreAuthorize("@ss.hasPermission('monitor:monitor-host:query')")
public List<String> getMonitorHostPolicyRuleTags(@RequestParam("policyId") Long policyId, public List<String> getMonitorHostTags(@RequestBody MonitorHostQueryTagRequest request) {
@RequestParam(value = "measurement", required = false) String measurement) { return monitorHostService.getMonitorHostTags(request);
return monitorHostService.getMonitorHostPolicyRuleTags(policyId, measurement);
} }
@DemoDisableApi @DemoDisableApi

View File

@@ -46,7 +46,7 @@ public class MonitorHostQueryRequest extends BaseQueryRequest {
@NotEmpty(groups = Key.class) @NotEmpty(groups = Key.class)
@Schema(description = "agentKey") @Schema(description = "agentKey")
private List<String> agentKeyList; private List<String> agentKeys;
@Schema(description = "搜索") @Schema(description = "搜索")
private String searchValue; private String searchValue;

View File

@@ -20,29 +20,34 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.dromara.visor.module.monitor.define.cache; package org.dromara.visor.module.monitor.entity.request.host;
import cn.orionsec.kit.lang.define.cache.key.CacheKeyBuilder; import io.swagger.v3.oas.annotations.media.Schema;
import cn.orionsec.kit.lang.define.cache.key.CacheKeyDefine; import lombok.Data;
import cn.orionsec.kit.lang.define.cache.key.struct.RedisCacheStruct; import lombok.EqualsAndHashCode;
import org.dromara.visor.common.entity.BaseQueryRequest;
import java.util.concurrent.TimeUnit; import java.util.List;
/** /**
* 监控主机缓存 key * 监控主机标签 查询请求对象
* *
* @author Jiahang Li * @author Jiahang Li
* @version 1.0.0 * @version 1.0.0
* @since 2025-9-14 00:12 * @since 2025-8-14 16:27
*/ */
public interface MonitorHostCacheKeyDefine { @Data
@EqualsAndHashCode(callSuper = true)
@Schema(name = "MonitorHostQueryTagRequest", description = "监控主机标签 查询请求对象")
public class MonitorHostQueryTagRequest extends BaseQueryRequest {
CacheKeyDefine MONITOR_HOST_POLICY_HOST_TAGS = new CacheKeyBuilder() @Schema(description = "数据集")
.key("monitor:host:policy:host-tags:{}") private String measurement;
.desc("告警规则沉默标志 ${policyId}")
.type(String.class) @Schema(description = "策略id")
.struct(RedisCacheStruct.HASH) private Long policyId;
.timeout(8, TimeUnit.HOURS)
.build(); @Schema(description = "agentKey")
private List<String> agentKeys;
} }

View File

@@ -24,10 +24,7 @@ package org.dromara.visor.module.monitor.service;
import cn.orionsec.kit.lang.define.wrapper.DataGrid; import cn.orionsec.kit.lang.define.wrapper.DataGrid;
import org.dromara.visor.common.entity.chart.TimeChartSeries; 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.*;
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.vo.MonitorHostMetricsDataVO; import org.dromara.visor.module.monitor.entity.vo.MonitorHostMetricsDataVO;
import org.dromara.visor.module.monitor.entity.vo.MonitorHostVO; import org.dromara.visor.module.monitor.entity.vo.MonitorHostVO;
@@ -53,10 +50,10 @@ public interface MonitorHostService {
/** /**
* 获取监控主机指标数据 * 获取监控主机指标数据
* *
* @param agentKeyList agentKeyList * @param agentKeys agentKeys
* @return metrics * @return metrics
*/ */
List<MonitorHostMetricsDataVO> getMonitorHostMetrics(List<String> agentKeyList); List<MonitorHostMetricsDataVO> getMonitorHostMetrics(List<String> agentKeys);
/** /**
* 获取监控主机图表数据 * 获取监控主机图表数据
@@ -67,13 +64,12 @@ public interface MonitorHostService {
List<TimeChartSeries> getMonitorHostChart(MonitorHostChartRequest request); List<TimeChartSeries> getMonitorHostChart(MonitorHostChartRequest request);
/** /**
* 查询监控告警规则主机标签 * 查询监控告警标签
* *
* @param policyId policyId * @param request request
* @param measurement measurement
* @return tags * @return tags
*/ */
List<String> getMonitorHostPolicyRuleTags(Long policyId, String measurement); List<String> getMonitorHostTags(MonitorHostQueryTagRequest request);
/** /**
* 更新监控主机 * 更新监控主机

View File

@@ -35,12 +35,10 @@ import org.dromara.visor.common.constant.ErrorMessage;
import org.dromara.visor.common.utils.Assert; import org.dromara.visor.common.utils.Assert;
import org.dromara.visor.common.utils.LockerUtils; import org.dromara.visor.common.utils.LockerUtils;
import org.dromara.visor.framework.influxdb.core.utils.InfluxdbUtils; import org.dromara.visor.framework.influxdb.core.utils.InfluxdbUtils;
import org.dromara.visor.framework.redis.core.utils.RedisMaps;
import org.dromara.visor.module.asset.api.HostApi; import org.dromara.visor.module.asset.api.HostApi;
import org.dromara.visor.module.asset.entity.dto.host.HostDTO; import org.dromara.visor.module.asset.entity.dto.host.HostDTO;
import org.dromara.visor.module.infra.api.SystemUserApi; import org.dromara.visor.module.infra.api.SystemUserApi;
import org.dromara.visor.module.monitor.dao.MonitorHostDAO; import org.dromara.visor.module.monitor.dao.MonitorHostDAO;
import org.dromara.visor.module.monitor.define.cache.MonitorHostCacheKeyDefine;
import org.dromara.visor.module.monitor.engine.AlarmEngine; import org.dromara.visor.module.monitor.engine.AlarmEngine;
import org.dromara.visor.module.monitor.engine.MonitorContext; import org.dromara.visor.module.monitor.engine.MonitorContext;
import org.dromara.visor.module.monitor.entity.domain.MonitorHostDO; import org.dromara.visor.module.monitor.entity.domain.MonitorHostDO;
@@ -148,11 +146,6 @@ public class MonitorAgentEndpointServiceImpl implements MonitorAgentEndpointServ
update.setMonitorConfig(JSON.toJSONString(newConfig)); update.setMonitorConfig(JSON.toJSONString(newConfig));
} }
monitorHostDAO.updateById(update); monitorHostDAO.updateById(update);
// 删除元数据缓存
Long policyId = monitorHost.getPolicyId();
if (policyId != null) {
RedisMaps.delete(MonitorHostCacheKeyDefine.MONITOR_HOST_POLICY_HOST_TAGS.format(policyId));
}
} }
// 重新加载监控主机上下文 // 重新加载监控主机上下文
if (newConfig != null) { if (newConfig != null) {

View File

@@ -40,7 +40,6 @@ import org.dromara.visor.framework.biz.operator.log.core.utils.OperatorLogs;
import org.dromara.visor.framework.influxdb.core.query.FluxQueryBuilder; import org.dromara.visor.framework.influxdb.core.query.FluxQueryBuilder;
import org.dromara.visor.framework.influxdb.core.utils.InfluxdbUtils; import org.dromara.visor.framework.influxdb.core.utils.InfluxdbUtils;
import org.dromara.visor.framework.mybatis.core.query.Conditions; import org.dromara.visor.framework.mybatis.core.query.Conditions;
import org.dromara.visor.framework.redis.core.utils.RedisMaps;
import org.dromara.visor.module.asset.api.HostAgentApi; import org.dromara.visor.module.asset.api.HostAgentApi;
import org.dromara.visor.module.asset.api.HostApi; import org.dromara.visor.module.asset.api.HostApi;
import org.dromara.visor.module.asset.entity.dto.host.HostAgentLogDTO; import org.dromara.visor.module.asset.entity.dto.host.HostAgentLogDTO;
@@ -52,15 +51,11 @@ import org.dromara.visor.module.monitor.constant.MetricsConst;
import org.dromara.visor.module.monitor.convert.MonitorHostConvert; import org.dromara.visor.module.monitor.convert.MonitorHostConvert;
import org.dromara.visor.module.monitor.dao.AlarmPolicyDAO; import org.dromara.visor.module.monitor.dao.AlarmPolicyDAO;
import org.dromara.visor.module.monitor.dao.MonitorHostDAO; import org.dromara.visor.module.monitor.dao.MonitorHostDAO;
import org.dromara.visor.module.monitor.define.cache.MonitorHostCacheKeyDefine;
import org.dromara.visor.module.monitor.engine.MonitorContext; 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.AlarmPolicyDO;
import org.dromara.visor.module.monitor.entity.domain.MonitorHostDO; import org.dromara.visor.module.monitor.entity.domain.MonitorHostDO;
import org.dromara.visor.module.monitor.entity.dto.*; 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.*;
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.vo.MonitorHostMetricsDataVO; import org.dromara.visor.module.monitor.entity.vo.MonitorHostMetricsDataVO;
import org.dromara.visor.module.monitor.entity.vo.MonitorHostVO; import org.dromara.visor.module.monitor.entity.vo.MonitorHostVO;
import org.dromara.visor.module.monitor.enums.AlarmSwitchEnum; import org.dromara.visor.module.monitor.enums.AlarmSwitchEnum;
@@ -76,7 +71,6 @@ import java.util.function.BiFunction;
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;
import java.util.stream.Stream;
/** /**
* 监控主机 服务实现类 * 监控主机 服务实现类
@@ -191,8 +185,8 @@ public class MonitorHostServiceImpl implements MonitorHostService {
} }
@Override @Override
public List<MonitorHostMetricsDataVO> getMonitorHostMetrics(List<String> agentKeyList) { public List<MonitorHostMetricsDataVO> getMonitorHostMetrics(List<String> agentKeys) {
return agentKeyList.stream() return agentKeys.stream()
.map(s -> this.getHostMetricsData(s, null)) .map(s -> this.getHostMetricsData(s, null))
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
@@ -239,25 +233,11 @@ public class MonitorHostServiceImpl implements MonitorHostService {
} }
@Override @Override
public List<String> getMonitorHostPolicyRuleTags(Long policyId, String measurement) { public List<String> getMonitorHostTags(MonitorHostQueryTagRequest request) {
MeasurementEnum measurementEnum = MeasurementEnum.of(measurement); MeasurementEnum measurementEnum = MeasurementEnum.of(request.getMeasurement());
if (measurementEnum == null) { if (measurementEnum == null) {
return Collections.emptyList(); return Collections.emptyList();
} }
// 查询缓存
String cacheKey = MonitorHostCacheKeyDefine.MONITOR_HOST_POLICY_HOST_TAGS.format(policyId);
String value = RedisMaps.get(cacheKey, measurement);
if (!Strings.isBlank(value)) {
return JSON.parseArray(value, String.class);
}
// 查询规则下的全部主机
List<MonitorHostMetaDTO> metas = monitorHostDAO.selectByPolicyId(policyId)
.stream()
.map(MonitorHostDO::getMonitorMeta)
.filter(Objects::nonNull)
.map(s -> JSON.parseObject(s, MonitorHostMetaDTO.class))
.filter(Objects::nonNull)
.collect(Collectors.toList());
// 映射数据 // 映射数据
Function<MonitorHostMetaDTO, List<String>> tagsGetter; Function<MonitorHostMetaDTO, List<String>> tagsGetter;
if (MeasurementEnum.CPU.equals(measurementEnum)) { if (MeasurementEnum.CPU.equals(measurementEnum)) {
@@ -269,15 +249,25 @@ public class MonitorHostServiceImpl implements MonitorHostService {
} else { } else {
return Collections.emptyList(); return Collections.emptyList();
} }
List<String> tags = metas.stream() // 查询监控主机元数据
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) .map(tagsGetter)
.flatMap(Collection::stream) .flatMap(Collection::stream)
.filter(Objects::nonNull) .filter(Objects::nonNull)
.distinct() .distinct()
.collect(Collectors.toList()); .collect(Collectors.toList());
// 设置缓存
RedisMaps.putJson(cacheKey, MonitorHostCacheKeyDefine.MONITOR_HOST_POLICY_HOST_TAGS, measurement, tags);
return tags;
} }
@Override @Override
@@ -317,14 +307,6 @@ public class MonitorHostServiceImpl implements MonitorHostService {
if (policyId == null) { if (policyId == null) {
monitorHostDAO.setPolicyIdWithNullById(id); monitorHostDAO.setPolicyIdWithNullById(id);
} }
// 删除元数据缓存
List<String> tagsCacheKeyList = Stream.of(policyId, monitorHost.getPolicyId())
.filter(Objects::nonNull)
.map(MonitorHostCacheKeyDefine.MONITOR_HOST_POLICY_HOST_TAGS::format)
.collect(Collectors.toList());
if (!tagsCacheKeyList.isEmpty()) {
RedisMaps.delete(tagsCacheKeyList);
}
// 重新加载监控主机上下文 // 重新加载监控主机上下文
monitorContext.reloadMonitorHost(host.getAgentKey()); monitorContext.reloadMonitorHost(host.getAgentKey());
log.info("MonitorHostService-updateMonitorHostById effect: {}", effect); log.info("MonitorHostService-updateMonitorHostById effect: {}", effect);

View File

@@ -28,7 +28,7 @@ export interface MonitorHostSwitchUpdateRequest {
* 监控主机查询请求 * 监控主机查询请求
*/ */
export interface MonitorHostQueryRequest extends Pagination { export interface MonitorHostQueryRequest extends Pagination {
agentKeyList?: Array<string>; agentKeys?: Array<string>;
searchValue?: string; searchValue?: string;
alarmSwitch?: number; alarmSwitch?: number;
policyId?: number; policyId?: number;
@@ -43,6 +43,15 @@ export interface MonitorHostQueryRequest extends Pagination {
tags?: Array<number>; 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', { return axios.post<Array<MonitorHostMetricsData>>('/monitor/monitor-host/metrics', {
agentKeyList agentKeys
}, { }, {
promptBizErrorMessage: false, promptBizErrorMessage: false,
promptRequestErrorMessage: false, promptRequestErrorMessage: false
}); });
} }
@@ -178,10 +187,10 @@ export function getMonitorHostPage(request: MonitorHostQueryRequest) {
} }
/** /**
* 查询监控告警标签 * 查询监控主机标签
*/ */
export function getMonitorHostPolicyRuleTags(policyId: number, measurement: string = '') { export function getMonitorHostTags(request: MonitorHostQueryTagRequest) {
return axios.get<Array<string>>('/monitor/monitor-host/host-tags', { params: { policyId, measurement } }); return axios.post<Array<string>>('/monitor/monitor-host/host-tags', request);
} }
/** /**

View File

@@ -17,6 +17,7 @@ export interface TimeSeriesColor {
export interface TimeSeriesOption { export interface TimeSeriesOption {
name: string; name: string;
type: TimeSeriesType; type: TimeSeriesType;
smooth: boolean;
area: boolean; area: boolean;
lineColor: string; lineColor: string;
itemBorderColor: string; itemBorderColor: string;
@@ -126,7 +127,7 @@ export const createTimeSeries = (option: Partial<TimeSeriesOption>): LineSeriesO
name: option.name, name: option.name,
data: option.data || [], data: option.data || [],
type: option.type || 'line', type: option.type || 'line',
smooth: true, smooth: option.smooth ?? true,
symbol: 'circle', symbol: 'circle',
symbolSize: 10, symbolSize: 10,
itemStyle: { itemStyle: {

View File

@@ -45,7 +45,7 @@
class="tag-values" class="tag-values"
style="width: 260px" style="width: 260px"
:max-tag-count="2" :max-tag-count="2"
:options="[measurement] || []" :options="measurementTags[measurement] || []"
placeholder="输入或选择标签值" placeholder="输入或选择标签值"
multiple multiple
allow-create> allow-create>
@@ -207,7 +207,7 @@
import { createAlarmRule, updateAlarmRule } from '@/api/monitor/alarm-rule'; import { createAlarmRule, updateAlarmRule } from '@/api/monitor/alarm-rule';
import { Message } from '@arco-design/web-vue'; import { Message } from '@arco-design/web-vue';
import { useDictStore, useCacheStore } from '@/store'; import { useDictStore, useCacheStore } from '@/store';
import { getMonitorHostPolicyRuleTags } from '@/api/monitor/monitor-host'; import { getMonitorHostTags } from '@/api/monitor/monitor-host';
import MonitorMetricsSelector from '@/components/monitor/metrics/selector/index.vue'; import MonitorMetricsSelector from '@/components/monitor/metrics/selector/index.vue';
const emits = defineEmits(['added', 'updated']); const emits = defineEmits(['added', 'updated']);
@@ -224,7 +224,7 @@
const tags = ref<Array<RuleTag>>([]); const tags = ref<Array<RuleTag>>([]);
const hasTags = ref(false); const hasTags = ref(false);
const measurement = ref(''); const measurement = ref('');
const = ref<Record<string, string[]>>({}); const measurementTags = ref<Record<string, string[]>>({});
const defaultForm = (): AlarmRuleUpdateRequest => { const defaultForm = (): AlarmRuleUpdateRequest => {
return { return {
@@ -330,13 +330,16 @@
// 加载全部标签 // 加载全部标签
const loadTags = () => { const loadTags = () => {
const tags = .value[measurement.value]; const tags = measurementTags.value[measurement.value];
if (tags) { if (tags) {
return; return;
} }
// 加载标签 // 加载标签
getMonitorHostPolicyRuleTags(formModel.value.policyId as number, measurement.value).then(({ data }) => { getMonitorHostTags({
.value[measurement.value as any] = data; measurement: measurement.value,
policyId: formModel.value.policyId,
}).then(({ data }) => {
measurementTags.value[measurement.value as any] = data;
}); });
}; };

View File

@@ -189,6 +189,7 @@
return createTimeSeries({ return createTimeSeries({
name: s.name, name: s.name,
type: props.option.type, type: props.option.type,
smooth: props.option.smooth,
area: props.option.background, area: props.option.background,
lineColor: colors?.[0], lineColor: colors?.[0],
itemBorderColor: colors?.[1], itemBorderColor: colors?.[1],

View File

@@ -19,6 +19,7 @@ export interface MetricsChartOption {
span?: number; span?: number;
legend?: boolean; legend?: boolean;
background?: boolean; background?: boolean;
smooth?: boolean;
colors: Array<[string, string]>; colors: Array<[string, string]>;
aggregate: string; aggregate: string;
unit: MetricUnitType; unit: MetricUnitType;