From 6726524c5070f9fc19e17ca366d798a1570a7a35 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 8 Jul 2026 14:46:18 +0800 Subject: [PATCH] fix: db.get_or_404 -> query.get_or_404 + rename to Palladium Monitor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复删除快照时 AttributeError: SQLAlchemy.get_or_404 (低版本兼容) - UI/标题/邮件主题从 'Palladium Z1 Monitor' 改为 'Palladium Monitor' --- README.md | 10 +++++----- app.py | 10 +++++----- collect.py | 6 +++--- mailer.py | 20 ++++++++++---------- palladium-monitor/README.md | 4 ++-- palladium-monitor/app.py | 10 +++++----- palladium-monitor/collect.sh | 2 +- palladium-monitor/templates/base.html | 6 +++--- palladium-monitor/templates/dashboard.html | 2 +- palladium-monitor/templates/history.html | 2 +- palladium-monitor/templates/snapshot.html | 2 +- static/style.css | 2 +- templates/base.html | 6 +++--- templates/dashboard.html | 2 +- templates/email_config.html | 4 ++-- templates/history.html | 2 +- templates/snapshot.html | 2 +- 17 files changed, 46 insertions(+), 46 deletions(-) diff --git a/README.md b/README.md index 943865f..7bc2c0b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# Palladium Z1 Monitor +# Palladium Monitor -LD 逻辑板使用监控系统 — 解析 `test_server -short` 输出,可视化展示 Palladium Z1 仿真器的逻辑板状态、逻辑板利用率、作业信息和 T-Pod 可用性。 +LD 逻辑板使用监控系统 — 解析 `test_server -short` 输出,可视化展示 Palladium 仿真器的逻辑板状态、逻辑板利用率、作业信息和 T-Pod 可用性。 ## 功能 @@ -37,7 +37,7 @@ python3 app.py ### 方式二:API 推送 (collect.py + 一键安装) -在 Palladium Z1 主机上部署采集 agent,**推荐**用一键脚本(处理 env 加载、crontab、依赖): +在 Palladium 主机上部署采集 agent,**推荐**用一键脚本(处理 env 加载、crontab、依赖): ```bash # 把 palladium-monitor/ 整个目录 scp 到 Z1 主机, 然后: @@ -194,7 +194,7 @@ gunicorn --workers 2 --bind 0.0.0.0:5100 app:app | `SMTP_USE_TLS` | ❌ | `true` | 是否用 STARTTLS (端口 587 时设为 `true`) | | `SMTP_USE_SSL` | ❌ | `false` | 是否用隐式 SSL (端口 465 时设为 `true`) | | `MAIL_FROM` | 启用时必填 | — | 发件人邮箱 | -| `MAIL_FROM_NAME` | ❌ | `Palladium Z1 Monitor` | 发件人显示名 | +| `MAIL_FROM_NAME` | ❌ | `Palladium Monitor` | 发件人显示名 | | `MAIL_TO` | 启用时必填 | — | 收件人列表, 英文逗号分隔 (如 `alice@x.com,bob@y.com`) | | `MAIL_SEND_HOUR` | ❌ | `9` | 每天发送时间-小时 (0-23) | | `MAIL_SEND_MINUTE` | ❌ | `0` | 每天发送时间-分钟 (0-59) | @@ -251,7 +251,7 @@ ExecStart=/usr/bin/gunicorn --workers 2 --bind 0.0.0.0:5100 app:app #### 邮件内容示例 每日报告包含: -- **主题**: `[Palladium Z1] 每日报告 YYYY-MM-DD — 利用率 X.X%` +- **主题**: `[Palladium] 每日报告 YYYY-MM-DD — 利用率 X.X%` - **正文 (HTML + 纯文本)**: 系统信息 / 当前指标卡片 / 近 24h 趋势统计 + 样本柱状图 / 离线板列表 / 活跃作业列表 - **多部分**: 同时发 HTML 和纯文本, 邮件客户端自动选最合适的渲染 diff --git a/app.py b/app.py index 0f790b8..35a6192 100644 --- a/app.py +++ b/app.py @@ -1,9 +1,9 @@ from typing import List, Dict, Tuple, Set, Any, Optional, Union #!/usr/bin/env python3 """ -Palladium Z1 Monitor — LD逻辑板使用监控系统 +Palladium Monitor — LD逻辑板使用监控系统 -解析 `test_server -short` 输出,展示 Palladium Z1 仿真器的 +解析 `test_server -short` 输出,展示 Palladium 仿真器的 逻辑板 (LD) 状态、逻辑板利用率、作业信息和 T-Pod 可用性。 支持两种数据来源: @@ -520,7 +520,7 @@ def history(): @app.route("/snapshot/") def snapshot_detail(sid): """单条快照详情。""" - snapshot = db.get_or_404(ScanSnapshot, sid) + snapshot = ScanSnapshot.query.get_or_404(sid) stats = { "total_boards": snapshot.total_boards, "online_boards": snapshot.online_boards, @@ -681,7 +681,7 @@ def api_history(): @app.route("/api/snapshot//delete", methods=["POST"]) def delete_snapshot(sid): """删除指定快照。""" - snapshot = db.get_or_404(ScanSnapshot, sid) + snapshot = ScanSnapshot.query.get_or_404(sid) db.session.delete(snapshot) db.session.commit() return redirect(url_for("history")) @@ -1270,7 +1270,7 @@ if __name__ == "__main__": seed_sample_data() start_email_scheduler() print("════════════════════════════════════════════════════════") - print(" Palladium Z1 Monitor") + print(" Palladium Monitor") print(" http://0.0.0.0:5100") print("════════════════════════════════════════════════════════") app.run(host="0.0.0.0", port=5100, debug=True) diff --git a/collect.py b/collect.py index 450247e..b7b0462 100644 --- a/collect.py +++ b/collect.py @@ -1,9 +1,9 @@ from typing import List, Dict, Tuple, Set, Any, Optional, Union #!/usr/bin/env python3 """ -collect.py — Palladium Z1 远程数据采集推送脚本 +collect.py — Palladium 远程数据采集推送脚本 -在 Palladium Z1 主机上运行,执行 test_server -short 并将结果推送到监控服务器。 +在 Palladium 主机上运行,执行 test_server -short 并将结果推送到监控服务器。 用法: python3 collect.py # 默认配置 @@ -153,7 +153,7 @@ def push_to_monitor(url: str, raw_output: str, source: str, # ═══════════════════════════════════════════════════════════════════════════ def main() -> int: parser = argparse.ArgumentParser( - description="Palladium Z1 数据采集推送 (cron 友好, 带重试和日志)", + description="Palladium 数据采集推送 (cron 友好, 带重试和日志)", formatter_class=argparse.ArgumentDefaultsHelpFormatter, ) parser.add_argument("--url", default=DEFAULT_URL, diff --git a/mailer.py b/mailer.py index 5e4eb89..31c8038 100644 --- a/mailer.py +++ b/mailer.py @@ -1,6 +1,6 @@ from typing import List, Dict, Tuple, Set, Any, Optional, Union """ -mailer.py — Palladium Z1 每日报告邮件发送 +mailer.py — Palladium 每日报告邮件发送 通过 SMTP 把"今日快照 + 24h 趋势"汇总发送到指定邮箱。 所有配置都从环境变量读 (生产建议用 systemd EnvironmentFile 或 .env)。 @@ -79,7 +79,7 @@ def _build_config_from_env() -> dict: "smtp_use_tls": _bool("SMTP_USE_TLS", True), "smtp_use_ssl": _bool("SMTP_USE_SSL", False), "from_addr": os.environ.get("MAIL_FROM", "").strip(), - "from_name": os.environ.get("MAIL_FROM_NAME", "Palladium Z1 Monitor").strip(), + "from_name": os.environ.get("MAIL_FROM_NAME", "Palladium Monitor").strip(), "to_addrs": [a.strip() for a in os.environ.get("MAIL_TO", "").split(",") if a.strip()], "send_hour": _int_env("MAIL_SEND_HOUR", 9), "send_minute": _int_env("MAIL_SEND_MINUTE", 0), @@ -109,7 +109,7 @@ def _build_config_from_dict(raw: Dict[str, str]) -> dict: "smtp_use_tls": _b("smtp_use_tls", True), "smtp_use_ssl": _b("smtp_use_ssl", False), "from_addr": _s("from_addr"), - "from_name": _s("from_name") or "Palladium Z1 Monitor", + "from_name": _s("from_name") or "Palladium Monitor", "to_addrs": [a.strip() for a in _s("to_addrs").split(",") if a.strip()], "send_hour": _i("send_hour", 9), "send_minute": _i("send_minute", 0), @@ -138,7 +138,7 @@ def save_config(data: dict) -> int: "smtp_use_tls": str(data.get("smtp_use_tls", True)).lower(), "smtp_use_ssl": str(data.get("smtp_use_ssl", False)).lower(), "from_addr": str(data.get("from_addr", "")).strip(), - "from_name": str(data.get("from_name", "Palladium Z1 Monitor")).strip(), + "from_name": str(data.get("from_name", "Palladium Monitor")).strip(), "to_addrs": to_addrs_str.strip(), "send_hour": str(data.get("send_hour", 9)), "send_minute": str(data.get("send_minute", 0)), @@ -310,11 +310,11 @@ def _render_text(data: dict, base_url: str) -> str: """纯文本版本 (HTML 不支持时回退)。""" latest = data["latest"] if not latest: - return "Palladium Z1 Monitor — 当前无快照数据, 无法生成报告。\n" + return "Palladium Monitor — 当前无快照数据, 无法生成报告。\n" lines = [] title_date = _fmt_ts(latest.timestamp, "%Y-%m-%d") - lines.append(f"Palladium Z1 每日报告 — {title_date}") + lines.append(f"Palladium 每日报告 — {title_date}") lines.append("=" * 60) lines.append(f"生成时间: {_fmt_ts(data['now_utc'])} UTC") lines.append(f"快照时间: {_fmt_ts(latest.timestamp)}") @@ -381,7 +381,7 @@ def _render_html(data: dict, base_url: str) -> str: if not latest: return ( '' - '

Palladium Z1 Monitor

' + '

Palladium Monitor

' '

当前无快照数据, 无法生成报告。

' '' ) @@ -475,7 +475,7 @@ def _render_html(data: dict, base_url: str) -> str:
-

⚡ Palladium Z1 每日报告

+

⚡ Palladium 每日报告

{title_date}
@@ -532,7 +532,7 @@ def _render_html(data: dict, base_url: str) -> str:
- 由 Palladium Z1 Monitor 自动生成 · + 由 Palladium Monitor 自动生成 · {_fmt_ts(data['now_utc'], '%Y-%m-%d %H:%M:%S')} UTC
@@ -552,7 +552,7 @@ def render_report(data: dict, cfg: dict) -> Tuple[str, str, str]: else: title_date = _fmt_ts(data["now_utc"], "%Y-%m-%d") util = f"{latest.utilization:.1f}%" if latest else "—" - subject = f"[Palladium Z1] 每日报告 {title_date} — 利用率 {util}" + subject = f"[Palladium] 每日报告 {title_date} — 利用率 {util}" html = _render_html(data, cfg["monitor_base_url"]) text = _render_text(data, cfg["monitor_base_url"]) return subject, html, text diff --git a/palladium-monitor/README.md b/palladium-monitor/README.md index 489e7ac..1cfaf16 100644 --- a/palladium-monitor/README.md +++ b/palladium-monitor/README.md @@ -1,6 +1,6 @@ -# Palladium Z1 Monitor +# Palladium Monitor -LD 逻辑板使用监控系统 — 解析 `test_server -short` 输出,可视化展示 Palladium Z1 仿真器的逻辑板状态、逻辑板利用率、作业信息和 T-Pod 可用性。 +LD 逻辑板使用监控系统 — 解析 `test_server -short` 输出,可视化展示 Palladium 仿真器的逻辑板状态、逻辑板利用率、作业信息和 T-Pod 可用性。 ## 功能 diff --git a/palladium-monitor/app.py b/palladium-monitor/app.py index 56e76a5..6708945 100644 --- a/palladium-monitor/app.py +++ b/palladium-monitor/app.py @@ -1,8 +1,8 @@ #!/usr/bin/env python3 """ -Palladium Z1 Monitor — LD逻辑板使用监控系统 +Palladium Monitor — LD逻辑板使用监控系统 -解析 `test_server -short` 输出,展示 Palladium Z1 仿真器的 +解析 `test_server -short` 输出,展示 Palladium 仿真器的 逻辑板 (LD) 状态、逻辑板利用率、作业信息和 T-Pod 可用性。 """ @@ -362,7 +362,7 @@ def history(): @app.route("/snapshot/") def snapshot_detail(sid): - snapshot = db.get_or_404(ScanSnapshot, sid) + snapshot = ScanSnapshot.query.get_or_404(sid) stats = _snapshot_stats(snapshot) racks_data = _build_racks(sid) jobs_data = JobInfo.query.filter_by(snapshot_id=sid).all() @@ -434,7 +434,7 @@ def api_history(): @app.route("/api/snapshot//delete", methods=["POST"]) def delete_snapshot(sid): - snapshot = db.get_or_404(ScanSnapshot, sid) + snapshot = ScanSnapshot.query.get_or_404(sid) db.session.delete(snapshot) db.session.commit() return redirect(url_for("history")) @@ -627,7 +627,7 @@ if __name__ == "__main__": db.create_all() seed_sample_data() print("════════════════════════════════════════════════════════") - print(" Palladium Z1 Monitor") + print(" Palladium Monitor") print(" http://0.0.0.0:5100") print("════════════════════════════════════════════════════════") app.run(host="0.0.0.0", port=5100, debug=True) diff --git a/palladium-monitor/collect.sh b/palladium-monitor/collect.sh index 4d1a4ae..144844d 100755 --- a/palladium-monitor/collect.sh +++ b/palladium-monitor/collect.sh @@ -1,6 +1,6 @@ #!/bin/bash # ═══════════════════════════════════════════════════════════════ -# collect.sh — Palladium Z1 数据采集脚本 (Shell 版, 无需 Python) +# collect.sh — Palladium 数据采集脚本 (Shell 版, 无需 Python) # # 在 Palladium 主机上运行, 执行 test_server -short 并推送到监控服务器 # diff --git a/palladium-monitor/templates/base.html b/palladium-monitor/templates/base.html index 39ea9c5..4e0b29b 100644 --- a/palladium-monitor/templates/base.html +++ b/palladium-monitor/templates/base.html @@ -3,7 +3,7 @@ - {% block title %}Palladium Z1 Monitor{% endblock %} + {% block title %}Palladium Monitor{% endblock %} {% block head %}{% endblock %} @@ -11,7 +11,7 @@