Search in sources :

Example 41 with NodeModel

use of io.jpom.model.data.NodeModel in project Jpom by dromara.

the class CheckMonitor method init.

@PreLoadMethod
private static void init() {
    // 缓存检测调度
    CronUtils.upsert("cache_manger_schedule", "0 0/10 * * * ?", () -> {
        BuildUtil.reloadCacheSize();
        ConfigBean.getInstance().dataSize();
    });
    // 开启版本检测调度
    CronUtils.upsert("system_monitor", "0 0 0,12 * * ?", () -> {
        try {
            BackupInfoService backupInfoService = SpringUtil.getBean(BackupInfoService.class);
            backupInfoService.checkAutoBackup();
            // 
            RemoteVersion.loadRemoteInfo();
        } catch (Exception e) {
            DefaultSystemLog.getLog().error("系统调度执行出现错误", e);
        }
    });
    // 拉取 脚本模版日志
    CronUtils.upsert("pull_script_log", "0 0/1 * * * ?", () -> {
        NodeService nodeService = SpringUtil.getBean(NodeService.class);
        NodeScriptServer nodeScriptServer = SpringUtil.getBean(NodeScriptServer.class);
        List<String> nodeIds = nodeScriptServer.hasScriptNode();
        if (nodeIds == null) {
            return;
        }
        for (String nodeId : nodeIds) {
            NodeModel nodeModel = nodeService.getByKey(nodeId);
            if (nodeModel == null) {
                continue;
            }
            ThreadUtil.execute(() -> CheckMonitor.pullScriptLogItem(nodeModel));
        }
    });
    // 异步加载
    CheckMonitor.asyncLoad();
}
Also used : NodeModel(io.jpom.model.data.NodeModel) BackupInfoService(io.jpom.service.dblog.BackupInfoService) NodeScriptServer(io.jpom.service.node.script.NodeScriptServer) NodeService(io.jpom.service.node.NodeService) PreLoadMethod(cn.jiangzeyin.common.PreLoadMethod)

Example 42 with NodeModel

use of io.jpom.model.data.NodeModel in project Jpom by dromara.

the class BaseHandler method logOpt.

/**
 * 操作 websocket 日志
 *
 * @param cls        class
 * @param attributes 属性
 * @param reqData    请求数据
 */
protected void logOpt(Class<?> cls, Map<String, Object> attributes, Object reqData) {
    String ip = (String) attributes.get("ip");
    NodeModel nodeModel = (NodeModel) attributes.get("nodeInfo");
    // 记录操作日志
    UserModel userInfo = (UserModel) attributes.get("userInfo");
    String workspaceId = (String) attributes.get("workspaceId");
    OperateLogController.CacheInfo cacheInfo = new OperateLogController.CacheInfo();
    cacheInfo.setIp(ip);
    Feature feature = cls.getAnnotation(Feature.class);
    MethodFeature method = feature.method();
    // Assert.state(feature != null && feature, "权限功能没有配置正确");
    cacheInfo.setClassFeature(feature.cls());
    cacheInfo.setWorkspaceId(workspaceId);
    cacheInfo.setMethodFeature(method);
    cacheInfo.setNodeModel(nodeModel);
    cacheInfo.setDataId(null);
    String userAgent = (String) attributes.get(HttpHeaders.USER_AGENT);
    cacheInfo.setUserAgent(userAgent);
    cacheInfo.setReqData(JSONObject.toJSONString(reqData));
    // cacheInfo.setMethodFeature(execute);
    Object proxySession = attributes.get("proxySession");
    try {
        attributes.remove("proxySession");
        attributes.put("use_type", "WebSocket");
        attributes.put("class_type", cls.getName());
        OperateLogController operateLogController = SpringUtil.getBean(OperateLogController.class);
        operateLogController.log(userInfo, JSONObject.toJSONString(attributes), cacheInfo);
    } catch (Exception e) {
        DefaultSystemLog.getLog().error("记录操作日志异常", e);
    } finally {
        if (proxySession != null) {
            attributes.put("proxySession", proxySession);
        }
    }
}
Also used : UserModel(io.jpom.model.data.UserModel) NodeModel(io.jpom.model.data.NodeModel) MethodFeature(io.jpom.permission.MethodFeature) JSONObject(com.alibaba.fastjson.JSONObject) OperateLogController(io.jpom.system.init.OperateLogController) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature)

Example 43 with NodeModel

