"""系统资源监控采样模型(契约1.23)。 MetricSampler 后台线程按固定间隔采集 CPU/内存写入本表, 支撑系统管理页签的资源趋势图;磁盘分区为实时查询不采样。 纯时序追加数据:无软删/行版本字段,按保留窗口直接物理删除。 """ from __future__ import annotations from datetime import datetime from sqlalchemy import BigInteger, Float, Index, text from sqlalchemy.dialects.mysql import DATETIME from sqlalchemy.orm import Mapped, mapped_column from dms.extensions import db class MetricSample(db.Model): __tablename__ = "sys_metric_sample" __table_args__ = (Index("ix_sys_metric_sample_time", "sampled_at"),) id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True) sampled_at: Mapped[datetime] = mapped_column( DATETIME(fsp=3), nullable=False, server_default=text("CURRENT_TIMESTAMP(3)"), ) # CPU 使用率(0-100,NULL=本次采集失败) cpu_percent: Mapped[float | None] = mapped_column(Float, nullable=True) mem_used_bytes: Mapped[int] = mapped_column(BigInteger, nullable=False) mem_total_bytes: Mapped[int] = mapped_column(BigInteger, nullable=False)