🔨 修改 influx 查询语句.
This commit is contained in:
@@ -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.Collections;
|
||||||
import cn.orionsec.kit.lang.utils.collect.Lists;
|
import cn.orionsec.kit.lang.utils.collect.Lists;
|
||||||
|
import cn.orionsec.kit.lang.utils.collect.Maps;
|
||||||
import org.dromara.visor.common.constant.Const;
|
import org.dromara.visor.common.constant.Const;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
@@ -194,7 +195,7 @@ public class FluxQueryBuilder {
|
|||||||
if (values.size() == 1) {
|
if (values.size() == 1) {
|
||||||
return this.tag(key, Collections.first(values));
|
return this.tag(key, Collections.first(values));
|
||||||
}
|
}
|
||||||
//
|
// 使用 or 拼接
|
||||||
Collection<String> conditions = values.stream()
|
Collection<String> conditions = values.stream()
|
||||||
.map(value -> String.format("r[\"%s\"] == \"%s\"", key, value))
|
.map(value -> String.format("r[\"%s\"] == \"%s\"", key, value))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
@@ -204,33 +205,18 @@ public class FluxQueryBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 过滤多个 tag
|
* 过滤 tag
|
||||||
* tag 使用 and
|
|
||||||
* value 使用 or
|
|
||||||
*
|
*
|
||||||
* @param tags tags
|
* @param tags tags
|
||||||
* @return this
|
* @return this
|
||||||
*/
|
*/
|
||||||
public FluxQueryBuilder tags(Map<String, ? extends Collection<String>> tags) {
|
public FluxQueryBuilder tags(Map<String, ? extends Collection<String>> tags) {
|
||||||
|
if (Maps.isEmpty(tags)) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
for (Map.Entry<String, ? extends Collection<String>> entry : tags.entrySet()) {
|
for (Map.Entry<String, ? extends Collection<String>> entry : tags.entrySet()) {
|
||||||
String key = entry.getKey();
|
this.tag(entry.getKey(), entry.getValue());
|
||||||
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) + ")");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.closeFilter();
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,17 +59,17 @@ public class MonitorHostChartRequest extends BaseQueryRequest {
|
|||||||
@Schema(description = "时间窗口")
|
@Schema(description = "时间窗口")
|
||||||
private String window;
|
private String window;
|
||||||
|
|
||||||
|
@Schema(description = "时间区间")
|
||||||
|
private String range;
|
||||||
|
|
||||||
|
@Schema(description = "时间区间")
|
||||||
|
private Long start;
|
||||||
|
|
||||||
|
@Schema(description = "时间区间")
|
||||||
|
private Long end;
|
||||||
|
|
||||||
@NotBlank
|
@NotBlank
|
||||||
@Schema(description = "聚合参数")
|
@Schema(description = "聚合参数")
|
||||||
private String aggregate;
|
private String aggregate;
|
||||||
|
|
||||||
@Schema(description = "聚合参数")
|
|
||||||
private Long start;
|
|
||||||
|
|
||||||
@Schema(description = "聚合参数")
|
|
||||||
private Long end;
|
|
||||||
|
|
||||||
@Schema(description = "区间")
|
|
||||||
private String range;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -372,6 +372,7 @@ public class MonitorHostServiceImpl implements MonitorHostService {
|
|||||||
} else {
|
} else {
|
||||||
Assert.notNull(request.getStart(), ErrorMessage.PARAM_MISSING);
|
Assert.notNull(request.getStart(), ErrorMessage.PARAM_MISSING);
|
||||||
Assert.notNull(request.getEnd(), ErrorMessage.PARAM_MISSING);
|
Assert.notNull(request.getEnd(), ErrorMessage.PARAM_MISSING);
|
||||||
|
query.range(request.getStart(), request.getEnd());
|
||||||
}
|
}
|
||||||
// 设置名称
|
// 设置名称
|
||||||
Set<String> names = null;
|
Set<String> names = null;
|
||||||
|
|||||||
@@ -70,6 +70,7 @@
|
|||||||
animation: false,
|
animation: false,
|
||||||
tooltip: {
|
tooltip: {
|
||||||
trigger: 'axis',
|
trigger: 'axis',
|
||||||
|
appendToBody: true,
|
||||||
backgroundColor: 'rgba(255, 255, 255, 0.9)',
|
backgroundColor: 'rgba(255, 255, 255, 0.9)',
|
||||||
textStyle: {
|
textStyle: {
|
||||||
color: 'rgba(0, 0, 0, 0.8)',
|
color: 'rgba(0, 0, 0, 0.8)',
|
||||||
|
|||||||
Reference in New Issue
Block a user