Unverified Commit 0a332896 authored by ZackYoung's avatar ZackYoung Committed by GitHub

Optimize get metrics (#2145)

parent beca02a7
...@@ -52,8 +52,10 @@ import org.springframework.stereotype.Component; ...@@ -52,8 +52,10 @@ import org.springframework.stereotype.Component;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.thread.AsyncUtil; import cn.hutool.core.thread.AsyncUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.core.util.URLUtil;
import cn.hutool.http.HttpUtil; import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONArray; import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import lombok.Getter; import lombok.Getter;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
...@@ -179,15 +181,15 @@ public class FlinkMetricsIndicator extends BaseSchedule { ...@@ -179,15 +181,15 @@ public class FlinkMetricsIndicator extends BaseSchedule {
return; return;
} }
// http://10.8.16.125:8282/jobs/06ccde3ff6e53bafe729e0e50fca72fd/vertices/cbc357ccb763df2852fee8c4fc7d55f2/metrics?get=0.buffers.inputExclusiveBuffersUsage // http://10.8.16.125:8282/jobs/06ccde3ff6e53bafe729e0e50fca72fd/vertices/cbc357ccb763df2852fee8c4fc7d55f2/metrics?get=0.buffers.inputExclusiveBuffersUsage,0.numRecordsInPerSecond
flinkMetrics flinkMetrics
.getVerticesAndMetricsMap() .getVerticesAndMetricsMap()
.forEach( .forEach(
(v, m) -> { (v, m) -> {
for (String metrics : m.keySet()) {
if (CollUtil.isEmpty(urlList)) { if (CollUtil.isEmpty(urlList)) {
return; return;
} }
String metricsName = StrUtil.join(",", m.keySet());
HttpUtils.asyncRequest( HttpUtils.asyncRequest(
flinkMetrics.getUrls(), flinkMetrics.getUrls(),
"/jobs/" "/jobs/"
...@@ -195,14 +197,21 @@ public class FlinkMetricsIndicator extends BaseSchedule { ...@@ -195,14 +197,21 @@ public class FlinkMetricsIndicator extends BaseSchedule {
+ "/vertices/" + "/vertices/"
+ v + v
+ "/metrics?get=" + "/metrics?get="
+ metrics, + URLUtil.encode(metricsName),
flinkMetricsRequestTimeout.get(), flinkMetricsRequestTimeout.get(),
x -> { x -> {
JSONArray array = JSONUtil.parseArray(x.body()); JSONArray array = JSONUtil.parseArray(x.body());
String value = array.getJSONObject(0).getStr("value"); if (CollUtil.isEmpty(array)) {
m.put(metrics, value); return;
});
} }
array.forEach(
y -> {
JSONObject jsonObject = JSONUtil.parseObj(y);
String id = jsonObject.getStr("id");
String value = jsonObject.getStr("value");
m.put(id, value);
});
});
}); });
FLINK_METRICS_DATA_MAP.get(now).add(flinkMetrics); FLINK_METRICS_DATA_MAP.get(now).add(flinkMetrics);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment