style: 去掉全部 emoji, 状态用颜色文字表达(一致/不一致/正常/过热/需关注)
emoji 在企微客户端渲染成大色块很扎眼; 改为纯文字+<font color> 三色, 状态词直接着色, 数据保持素色, 版式标题+单行结论+引用详情不变
This commit is contained in:
@@ -291,11 +291,11 @@ def _check_services() -> dict:
|
||||
|
||||
|
||||
def _mark(pct: float | None, threshold: int) -> str:
|
||||
"""百分比展示:超阈值用 warning 色加粗+🔴。"""
|
||||
"""百分比展示:超阈值用 warning 色加粗。"""
|
||||
if pct is None:
|
||||
return "—"
|
||||
if pct >= threshold:
|
||||
return f'<font color="warning">**{pct:.0f}%** 🔴</font>'
|
||||
return f'<font color="warning">**{pct:.0f}%**</font>'
|
||||
return f"{pct:.0f}%"
|
||||
|
||||
|
||||
@@ -343,7 +343,7 @@ def device_check(alarm_threshold: int = 80) -> dict:
|
||||
print(f"[device-check] 磁盘检查失败: {err}")
|
||||
|
||||
threshold = alarm_threshold
|
||||
header = f"## 🖥 设备日报 {datetime.now():%m-%d %H:%M}(24h 采样 {agg['count']} 次"
|
||||
header = f"## 设备日报 {datetime.now():%m-%d %H:%M}(24h 采样 {agg['count']} 次"
|
||||
if agg.get("firstTs"):
|
||||
first = datetime.fromisoformat(agg["firstTs"])
|
||||
if first > datetime.now() - timedelta(hours=23):
|
||||
@@ -397,8 +397,12 @@ def device_check(alarm_threshold: int = 80) -> dict:
|
||||
else:
|
||||
mem_txt = "显存 无数据"
|
||||
temp_peak = g.get("tempPeak")
|
||||
temp_txt = (f"温度峰 {temp_peak:.0f}°C" + (" 🔴过热" if temp_peak >= GPU_TEMP_WARN else " ✅")
|
||||
if temp_peak is not None else "温度 无数据")
|
||||
if temp_peak is None:
|
||||
temp_txt = "温度 无数据"
|
||||
elif temp_peak >= GPU_TEMP_WARN:
|
||||
temp_txt = f'温度峰 {temp_peak:.0f}°C <font color="warning">过热</font>'
|
||||
else:
|
||||
temp_txt = f"温度峰 {temp_peak:.0f}°C 正常"
|
||||
lines.append(f"**GPU** {name} {util_txt} | {mem_txt} | {temp_txt}")
|
||||
else:
|
||||
gpus_now = _check_gpus()
|
||||
@@ -415,22 +419,25 @@ def device_check(alarm_threshold: int = 80) -> dict:
|
||||
if docker.get("running") is None:
|
||||
docker_txt = issues[0]["issue"] if issues else "不可用"
|
||||
else:
|
||||
docker_txt = f"运行 {docker['running']}/{docker.get('total', '?')} · 异常 {len(issues)}" + ("🔴" if issues else "")
|
||||
n_issues = len(issues)
|
||||
docker_txt = "运行 " + f"{docker['running']}/{docker.get('total', '?')} · 异常 "
|
||||
docker_txt += f'<font color="warning">{n_issues}</font>' if n_issues else "0"
|
||||
if svc:
|
||||
docker_txt += f" | OCR {'✅' if svc.get('ocr') else '🔴'} | PG {'✅' if svc.get('pg') else '🔴'}"
|
||||
docker_txt += " · OCR " + ("正常" if svc.get("ocr") else '<font color="warning">异常</font>')
|
||||
docker_txt += " · PG " + ("正常" if svc.get("pg") else '<font color="warning">异常</font>')
|
||||
lines.append(f"**Docker** {docker_txt}")
|
||||
for it in issues[:8]:
|
||||
lines.append(f"> 🔴 {it['name']}:{it['issue']}")
|
||||
lines.append(f"> {it['name']}:{it['issue']}")
|
||||
|
||||
failures = checks.get("prefectFailures") or []
|
||||
if failures:
|
||||
lines.append(f"**失败任务(24h)** {len(failures)} 次 🔴")
|
||||
lines.append(f'**任务** 失败 <font color="warning">{len(failures)} 次</font>(24h)')
|
||||
for f in failures[:5]:
|
||||
lines.append(f"> {f['flow']}「{f['name']}」{f['state']} · {(f.get('start') or '')[5:]}")
|
||||
lines.append(f"> {f['flow']}:{f['name']} {f['state']} {(f.get('start') or '')[5:]}")
|
||||
if len(failures) > 5:
|
||||
lines.append(f"> …共 {len(failures)} 次")
|
||||
else:
|
||||
lines.append("**失败任务(24h)** 0 ✅")
|
||||
lines.append("**任务** 失败 0 次(24h)")
|
||||
|
||||
mem_peak_for_alarm = mem.get("peak") if mem else None
|
||||
swap_peak_for_alarm = swap.get("peak") if swap else None
|
||||
@@ -442,8 +449,8 @@ def device_check(alarm_threshold: int = 80) -> dict:
|
||||
or any((g.get("tempPeak") or 0) >= GPU_TEMP_WARN for g in gpu_stats)
|
||||
or bool(issues) or bool(failures) or not svc.get("ocr") or not svc.get("pg")
|
||||
)
|
||||
lines.append('<font color="warning">🔴 有项目需要处理,见上</font>' if alarms
|
||||
else '<font color="info">✅ 一切正常</font>')
|
||||
lines.append('<font color="warning">有项目需要处理,见上</font>' if alarms
|
||||
else '<font color="info">一切正常</font>')
|
||||
|
||||
content = "\n".join(lines)
|
||||
sent = send_markdown(content)
|
||||
|
||||
Reference in New Issue
Block a user