Files
MoFin/archive/scripts/check_price_monitor.py
T
知微 ccea9fcf09 cleanup: 去冗余+归档一次性脚本
- 移除重复的系统健康检查-每日(no_agent版,与LLM版重叠)
- 归档42个一次性脚本(移出MoFin/scripts→archive/scripts):
  - fix_*: 历史数据修复(11个)
  - migrate_*/rollback_*: 数据迁移(2个)
  - 一次性数据修复: bulk/close/data_freshness等(16个)
  - check_*/verify_*/diagnose_*: 历史诊断工具(12个)
  - test_*: 测试脚本(3个)
- 84个活跃脚本, 0架构违规, 31张healthy数据表
2026-07-09 00:19:00 +08:00

51 lines
1.6 KiB
Python

#!/usr/bin/env python3
"""保活检测:检查 DB 中的价格是否新鲜,price_monitor 是否在运行"""
import sqlite3, subprocess, sys, os
from datetime import datetime
DB = '/home/hmo/web-dashboard/data/mofin.db'
def check():
issues = []
# 1. 检查 price_monitor 进程
try:
r = subprocess.run(['pgrep', '-f', 'price_monitor'], capture_output=True, text=True)
if r.stdout.strip():
print(f" price_monitor: RUNNING (PID {r.stdout.strip()})")
else:
issues.append("price_monitor 未运行")
print(f" price_monitor: NOT RUNNING")
except:
pass
# 2. 检查 DB 价格新鲜度
try:
db = sqlite3.connect(DB)
db.row_factory = sqlite3.Row
row = db.execute("SELECT updated_at FROM portfolio_summary WHERE id=1").fetchone()
if row and row['updated_at']:
try:
dt = datetime.strptime(row['updated_at'], '%Y-%m-%d %H:%M')
age = (datetime.now() - dt).total_seconds() / 60
if age > 10:
issues.append(f"DB 价格 {age:.0f} 分钟未更新")
print(f" DB updated: {row['updated_at']} ({age:.0f} min ago)")
except:
pass
else:
issues.append("DB 无价格数据")
db.close()
except Exception as e:
issues.append(f"DB 读取失败: {e}")
# 3. 输出
if issues:
print(f"\n ISSUES: {', '.join(issues)}")
return 1
print(" OK")
return 0
if __name__ == '__main__':
sys.exit(check())