use of io.jpom.model.data.NodeModel in project Jpom by dromara.

the class NodeStatService method saveSystemMonitor.

private void saveSystemMonitor(List<NodeModel> modelList, JSONObject systemMonitor) {
    if (systemMonitor != null) {
        List<SystemMonitorLog> monitorLogs = modelList.stream().map(nodeModel -> {
            SystemMonitorLog log = new SystemMonitorLog();
            log.setOccupyMemory(systemMonitor.getDouble("memory"));
            log.setOccupyMemoryUsed(systemMonitor.getDouble("memoryUsed"));
            log.setOccupyDisk(systemMonitor.getDouble("disk"));
            log.setOccupyCpu(systemMonitor.getDouble("cpu"));
            log.setMonitorTime(systemMonitor.getLongValue("time"));
            log.setNetworkTime(systemMonitor.getIntValue("networkTime"));
            log.setNodeId(nodeModel.getId());
            return log;
        }).collect(Collectors.toList());
        // 
        dbSystemMonitorLogService.insert(monitorLogs);
    }
}
Also used : ObjectUtil(cn.hutool.core.util.ObjectUtil) DefaultSystemLog(cn.jiangzeyin.common.DefaultSystemLog) DbSystemMonitorLogService(io.jpom.service.dblog.DbSystemMonitorLogService) IAsyncLoad(io.jpom.cron.IAsyncLoad) JsonMessage(cn.jiangzeyin.common.JsonMessage) Service(org.springframework.stereotype.Service) NodeService(io.jpom.service.node.NodeService) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) BaseWorkspaceService(io.jpom.service.h2db.BaseWorkspaceService) NodeForward(io.jpom.common.forward.NodeForward) Collection(java.util.Collection) NodeModel(io.jpom.model.data.NodeModel) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) NodeStatModel(io.jpom.model.stat.NodeStatModel) NodeUrl(io.jpom.common.forward.NodeUrl) SystemMonitorLog(io.jpom.model.log.SystemMonitorLog) TimeUnit(java.util.concurrent.TimeUnit) CollUtil(cn.hutool.core.collection.CollUtil) StrUtil(cn.hutool.core.util.StrUtil) AuthorizeException(io.jpom.system.AuthorizeException) List(java.util.List) SystemClock(cn.hutool.core.date.SystemClock) JSONObject(com.alibaba.fastjson.JSONObject) Entity(cn.hutool.db.Entity) ThreadUtil(cn.hutool.core.thread.ThreadUtil) UserModel(io.jpom.model.data.UserModel) AgentException(io.jpom.system.AgentException) BaseServerController(io.jpom.common.BaseServerController) ServerExtConfigBean(io.jpom.system.ServerExtConfigBean) SystemMonitorLog(io.jpom.model.log.SystemMonitorLog)

Example 44 with NodeModel

use of io.jpom.model.data.NodeModel 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)

Example 45 with NodeModel

use of io.jpom.model.data.NodeModel in project Jpom by dromara.

the class NodeStatService method getListByUrl.

private List<NodeModel> getListByUrl(String url) {
    NodeModel nodeModel = new NodeModel();
    nodeModel.setUrl(url);
    return nodeService.listByBean(nodeModel);
}
Also used : NodeModel(io.jpom.model.data.NodeModel)

Aggregations

NodeModel (io.jpom.model.data.NodeModel)67 JSONObject (com.alibaba.fastjson.JSONObject)29 Feature (io.jpom.permission.Feature)23 MethodFeature (io.jpom.permission.MethodFeature)23 ClassFeature (io.jpom.permission.ClassFeature)22 UserModel (io.jpom.model.data.UserModel)18 StrUtil (cn.hutool.core.util.StrUtil)13 NodeService (io.jpom.service.node.NodeService)13 Collectors (java.util.stream.Collectors)13 CollUtil (cn.hutool.core.collection.CollUtil)12 JsonMessage (cn.jiangzeyin.common.JsonMessage)12 List (java.util.List)12 HttpServletRequest (javax.servlet.http.HttpServletRequest)11 DefaultSystemLog (cn.jiangzeyin.common.DefaultSystemLog)10 NodeForward (io.jpom.common.forward.NodeForward)9 NodeUrl (io.jpom.common.forward.NodeUrl)9 JSONArray (com.alibaba.fastjson.JSONArray)8 BaseServerController (io.jpom.common.BaseServerController)8 Assert (org.springframework.util.Assert)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8