You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
194 lines
4.9 KiB
194 lines
4.9 KiB
3 years ago
|
package com.fr.startup.metric;
|
||
|
|
||
|
import com.fr.json.JSONArray;
|
||
|
import com.fr.json.JSONObject;
|
||
|
import com.fr.plugin.context.PluginContext;
|
||
|
import com.fr.plugin.manage.PluginManager;
|
||
|
import com.fr.stable.os.AbstractOperatingSystem;
|
||
|
import com.fr.stable.os.OperatingSystem;
|
||
|
import com.fr.start.common.DesignerStartupConfig;
|
||
|
import com.fr.workspace.WorkContext;
|
||
|
|
||
|
import java.lang.management.ManagementFactory;
|
||
|
import java.util.List;
|
||
|
import java.util.stream.Collectors;
|
||
|
|
||
|
/**
|
||
|
* 设计器启动数据
|
||
|
*
|
||
|
* created by Harrison on 2022/08/12
|
||
|
**/
|
||
|
public class DesignerStartupModel {
|
||
|
|
||
|
/**
|
||
|
* landingTime:用户从双击图标/.bat启动等,到出现起始页的时间
|
||
|
*/
|
||
|
private long landingTime;
|
||
|
|
||
|
/**
|
||
|
* startingTime:用户从起始页进入设计器,完全可用的时间
|
||
|
*/
|
||
|
private long startingTime;
|
||
|
|
||
|
/**
|
||
|
* info:设计器环境的详细信息。记录环境信息、机器信息、远程or本地、插件信息。
|
||
|
*/
|
||
|
private MachineInfo info;
|
||
|
|
||
|
/**
|
||
|
* mode:模式,0-有设计器起动页;1-无设计器起始页
|
||
|
*/
|
||
|
private int mode;
|
||
|
|
||
|
public DesignerStartupModel() {
|
||
|
}
|
||
|
|
||
|
public DesignerStartupModel(long landingTime, long startingTime, MachineInfo info, int mode) {
|
||
|
this.landingTime = landingTime;
|
||
|
this.startingTime = startingTime;
|
||
|
this.info = info;
|
||
|
this.mode = mode;
|
||
|
}
|
||
|
|
||
|
public long getLandingTime() {
|
||
|
return landingTime;
|
||
|
}
|
||
|
|
||
|
public void setLandingTime(long landingTime) {
|
||
|
this.landingTime = landingTime;
|
||
|
}
|
||
|
|
||
|
public long getStartingTime() {
|
||
|
return startingTime;
|
||
|
}
|
||
|
|
||
|
public void setStartingTime(long startingTime) {
|
||
|
this.startingTime = startingTime;
|
||
|
}
|
||
|
|
||
|
public MachineInfo getInfo() {
|
||
|
return info;
|
||
|
}
|
||
|
|
||
|
public void setInfo(MachineInfo info) {
|
||
|
this.info = info;
|
||
|
}
|
||
|
|
||
|
public int getMode() {
|
||
|
return mode;
|
||
|
}
|
||
|
|
||
|
public void setMode(int mode) {
|
||
|
this.mode = mode;
|
||
|
}
|
||
|
|
||
|
private void fillInfo() {
|
||
|
|
||
|
MachineInfo info = new MachineInfo();
|
||
|
AbstractOperatingSystem operatingSystem = OperatingSystem.getOperatingSystem();
|
||
|
info.setSystem(operatingSystem.getDisplayString());
|
||
|
|
||
|
try {
|
||
|
final int byteToMb = 1024 * 1024;
|
||
|
com.sun.management.OperatingSystemMXBean operatingSystemMXBean = (com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
|
||
|
long free = operatingSystemMXBean.getFreePhysicalMemorySize() / byteToMb;
|
||
|
long total = operatingSystemMXBean.getTotalPhysicalMemorySize() / byteToMb;
|
||
|
long used = total - free;
|
||
|
JSONObject jo = new JSONObject();
|
||
|
jo.put("free", free);
|
||
|
jo.put("used", used);
|
||
|
jo.put("total", total);
|
||
|
info.setMachine(jo.toString());
|
||
|
} catch (Exception ignored) {
|
||
|
}
|
||
|
|
||
|
boolean local = WorkContext.getCurrent().isLocal();
|
||
|
info.setWork(local ? 1 : 0);
|
||
|
|
||
|
List<PluginContext> contexts = PluginManager.getContexts();
|
||
|
List<String> contextNames = contexts.stream()
|
||
|
.map(PluginContext::getName)
|
||
|
.collect(Collectors.toList());
|
||
|
JSONArray contextNameJa = new JSONArray(contextNames);
|
||
|
info.setPlugins(contextNameJa.toString());
|
||
|
this.setInfo(info);
|
||
|
|
||
|
}
|
||
|
|
||
|
private void fillMode() {
|
||
|
|
||
|
this.setMode(DesignerStartupConfig.getInstance().isEnabled() ? 0 : 1);
|
||
|
}
|
||
|
|
||
|
public void fill() {
|
||
|
|
||
|
fillInfo();
|
||
|
fillMode();
|
||
|
}
|
||
|
|
||
|
private static class MachineInfo {
|
||
|
|
||
|
/**
|
||
|
* 系统信息
|
||
|
*/
|
||
|
private String system;
|
||
|
|
||
|
/**
|
||
|
* 机器信息
|
||
|
*/
|
||
|
private String machine;
|
||
|
|
||
|
/**
|
||
|
* work:0-远程;1-本地;
|
||
|
*/
|
||
|
private int work;
|
||
|
|
||
|
/**
|
||
|
* 插件列表
|
||
|
*/
|
||
|
private String plugins;
|
||
|
|
||
|
public MachineInfo() {
|
||
|
}
|
||
|
|
||
|
public MachineInfo(String system, String machine, int work, String plugins) {
|
||
|
this.system = system;
|
||
|
this.machine = machine;
|
||
|
this.work = work;
|
||
|
this.plugins = plugins;
|
||
|
}
|
||
|
|
||
|
public String getSystem() {
|
||
|
return system;
|
||
|
}
|
||
|
|
||
|
public void setSystem(String system) {
|
||
|
this.system = system;
|
||
|
}
|
||
|
|
||
|
public String getMachine() {
|
||
|
return machine;
|
||
|
}
|
||
|
|
||
|
public void setMachine(String machine) {
|
||
|
this.machine = machine;
|
||
|
}
|
||
|
|
||
|
public int getWork() {
|
||
|
return work;
|
||
|
}
|
||
|
|
||
|
public void setWork(int work) {
|
||
|
this.work = work;
|
||
|
}
|
||
|
|
||
|
public String getPlugins() {
|
||
|
return plugins;
|
||
|
}
|
||
|
|
||
|
public void setPlugins(String plugins) {
|
||
|
this.plugins = plugins;
|
||
|
}
|
||
|
}
|
||
|
}
|