Skip to content

Commit 5e960e9

Browse files
committed
refactor(metrics):优化指标收集逻辑
- 移除多余的空行和注释 - 删除重复的 CompletableFuture 调用- 简化 FmMetricsResponse 的获取方式 - 保持代码整洁和一致性
1 parent 567c415 commit 5e960e9

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

src/main/java/tech/wetech/flexmodel/application/MetricsApplicationService.java

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package tech.wetech.flexmodel.application;
22

3-
import io.quarkus.arc.Arc;
43
import jakarta.enterprise.context.ApplicationScoped;
54
import jakarta.inject.Inject;
65
import lombok.extern.slf4j.Slf4j;
@@ -64,19 +63,19 @@ public FmMetricsResponse getFmMetrics() {
6463
int queryCount = 0;
6564
int mutationCount = 0;
6665
int subscribeCount = 0;
67-
66+
6867
try {
6968
// 同步调用所有服务
7069
List<ApiDefinition> defList = apiDefinitionService.findList();
7170
List<Datasource> dsList = datasourceService.findAll();
72-
71+
7372
// 计算模型数量
7473
AtomicInteger modelCount = new AtomicInteger();
7574
for (Datasource datasource : dsList) {
7675
List<SchemaObject> ds = modelService.findAll(datasource.getName());
7776
modelCount.addAndGet(ds.size());
7877
}
79-
78+
8079
// 获取各种计数
8180
int reqLogCount = (int) apiLogService.count(TRUE);
8281
int flowDefCount = (int) flowDefService.count(TRUE);
@@ -915,16 +914,6 @@ public AllMetricsResponse getAllMetrics() {
915914
long startTime = System.currentTimeMillis();
916915
try {
917916
// 并行获取所有指标
918-
CompletableFuture<FmMetricsResponse> fmFuture =
919-
CompletableFuture.supplyAsync(() -> {
920-
Arc.container().requestContext().activate();
921-
try {
922-
return this.getFmMetrics();
923-
} finally {
924-
Arc.container().requestContext().deactivate();
925-
}
926-
});
927-
928917
CompletableFuture<JvmMetricsResponse> jvmFuture =
929918
CompletableFuture.supplyAsync(this::getJvmMetrics);
930919

@@ -951,15 +940,15 @@ public AllMetricsResponse getAllMetrics() {
951940

952941
// 等待所有任务完成,设置超时时间为30秒
953942
CompletableFuture<Void> allFutures = CompletableFuture.allOf(
954-
fmFuture, jvmFuture, cpuFuture, memoryFuture, threadsFuture,
943+
jvmFuture, cpuFuture, memoryFuture, threadsFuture,
955944
diskFuture, networkFuture, summaryFuture, prometheusFuture
956945
);
957946

958947
// 等待所有任务完成或超时
959948
allFutures.get(30, TimeUnit.SECONDS);
960949

961950
// 获取结果
962-
FmMetricsResponse fm = fmFuture.get();
951+
FmMetricsResponse fm = this.getFmMetrics();
963952
JvmMetricsResponse jvm = jvmFuture.get();
964953
CpuMetricsResponse cpu = cpuFuture.get();
965954
MemoryMetricsResponse memory = memoryFuture.get();

0 commit comments

Comments
 (0)