Browse Source

Pull request #14209: REPORT-117002 & REPORT-127241 设计器性能埋点监控

Merge in DESIGN/design from ~LEVY.XIE/design:release/11.0 to release/11.0

* commit 'edc7184564e6ed125862266152013045a52f156c':
  REPORT-127241 设计器性能埋点字段调整
  REPORT-117002 设计器性能埋点监控 调整代码
  REPORT-117002 设计器性能埋点监控 调整代码
release/11.0
Levy.Xie-解安森 5 months ago
parent
commit
80acabb5dc
  1. 29
      designer-base/src/main/java/com/fr/design/carton/latency/DesignerLatencyMetric.java

29
designer-base/src/main/java/com/fr/design/carton/latency/DesignerLatencyMetric.java

@ -8,9 +8,12 @@ import com.fr.design.mainframe.SiteCenterToken;
import com.fr.event.Event; import com.fr.event.Event;
import com.fr.event.EventDispatcher; import com.fr.event.EventDispatcher;
import com.fr.event.Listener; import com.fr.event.Listener;
import com.fr.general.CloudCenter;
import com.fr.general.http.HttpToolbox; import com.fr.general.http.HttpToolbox;
import com.fr.json.JSONObject; import com.fr.json.JSONObject;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.ProductConstants; import com.fr.stable.ProductConstants;
import com.fr.stable.StringUtils;
import com.fr.workspace.WorkContext; import com.fr.workspace.WorkContext;
import com.fr.workspace.Workspace; import com.fr.workspace.Workspace;
import com.fr.workspace.WorkspaceEvent; import com.fr.workspace.WorkspaceEvent;
@ -43,11 +46,13 @@ import static com.fr.design.carton.CartonConstants.USERID;
*/ */
public class DesignerLatencyMetric { public class DesignerLatencyMetric {
private String latencyUrl;
private ExecutorService executorService; private ExecutorService executorService;
private ScheduledExecutorService scheduler; private ScheduledExecutorService scheduler;
private static final Map<LatencyLevel, AtomicInteger> LATENCY_CONTAINER = new ConcurrentHashMap<>(); private static final Map<LatencyLevel, AtomicInteger> LATENCY_CONTAINER = new ConcurrentHashMap<>();
private static final String LATENCY_INFO_URL = "https://cloud.fanruan.com/api/monitor/record_of_deisgner_latency/single"; private static final String DEFAULT_MONITOR_URL = "https://cloud.fanruan.com/api/monitor/";
private static final String LATENCY_TABLE_SUFFIX = "record_of_designer_latency/single";
private final static class InstanceHolder { private final static class InstanceHolder {
static final DesignerLatencyMetric INSTANCE = new DesignerLatencyMetric(); static final DesignerLatencyMetric INSTANCE = new DesignerLatencyMetric();
@ -74,7 +79,7 @@ public class DesignerLatencyMetric {
executorService = Executors.newFixedThreadPool(8); executorService = Executors.newFixedThreadPool(8);
// 启动定时埋点 // 启动定时埋点
this.scheduler = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("LatencyMetricWorker")); this.scheduler = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("LatencyMetricWorker"));
this.scheduler.scheduleWithFixedDelay(this::collectAndSubmit, 60, 60, TimeUnit.SECONDS); this.scheduler.scheduleWithFixedDelay(this::collectAndSubmit, 60, 60, TimeUnit.MINUTES);
// 注册设计器工作目录切换事件监听 // 注册设计器工作目录切换事件监听
EventDispatcher.listen(WorkspaceEvent.AfterSwitch, new Listener<Workspace>() { EventDispatcher.listen(WorkspaceEvent.AfterSwitch, new Listener<Workspace>() {
@Override @Override
@ -82,6 +87,7 @@ public class DesignerLatencyMetric {
collectAndSubmit(); collectAndSubmit();
} }
}); });
FineLoggerFactory.getLogger().info("[Latency] designer latency metric started.");
} }
} }
@ -97,9 +103,19 @@ public class DesignerLatencyMetric {
this.scheduler.shutdown(); this.scheduler.shutdown();
} }
collectAndSubmit(); collectAndSubmit();
FineLoggerFactory.getLogger().info("[Latency] designer latency metric stopped.");
} }
} }
private String getLatencyUrl() {
if (StringUtils.isEmpty(latencyUrl)) {
String monitorEntry = CloudCenter.getInstance().acquireUrlByKind("cloud.monitor.api.entrypoint");
latencyUrl = (StringUtils.isNotEmpty(monitorEntry) ? monitorEntry : DEFAULT_MONITOR_URL)
+ LATENCY_TABLE_SUFFIX;
}
return latencyUrl;
}
private void initializeContainer() { private void initializeContainer() {
for (LatencyLevel level : LatencyLevel.values()) { for (LatencyLevel level : LatencyLevel.values()) {
LATENCY_CONTAINER.put(level, new AtomicInteger()); LATENCY_CONTAINER.put(level, new AtomicInteger());
@ -132,9 +148,10 @@ public class DesignerLatencyMetric {
para.put("token", SiteCenterToken.generateToken()); para.put("token", SiteCenterToken.generateToken());
para.put("content", collect()); para.put("content", collect());
try { try {
HttpToolbox.post(LATENCY_INFO_URL, para); HttpToolbox.post(getLatencyUrl(), para);
} catch (Throwable ignore) { FineLoggerFactory.getLogger().debug("[Latency] submit latency log to cloud.");
// doNothing } catch (Throwable t) {
FineLoggerFactory.getLogger().debug(t,"[Latency] failed to submit latency log to cloud.");
} }
resetContainer(); resetContainer();
} }
@ -149,8 +166,10 @@ public class DesignerLatencyMetric {
info.put(DESIGN_METHOD, WorkContext.getCurrent().isLocal() ? LOCAL : REMOTE); info.put(DESIGN_METHOD, WorkContext.getCurrent().isLocal() ? LOCAL : REMOTE);
info.put(OPERANDS_NUM, LATENCY_CONTAINER.values().stream().mapToInt(AtomicInteger::get).sum()); info.put(OPERANDS_NUM, LATENCY_CONTAINER.values().stream().mapToInt(AtomicInteger::get).sum());
for (Map.Entry<LatencyLevel, AtomicInteger> entry : LATENCY_CONTAINER.entrySet()) { for (Map.Entry<LatencyLevel, AtomicInteger> entry : LATENCY_CONTAINER.entrySet()) {
if (!LatencyLevel.UNDEFINE.equals(entry.getKey())) {
info.put(entry.getKey().getMark(), entry.getValue().get()); info.put(entry.getKey().getMark(), entry.getValue().get());
} }
}
return info; return info;
} }

Loading…
Cancel
Save