feat: persist probe quality and notification outbox
This commit is contained in:
@@ -1,18 +1,32 @@
|
||||
from datetime import datetime
|
||||
from sqlalchemy import Column, Integer, Float, Boolean, DateTime, BigInteger
|
||||
from sqlalchemy import BigInteger, Boolean, Column, DateTime, Float, Index, Integer, String
|
||||
from .device import Base
|
||||
|
||||
|
||||
PRIMARY_KEY_TYPE = BigInteger().with_variant(Integer, "sqlite")
|
||||
|
||||
|
||||
class PingRecord(Base):
|
||||
"""单次 ping 结果记录"""
|
||||
__tablename__ = "ping_records"
|
||||
|
||||
id = Column(BigInteger, primary_key=True, autoincrement=True)
|
||||
id = Column(PRIMARY_KEY_TYPE, primary_key=True, autoincrement=True)
|
||||
device_id = Column(Integer, nullable=False, index=True)
|
||||
is_alive = Column(Boolean, nullable=False, comment="是否通")
|
||||
response_time_ms = Column(Float, nullable=True, comment="响应时间毫秒,不通则为 NULL")
|
||||
round_num = Column(Integer, nullable=False, comment="轮次编号(从 1 递增)")
|
||||
created_at = Column(DateTime, default=datetime.now, index=True, comment="记录时间")
|
||||
|
||||
sent_count = Column(Integer, nullable=True, comment="本轮发包数")
|
||||
received_count = Column(Integer, nullable=True, comment="本轮收包数")
|
||||
packet_loss_percent = Column(Float, nullable=True, comment="本轮丢包率百分比")
|
||||
average_rtt_ms = Column(Float, nullable=True, comment="本轮平均时延毫秒")
|
||||
is_valid = Column(Boolean, nullable=False, default=True, comment="探测结果是否有效")
|
||||
failure_reason = Column(String(512), nullable=True, comment="无效探测的原因")
|
||||
|
||||
__table_args__ = (
|
||||
Index("idx_ping_records_device_created_at", "device_id", "created_at"),
|
||||
)
|
||||
|
||||
def __repr__(self):
|
||||
return f"<PingRecord(device={self.device_id}, alive={self.is_alive}, rtt={self.response_time_ms})>"
|
||||
|
||||
Reference in New Issue
Block a user