From 74caed7cc3cb7bd9b25a0517a8e125988a6f4b7b Mon Sep 17 00:00:00 2001 From: 潘志宝 <979469083@qq.com> Date: 星期二, 11 三月 2025 09:24:21 +0800 Subject: [PATCH] 监控model服务状态,崩溃后重启 --- ansteel-biz/src/main/java/com/iailab/module/ansteel/job/task/CheckIailabModelServiceTask.java | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ pom.xml | 2 +- 2 files changed, 57 insertions(+), 1 deletions(-) diff --git a/ansteel-biz/src/main/java/com/iailab/module/ansteel/job/task/CheckIailabModelServiceTask.java b/ansteel-biz/src/main/java/com/iailab/module/ansteel/job/task/CheckIailabModelServiceTask.java new file mode 100644 index 0000000..86ab882 --- /dev/null +++ b/ansteel-biz/src/main/java/com/iailab/module/ansteel/job/task/CheckIailabModelServiceTask.java @@ -0,0 +1,56 @@ +package com.iailab.module.ansteel.job.task; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.iailab.framework.common.util.http.HttpUtils; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; + +/** + * 监控model服务状态,崩溃后重启 + * + * @author PanZhibao + * @Description + * @createTime 2025年03月11日 + */ +@Component("checkIailabModelServiceTask") +public class CheckIailabModelServiceTask implements ITask { + private Logger logger = LoggerFactory.getLogger(getClass()); + + @Resource + private RestartIailabModelServiceTask restartIailabModelServiceTask; + + @Override + public void run(String params) { + logger.info("CheckIailabModelServiceTask定时任务正在执行,参数为:{}", params); + boolean isHealth = true; + try { + if (StringUtils.isEmpty(params)) { + return; + } + String url = "http://" + params + "/actuator/health"; + String resp = HttpUtils.sendGet(url,null); + logger.info("actuator:" + resp); + if (StringUtils.isEmpty(resp)) { + isHealth = false; + } + JSONObject jsonObject = JSON.parseObject(resp); + if (!"UP".equals(jsonObject.getString("status"))) { + isHealth = false; + } + logger.info("IailabModelService is UP"); + } catch (Exception e) { + isHealth = false; + e.printStackTrace(); + } + if (!isHealth) { + logger.info("IailabModelService is DOWN"); + restartIailabModelServiceTask.run(""); + } + logger.info("CheckIailabModelServiceTask运行完成"); + } +} \ No newline at end of file diff --git a/pom.xml b/pom.xml index ff99171..f58865e 100644 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,7 @@ <properties> - <revision>0.0.1</revision> + <revision>1.0.0</revision> <!-- Maven 相关 --> <java.version>1.8</java.version> <maven.compiler.source>${java.version}</maven.compiler.source> -- Gitblit v1.9.3