🔨 修改 influx 查询语句.

This commit is contained in:
lijiahangmax
2025-10-06 16:18:20 +08:00
parent 29e6db75ca
commit d58d46ca8c
4 changed files with 19 additions and 31 deletions

View File

@@ -24,6 +24,7 @@ package org.dromara.visor.framework.influxdb.core.query;
import cn.orionsec.kit.lang.utils.collect.Collections;
import cn.orionsec.kit.lang.utils.collect.Lists;
import cn.orionsec.kit.lang.utils.collect.Maps;
import org.dromara.visor.common.constant.Const;
import java.time.Instant;
@@ -194,7 +195,7 @@ public class FluxQueryBuilder {
if (values.size() == 1) {
return this.tag(key, Collections.first(values));
}
//
// 使用 or 拼接
Collection<String> conditions = values.stream()
.map(value -> String.format("r[\"%s\"] == \"%s\"", key, value))
.collect(Collectors.toList());
@@ -204,33 +205,18 @@ public class FluxQueryBuilder {
}
/**
* 过滤多个 tag
* tag 使用 and
* value 使用 or
* 过滤 tag
*
* @param tags tags
* @return this
*/
public FluxQueryBuilder tags(Map<String, ? extends Collection<String>> tags) {
for (Map.Entry<String, ? extends Collection<String>> entry : tags.entrySet()) {
String key = entry.getKey();
Collection<String> values = entry.getValue();
if (Collections.isEmpty(values)) {
continue;
}
if (values.size() == 1) {
// 单值直接用等号
String singleValue = values.iterator().next();
this.appendFilter(String.format("r[\"%s\"] == \"%s\"", key, singleValue));
} else {
// 多值用 OR
Collection<String> conditions = values.stream()
.map(v -> String.format("r[\"%s\"] == \"%s\"", key, v))
.collect(Collectors.toList());
this.appendFilter("(" + String.join(" or ", conditions) + ")");
}
if (Maps.isEmpty(tags)) {
return this;
}
for (Map.Entry<String, ? extends Collection<String>> entry : tags.entrySet()) {
this.tag(entry.getKey(), entry.getValue());
}
this.closeFilter();
return this;
}

View File

@@ -59,17 +59,17 @@ public class MonitorHostChartRequest extends BaseQueryRequest {
@Schema(description = "时间窗口")
private String window;
@Schema(description = "时间区间")
private String range;
@Schema(description = "时间区间")
private Long start;
@Schema(description = "时间区间")
private Long end;
@NotBlank
@Schema(description = "聚合参数")
private String aggregate;
@Schema(description = "聚合参数")
private Long start;
@Schema(description = "聚合参数")
private Long end;
@Schema(description = "区间")
private String range;
}

View File

@@ -372,6 +372,7 @@ public class MonitorHostServiceImpl implements MonitorHostService {
} else {
Assert.notNull(request.getStart(), ErrorMessage.PARAM_MISSING);
Assert.notNull(request.getEnd(), ErrorMessage.PARAM_MISSING);
query.range(request.getStart(), request.getEnd());
}
// 设置名称
Set<String> names = null;

View File

@@ -70,6 +70,7 @@
animation: false,
tooltip: {
trigger: 'axis',
appendToBody: true,
backgroundColor: 'rgba(255, 255, 255, 0.9)',
textStyle: {
color: 'rgba(0, 0, 0, 0.8)',