Search in sources :

Example 1 with MonitorService

use of io.jpom.service.monitor.MonitorService in project Jpom by dromara.

the class LoadJsonConfigToDb method loadMonitorInfo.

public void loadMonitorInfo() {
    File backupOldData = FileUtil.file(ConfigBean.getInstance().getDataPath(), "backup_old_data");
    // 读取 monitor 文件内容
    File file = FileUtil.file(ConfigBean.getInstance().getDataPath(), ServerConfigBean.MONITOR_FILE);
    if (!FileUtil.exist(file)) {
        return;
    }
    try {
        JSON json = JsonFileUtil.readJson(file.getAbsolutePath());
        JSONArray jsonArray = JsonFileUtil.formatToArray((JSONObject) json);
        List<MonitorModel> monitorModels = jsonArray.toJavaList(MonitorModel.class);
        if (monitorModels == null) {
            return;
        }
        MonitorService monitorService = SpringUtil.getBean(MonitorService.class);
        monitorService.insert(monitorModels);
        // 将 json 文件转移到备份目录
        FileUtil.move(file, FileUtil.mkdir(backupOldData), true);
        DefaultSystemLog.getLog().info("{} mv to {}", FileUtil.getAbsolutePath(file), FileUtil.getAbsolutePath(backupOldData));
    } catch (Exception e) {
        DefaultSystemLog.getLog().error("load monitor error ", e);
    }
}
Also used : MonitorService(io.jpom.service.monitor.MonitorService) JSONArray(com.alibaba.fastjson.JSONArray) JSON(com.alibaba.fastjson.JSON) File(java.io.File)

Aggregations

JSON (com.alibaba.fastjson.JSON)1 JSONArray (com.alibaba.fastjson.JSONArray)1 MonitorService (io.jpom.service.monitor.MonitorService)1 File (java.io.File)1