Search in sources :

Example 1 with NodeStatModel

use of io.jpom.model.stat.NodeStatModel in project Jpom by dromara.

the class NodeStatService method startLoad.

@Override
public void startLoad() {
    // 启动心跳检测
    int heartSecond = serverExtConfigBean.getNodeHeartSecond();
    ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(runnable -> new Thread(runnable, "Jpom Node Monitor"));
    scheduler.scheduleAtFixedRate(this, 10, heartSecond, TimeUnit.SECONDS);
    // 清理 错误的节点统计数据
    List<String> duplicationByUrl = nodeService.getDeDuplicationByUrl();
    List<String> statUrl = this.getDeDuplicationByUrl();
    Collection<String> subtract = CollUtil.subtract(statUrl, duplicationByUrl);
    // 
    for (String s : subtract) {
        NodeStatModel statModel = new NodeStatModel();
        statModel.setUrl(s);
        this.del(this.dataBeanToEntity(statModel));
    }
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) NodeStatModel(io.jpom.model.stat.NodeStatModel)

Example 2 with NodeStatModel

use of io.jpom.model.stat.NodeStatModel in project Jpom by dromara.

the class NodeStatService method create.

private NodeStatModel create(NodeModel model) {
    NodeStatModel nodeStatModel = new NodeStatModel();
    nodeStatModel.setId(model.getId());
    nodeStatModel.setWorkspaceId(model.getWorkspaceId());
    nodeStatModel.setName(model.getName());
    nodeStatModel.setUrl(model.getUrl());
    // 
    nodeStatModel.setOccupyMemory(-1D);
    nodeStatModel.setOccupyMemoryUsed(-1D);
    nodeStatModel.setOccupyDisk(-1D);
    nodeStatModel.setOccupyCpu(-1D);
    nodeStatModel.setGroup(model.getGroup());
    nodeStatModel.setNetworkTime(-1);
    nodeStatModel.setUpTimeStr(StrUtil.EMPTY);
    return nodeStatModel;
}
Also used : NodeStatModel(io.jpom.model.stat.NodeStatModel)

Example 3 with NodeStatModel

use of io.jpom.model.stat.NodeStatModel in project Jpom by dromara.

the class NodeStatService method save.

/**
 * 报错结果
 *
 * @param modelList     节点
 * @param systemMonitor 系统监控
 * @param statusData    状态数据
 */
private void save(List<NodeModel> modelList, JSONObject systemMonitor, JSONObject statusData) {
    this.saveSystemMonitor(modelList, systemMonitor);
    // 
    for (NodeModel nodeModel : modelList) {
        NodeStatModel nodeStatModel = this.create(nodeModel);
        if (nodeModel.isOpenStatus()) {
            if (systemMonitor != null) {
                nodeStatModel.setOccupyMemory(ObjectUtil.defaultIfNull(systemMonitor.getDouble("memory"), -1D));
                nodeStatModel.setOccupyMemoryUsed(ObjectUtil.defaultIfNull(systemMonitor.getDouble("memoryUsed"), -1D));
                nodeStatModel.setOccupyDisk(ObjectUtil.defaultIfNull(systemMonitor.getDouble("disk"), -1D));
                nodeStatModel.setOccupyCpu(ObjectUtil.defaultIfNull(systemMonitor.getDouble("cpu"), -1D));
            }
            // 
            nodeStatModel.setNetworkTime(statusData.getIntValue("networkTime"));
            nodeStatModel.setJpomVersion(statusData.getString("jpomVersion"));
            nodeStatModel.setOsName(statusData.getString("osName"));
            String runTime = statusData.getString("runTime");
            String runTimeLong = statusData.getString("runTimeLong");
            // 兼容数据
            nodeStatModel.setUpTimeStr(StrUtil.emptyToDefault(runTimeLong, runTime));
            nodeStatModel.setFailureMsg(StrUtil.emptyToDefault(statusData.getString("failureMsg"), StrUtil.EMPTY));
            // 
            Integer statusInteger = statusData.getInteger("status");
            if (statusInteger != null) {
                nodeStatModel.setStatus(statusInteger);
            } else {
                nodeStatModel.setStatus(0);
            }
        } else {
            nodeStatModel.setStatus(4);
            nodeStatModel.setFailureMsg("节点禁用中");
        }
        this.upsert(nodeStatModel);
    }
}
Also used : NodeModel(io.jpom.model.data.NodeModel) NodeStatModel(io.jpom.model.stat.NodeStatModel)

Example 4 with NodeStatModel

use of io.jpom.model.stat.NodeStatModel in project Jpom by dromara.

the class NodeStatService method save.

/**
 * 更新状态 和错误信息
 *
 * @param modelList 节点
 * @param satus     状态
 * @param msg       错误消息
 */
private void save(List<NodeModel> modelList, int satus, String msg) {
    for (NodeModel nodeModel : modelList) {
        NodeStatModel nodeStatModel = this.create(nodeModel);
        nodeStatModel.setFailureMsg(msg);
        nodeStatModel.setStatus(satus);
        this.upsert(nodeStatModel);
    }
}
Also used : NodeModel(io.jpom.model.data.NodeModel) NodeStatModel(io.jpom.model.stat.NodeStatModel)

Aggregations

NodeStatModel (io.jpom.model.stat.NodeStatModel)4 NodeModel (io.jpom.model.data.NodeModel)2 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1