diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/ServerController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/ServerController.java index 49911cd..82675d2 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/ServerController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/ServerController.java @@ -1,10 +1,14 @@ package com.ruoyi.web.controller.monitor; +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; +import org.springframework.beans.factory.annotation.Value; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.utils.http.HttpUtils; import com.ruoyi.framework.web.domain.Server; import com.ruoyi.jarvis.service.ILogisticsService; import com.ruoyi.jarvis.service.IWxSendService; @@ -27,6 +31,10 @@ public class ServerController @Resource private IWxSendService wxSendService; + + /** Ollama 服务地址,用于健康检查 */ + @Value("${jarvis.ollama.base-url:http://192.168.8.34:11434}") + private String ollamaBaseUrl; @PreAuthorize("@ss.hasPermi('monitor:server:list')") @GetMapping() @@ -82,6 +90,38 @@ public class ServerController healthMap.put("wxSend", wxSendMap); } + // Ollama 服务健康检测(调试用) + try { + String url = ollamaBaseUrl.replaceAll("/$", "") + "/api/tags"; + String result = HttpUtils.sendGet(url); + if (result != null && !result.trim().isEmpty()) { + JSONObject json = JSON.parseObject(result); + if (json != null && json.containsKey("models") && !json.containsKey("error")) { + Map ollamaMap = new HashMap<>(); + ollamaMap.put("healthy", true); + ollamaMap.put("status", "正常"); + ollamaMap.put("message", "Ollama 服务可用"); + ollamaMap.put("serviceUrl", ollamaBaseUrl); + healthMap.put("ollama", ollamaMap); + } else { + putOllamaUnhealthy(healthMap, url, json != null && json.getString("error") != null ? json.getString("error") : "返回格式异常"); + } + } else { + putOllamaUnhealthy(healthMap, url, "返回为空"); + } + } catch (Exception e) { + putOllamaUnhealthy(healthMap, ollamaBaseUrl, "健康检测异常: " + e.getMessage()); + } + return AjaxResult.success(healthMap); } + + private void putOllamaUnhealthy(Map healthMap, String url, String message) { + Map ollamaMap = new HashMap<>(); + ollamaMap.put("healthy", false); + ollamaMap.put("status", "异常"); + ollamaMap.put("message", message); + ollamaMap.put("serviceUrl", url); + healthMap.put("ollama", ollamaMap); + } } diff --git a/ruoyi-admin/src/main/resources/application-dev.yml b/ruoyi-admin/src/main/resources/application-dev.yml index 0d810e6..142608e 100644 --- a/ruoyi-admin/src/main/resources/application-dev.yml +++ b/ruoyi-admin/src/main/resources/application-dev.yml @@ -205,6 +205,10 @@ jarvis: # 获取评论接口服务地址(后端转发,避免前端跨域) fetch-comments: base-url: http://192.168.8.60:5008 + # Ollama 大模型服务(监控健康度调试用) + ollama: + base-url: http://192.168.8.34:11434 + model: qwen3.5:9b # 腾讯文档开放平台配置 # 文档地址:https://docs.qq.com/open/document/app/openapi/v3/sheet/model/spreadsheet.html tencent: diff --git a/ruoyi-admin/src/main/resources/application-prod.yml b/ruoyi-admin/src/main/resources/application-prod.yml index 1c9afa5..316db45 100644 --- a/ruoyi-admin/src/main/resources/application-prod.yml +++ b/ruoyi-admin/src/main/resources/application-prod.yml @@ -205,6 +205,10 @@ jarvis: # 获取评论接口服务地址(后端转发) fetch-comments: base-url: http://192.168.8.60:5008 + # Ollama 大模型服务(监控健康度调试用) + ollama: + base-url: http://192.168.8.34:11434 + model: qwen3.5:9b # 腾讯文档开放平台配置 # 文档地址:https://docs.qq.com/open/document/app/openapi/v3/sheet/model/spreadsheet.html tencent: