This commit is contained in:
van
2026-03-10 00:31:54 +08:00
parent b4749f3516
commit 0a20825831
3 changed files with 48 additions and 0 deletions

View File

@@ -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<String, Object> 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<String, Object> healthMap, String url, String message) {
Map<String, Object> ollamaMap = new HashMap<>();
ollamaMap.put("healthy", false);
ollamaMap.put("status", "异常");
ollamaMap.put("message", message);
ollamaMap.put("serviceUrl", url);
healthMap.put("ollama", ollamaMap);
}
}

View File

@@ -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:

View File

@@ -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: