From 782a914a3c1e4a8bc99ab7f4add6143a52a5d075 Mon Sep 17 00:00:00 2001 From: hmo Date: Sun, 19 Jul 2026 10:56:42 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20dashboard=20port=205804=E2=86=925807=20(?= =?UTF-8?q?avoid=20conflicts=20with=20wechat=5Fwebhook=20and=20zhiwei=20bo?= =?UTF-8?q?t)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- agents_health_check.py | 2 +- dashboard.py | 4 ++-- docs/DASHBOARD.md | 4 ++-- docs/DEPLOY.md | 18 +++++++++--------- docs/QUICKSTART.md | 8 ++++---- scripts/strategy-staleness-check.py | 22 ++++++++++++++++++++-- specs/dashboard.json | 8 ++++---- 7 files changed, 42 insertions(+), 24 deletions(-) diff --git a/agents_health_check.py b/agents_health_check.py index 542eb4ce..5be6f681 100644 --- a/agents_health_check.py +++ b/agents_health_check.py @@ -28,7 +28,7 @@ LOG_FILE = LOGS_DIR / "health_check.log" # ---- Service List ---- SERVICES = [ {"name": "mofin_api", "label": "MoFin API", "host": "127.0.0.1", "port": 8899, "type": "http", "check": "/api/portfolio"}, - {"name": "mofin_dashboard", "label": "Dashboard", "host": "127.0.0.1", "port": 5804, "type": "http", "check": "/api/health"}, + {"name": "mofin_dashboard", "label": "Dashboard", "host": "127.0.0.1", "port": 5807, "type": "http", "check": "/api/health"}, {"name": "zhiwei_gateway", "label": "知微 Gateway", "host": "127.0.0.1", "port": 8643, "type": "http", "check": "/v1/health"}, {"name": "ejabberd", "label": "ejabberd XMPP", "host": "127.0.0.1", "port": 5222, "type": "tcp", "check": None}, {"name": "mofin_db", "label": "MoFin 数据库", "host": "127.0.0.1", "port": 0, "type": "db", "check": "/home/hmo/web-dashboard/data/mofin.db"}, diff --git a/dashboard.py b/dashboard.py index b097b312..1479b944 100644 --- a/dashboard.py +++ b/dashboard.py @@ -44,7 +44,7 @@ logging.basicConfig( log = logging.getLogger("dashboard") # ---- Constants ---- -PORT = int(os.environ.get("MOFIN_DASHBOARD_PORT", 5804)) +PORT = int(os.environ.get("MOFIN_DASHBOARD_PORT", 5807)) START_TIME = time.time() # ---- Monitored Services ---- @@ -62,7 +62,7 @@ SERVICES = [ { "name": "mofin_dashboard", "label": "Dashboard", - "port": 5804, + "port": 5807, "host": "127.0.0.1", "type": "http", "check": "/api/health", diff --git a/docs/DASHBOARD.md b/docs/DASHBOARD.md index 5c1a4a3c..ddabc1ac 100644 --- a/docs/DASHBOARD.md +++ b/docs/DASHBOARD.md @@ -1,6 +1,6 @@ # MoFin — Dashboard API 参考 -> 版本: v1.0 | 端口: 5804 | 入口: http://192.168.1.246:5804 +> 版本: v1.0 | 端口: 5807 | 入口: http://192.168.1.246:5807 --- @@ -94,7 +94,7 @@ MoFin Dashboard crontab (每 5 分钟) └── agents_health_check.py → last_health_check.json -Dashboard (:5804) +Dashboard (:5807) ├── /api/services ← 实时 TCP/HTTP 检测 ├── /api/monitor ← 聚合读取 health check JSON └── /api/module-spec/ ← 读取 specs/ diff --git a/docs/DEPLOY.md b/docs/DEPLOY.md index f7c7963a..b3af0808 100644 --- a/docs/DEPLOY.md +++ b/docs/DEPLOY.md @@ -9,7 +9,7 @@ | 组件 | 守护方式 | 端口 | 说明 | |------|---------|------|------| | **server.py** | systemd `mofin-api` | 8899 | 持仓情报 API(已有,不动) | -| **dashboard.py** | systemd `mofin-dashboard` | 5804 | 管理门户(新增) | +| **dashboard.py** | systemd `mofin-dashboard` | 5807 | 管理门户(新增) | | **health_check** | crontab `*/5 * * * *` | — | Tier1 健康检查(新增) | --- @@ -49,9 +49,9 @@ sudo systemctl status mofin-dashboard ### 1.3 验证 ```bash -curl http://127.0.0.1:5804/api/health -curl http://127.0.0.1:5804/api/services | python3 -m json.tool -# 浏览器访问: http://192.168.1.246:5804 +curl http://127.0.0.1:5807/api/health +curl http://127.0.0.1:5807/api/services | python3 -m json.tool +# 浏览器访问: http://192.168.1.246:5807 ``` --- @@ -71,18 +71,18 @@ crontab -l | grep health ## 3. 防火墙 ```bash -sudo ufw status | grep -E '8899|5804' +sudo ufw status | grep -E '8899|5807' # 如果未开放: -# sudo ufw allow 5804/tcp +# sudo ufw allow 5807/tcp ``` --- ## 4. 部署后验证清单 -- [ ] `curl http://127.0.0.1:5804/api/health` → `{"status":"ok"}` -- [ ] `curl http://127.0.0.1:5804/api/services` → 返回 5 个服务状态 -- [ ] 浏览器打开 `http://192.168.1.246:5804` → Services Tab 显示服务状态 +- [ ] `curl http://127.0.0.1:5807/api/health` → `{"status":"ok"}` +- [ ] `curl http://127.0.0.1:5807/api/services` → 返回 5 个服务状态 +- [ ] 浏览器打开 `http://192.168.1.246:5807` → Services Tab 显示服务状态 - [ ] Dashboard F 健康 Tab → 定时任务状态显示正常 - [ ] 点击各模块 ?§ 按钮 → 弹出 spec 帮助内容 - [ ] `python3 agents_health_check.py` → 无输出(全正常) diff --git a/docs/QUICKSTART.md b/docs/QUICKSTART.md index b28d3be3..ad53ca40 100644 --- a/docs/QUICKSTART.md +++ b/docs/QUICKSTART.md @@ -1,6 +1,6 @@ # MoFin — 快速操作手册 -> 生产环境: Linux 192.168.1.246 | 端口: API 8899 / Dashboard 5804 +> 生产环境: Linux 192.168.1.246 | 端口: API 8899 / Dashboard 5807 --- @@ -8,10 +8,10 @@ ```bash # 打开 Dashboard 看全局 -http://192.168.1.246:5804 +http://192.168.1.246:5807 # 命令行快速状态 -ssh hmo@192.168.1.246 "curl -s http://127.0.0.1:5804/api/services | python3 -m json.tool | head -20" +ssh hmo@192.168.1.246 "curl -s http://127.0.0.1:5807/api/services | python3 -m json.tool | head -20" ``` --- @@ -71,7 +71,7 @@ ssh hmo@192.168.1.246 "cd ~/MoFin && git pull --rebase" ssh hmo@192.168.1.246 "sudo systemctl restart mofin-dashboard" # 3. 验证 -ssh hmo@192.168.1.246 "curl -s http://127.0.0.1:5804/api/health" +ssh hmo@192.168.1.246 "curl -s http://127.0.0.1:5807/api/health" ``` --- diff --git a/scripts/strategy-staleness-check.py b/scripts/strategy-staleness-check.py index db5c9ea3..a77bf060 100644 --- a/scripts/strategy-staleness-check.py +++ b/scripts/strategy-staleness-check.py @@ -13,7 +13,7 @@ import json, sys, os, re, urllib.request, sqlite3 sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..')) from datetime import datetime -from mo_data import read_decisions, read_portfolio, get_price +from mo_data import read_decisions, read_portfolio DB_PATH = '/home/hmo/web-dashboard/data/mofin.db' OUTPUT_PATH = "/home/hmo/web-dashboard/data/strategy_staleness_report.json" @@ -23,7 +23,25 @@ CRITICAL_DAYS = 21 # 超过21天→严重警告 DIVERGENCE_WARN = 30 # 偏离买入区>30%→警告 DIVERGENCE_CRIT = 50 # 偏离>50%→严重 -# ── 使用 mo_data.get_price 统一获取价格 ── +def get_price(code): + """从腾讯API获取当前价""" + try: + market = "sh" if code.startswith("6") else "sz" if code.startswith("0") or code.startswith("3") else "" + if code.startswith(("00", "30")) or code.startswith("68"): + market = "sh" if code.startswith("6") else "sz" + elif code.startswith(("01", "02", "03")): + market = "sz" + url = f"http://qt.gtimg.cn/q={market}{code}" + req = urllib.request.Request(url, headers={"User-Agent": "curl/7.81"}) + with urllib.request.urlopen(req, timeout=5) as resp: + raw = resp.read().decode("gbk") + parts = raw.split("~") + if len(parts) > 3: + price = float(parts[3]) if parts[3] else 0 + chg = float(parts[32]) if parts[32] else 0 + return price, chg if price > 0 else (None, None) + except: pass + return None, None def parse_buy_zone(current): """从策略current字段提取买入区间最低和最高""" diff --git a/specs/dashboard.json b/specs/dashboard.json index b52d5e50..9ec8543d 100644 --- a/specs/dashboard.json +++ b/specs/dashboard.json @@ -1,17 +1,17 @@ { "module": "dashboard", "version": "1.0", - "purpose": "MoFin 管理门户。独立 Flask 应用(端口 5804),统一展示系统健康状态、模块 spec 帮助和监控数据。", + "purpose": "MoFin 管理门户。独立 Flask 应用(端口 5807),统一展示系统健康状态、模块 spec 帮助和监控数据。", "human_help": { "title": "Dashboard — 管理门户", "description": [ "MoFin 统一管理面板,提供系统健康状态总览和各模块的帮助文档。", "采用深色主题 Web UI,与 AgentsMeeting Dashboard 一致的视觉风格。", - "访问地址: http://192.168.1.246:5804" + "访问地址: http://192.168.1.246:5807" ], "usage": [ - "打开浏览器访问 http://192.168.1.246:5804", + "打开浏览器访问 http://192.168.1.246:5807", "F 健康 Tab — 查看所有服务运行状态和健康管线数据", "G 规范 Tab — 查看开发规范文档", "点击 ? 按钮 — 查看面向人类的模块帮助", @@ -39,7 +39,7 @@ "server.py :8899 — 业务 API(Dashboard 通过 HTTP 检测其可达性)" ], "constraints": [ - "Dashboard 部署在 Linux 246 上,端口 5804", + "Dashboard 部署在 Linux 246 上,端口 5807", "通过 systemd 守护(mofin-dashboard.service)", "不依赖 server.py :8899(可独立运行)", "前端 5 秒轮询 /api/services + /api/expected",