package model import "time" // MetricsAggregate 指标聚合数据(Redis 热数据 → MySQL 时序聚合)// Logan.Li // 替代旧名 MetricsKline,OHLC 对监控无意义,改用 max/min/avg/p95 type MetricsAggregate struct { ID uint `gorm:"primarykey" json:"id"` Hostname string `gorm:"size:255;index:idx_agg;not null" json:"hostname"` Metric string `gorm:"size:32;index:idx_agg;not null" json:"metric"` // cpu / mem / load1 / disk / net_rx / net_tx Interval string `gorm:"size:8;index:idx_agg;not null" json:"interval"` // 1m / 5m / 1h / 6h / 1d Avg float64 `gorm:"type:decimal(10,2)" json:"avg"` MaxV float64 `gorm:"column:max_v;type:decimal(10,2)" json:"max"` MinV float64 `gorm:"column:min_v;type:decimal(10,2)" json:"min"` P95 float64 `gorm:"type:decimal(10,2)" json:"p95"` Count int `json:"count"` BucketTime time.Time `gorm:"index:idx_agg;not null" json:"bucket_time"` CreatedAt time.Time `json:"created_at"` } func (MetricsAggregate) TableName() string { return "monitor_metrics_aggregate" } // AggregateReq 聚合触发请求 type AggregateReq struct { Hostname string `json:"hostname" binding:"required"` Metric string `json:"metric" binding:"required"` // cpu / mem / load1 } // AggregateQueryReq 聚合查询参数 type AggregateQueryReq struct { Hostname string `form:"hostname" binding:"required"` Metric string `form:"metric" binding:"required"` Interval string `form:"interval" binding:"required"` From string `form:"from" binding:"required"` // RFC3339 To string `form:"to" binding:"required"` // RFC3339 }