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,30 +181,37 @@ public class FlinkMetricsIndicator extends BaseSchedule { ...@@ -179,30 +181,37 @@ 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;
}
HttpUtils.asyncRequest(
flinkMetrics.getUrls(),
"/jobs/"
+ flinkMetrics.getJobId()
+ "/vertices/"
+ v
+ "/metrics?get="
+ metrics,
flinkMetricsRequestTimeout.get(),
x -> {
JSONArray array = JSONUtil.parseArray(x.body());
String value = array.getJSONObject(0).getStr("value");
m.put(metrics, value);
});
} }
String metricsName = StrUtil.join(",", m.keySet());
HttpUtils.asyncRequest(
flinkMetrics.getUrls(),
"/jobs/"
+ flinkMetrics.getJobId()
+ "/vertices/"
+ v
+ "/metrics?get="
+ URLUtil.encode(metricsName),
flinkMetricsRequestTimeout.get(),
x -> {
JSONArray array = JSONUtil.parseArray(x.body());
if (CollUtil.isEmpty(array)) {
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