| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- from datetime import datetime
- from sqlalchemy import (
- Column,
- Integer,
- BigInteger,
- String,
- Boolean,
- DateTime,
- UniqueConstraint,
- Index,
- )
- from app.core.database import Base
- class ProxyReputation(Base):
- """
- 代理出口 IP 维度信誉状态表
- 以 (plugin_name, egress_ip) 为主键聚合分析各 IP 的健康度与信誉分
- """
- __tablename__ = "proxy_reputation"
- id = Column(BigInteger().with_variant(Integer, "sqlite"), primary_key=True, autoincrement=True)
- plugin_name = Column(String(64), nullable=False, comment="插件名称,如 vfs_plugin")
- egress_ip = Column(String(64), nullable=False, comment="公网出口IP")
- score = Column(Integer, nullable=False, default=60, comment="信誉分 0-100")
- state = Column(String(16), nullable=False, default="probation", comment="trusted, probation, blocked")
- total_calls = Column(Integer, nullable=False, default=0, comment="总调用次数")
- success_calls = Column(Integer, nullable=False, default=0, comment="成功调用次数")
- consecutive_successes = Column(Integer, nullable=False, default=0, comment="连续成功次数")
- consecutive_fails = Column(Integer, nullable=False, default=0, comment="连续失败次数")
- last_http_code = Column(Integer, nullable=True, comment="最近一次 HTTP 响应码")
- last_error_type = Column(String(128), nullable=True, comment="最近一次错误类型")
- last_seen = Column(Integer, nullable=True, comment="最近一次调用秒级时间戳")
- unblock_time = Column(DateTime, nullable=True, comment="封禁解封时间点")
- created_at = Column(DateTime, default=datetime.utcnow, nullable=False)
- updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False)
- __table_args__ = (
- UniqueConstraint("plugin_name", "egress_ip", name="uk_plugin_ip"),
- Index("idx_plugin_state", "plugin_name", "state"),
- )
- class ProxyTelemetryLog(Base):
- """
- 代理调用流水日志表
- 用于原始调用记录留存及全局故障率滑动窗口统计
- """
- __tablename__ = "proxy_telemetry_log"
- id = Column(BigInteger().with_variant(Integer, "sqlite"), primary_key=True, autoincrement=True)
- client_id = Column(String(64), nullable=False, comment="上报客户端ID")
- plugin_name = Column(String(64), nullable=False, comment="插件名称")
- egress_ip = Column(String(64), nullable=False, comment="出口IP")
- local_port = Column(Integer, nullable=True, comment="客户端本地代理端口")
- node_name = Column(String(128), nullable=True, comment="节点标签名称")
- action = Column(String(32), nullable=False, comment="调用场景: spawn, query, book 等")
- success = Column(Boolean, nullable=False, comment="是否成功")
- http_code = Column(Integer, nullable=False, comment="HTTP状态码")
- error_type = Column(String(128), nullable=True, comment="错误描述")
- latency_ms = Column(Integer, nullable=False, default=0, comment="耗时毫秒")
- timestamp = Column(Integer, nullable=False, comment="客户端上报时间戳")
- created_at = Column(DateTime, default=datetime.utcnow, nullable=False)
- __table_args__ = (
- Index("idx_telemetry_created_at", "created_at"),
- Index("idx_telemetry_plugin_created", "plugin_name", "created_at"),
- )
|