package models import ( "time" "gorm.io/gorm" ) // AgentReport Agent 上报的原始指标数据 // Logan.Li type AgentReport struct { ID uint `gorm:"primarykey" json:"id"` Hostname string `gorm:"size:255;index;not null" json:"hostname"` CPUUsage float64 `gorm:"type:decimal(6,2)" json:"cpu_usage"` // CPU 使用率 % CPUCores int `json:"cpu_cores"` // CPU 核心数 Load1 float64 `gorm:"type:decimal(8,2)" json:"load1"` // 1分钟负载 Load5 float64 `gorm:"type:decimal(8,2)" json:"load5"` // 5分钟负载 Load15 float64 `gorm:"type:decimal(8,2)" json:"load15"` // 15分钟负载 MemTotal float64 `gorm:"type:decimal(10,2)" json:"mem_total"` // 总内存 GB MemUsed float64 `gorm:"type:decimal(10,2)" json:"mem_used"` // 已用内存 GB MemUsage float64 `gorm:"type:decimal(6,2)" json:"mem_usage"` // 内存使用率 % DiskInfo string `gorm:"type:text" json:"disk_info"` // 磁盘信息 JSON PortInfo string `gorm:"type:text" json:"port_info"` // 端口信息 JSON NetInfo string `gorm:"type:text" json:"net_info"` // 网络指标 JSON DiskIOInfo string `gorm:"type:text" json:"disk_io_info"` // 磁盘 IO JSON ReportTime time.Time `json:"report_time"` // 上报时间 CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` DeletedAt gorm.DeletedAt `gorm:"index" json:"-"` } func (AgentReport) TableName() string { return "agent_reports" } // AgentLatestResponse Agent 最新状态(含服务器元信息)// Logan.Li type AgentLatestResponse struct { Hostname string `json:"hostname"` IP string `json:"ip"` CPUUsage float64 `json:"cpu_usage"` CPUCores int `json:"cpu_cores"` MemUsage float64 `json:"mem_usage"` MemTotal float64 `json:"mem_total"` MemUsed float64 `json:"mem_used"` DiskUsage float64 `json:"disk_usage"` DiskInfo string `json:"disk_info"` NetInfo string `json:"net_info"` ReportTime string `json:"report_time"` AgentVersion string `json:"agent_version"` AgentStatus string `json:"agent_status"` OS string `json:"os"` Region string `json:"region"` } // AgentReportRequest Agent 上报请求体 // Logan.Li type AgentReportRequest struct { Hostname string `json:"hostname" binding:"required"` Timestamp string `json:"timestamp"` AgentVersion string `json:"agent_version"` // Agent 版本号 CPU CPUMetric `json:"cpu"` Memory MemMetric `json:"memory"` Disks []DiskMetric `json:"disks"` Ports []PortMetric `json:"ports"` Network NetworkStat `json:"network"` // 网络指标 DiskIO DiskIOStat `json:"disk_io"` // 磁盘 IO } type CPUMetric struct { UsagePercent float64 `json:"usage_percent"` CoreCount int `json:"core_count"` Load1 float64 `json:"load1"` Load5 float64 `json:"load5"` Load15 float64 `json:"load15"` } type MemMetric struct { TotalGB float64 `json:"total_gb"` UsedGB float64 `json:"used_gb"` CachedGB float64 `json:"cached_gb"` UsagePercent float64 `json:"usage_percent"` } type DiskMetric struct { Mount string `json:"mount"` Device string `json:"device"` TotalGB float64 `json:"total_gb"` UsedGB float64 `json:"used_gb"` UsagePercent float64 `json:"usage_percent"` } type PortMetric struct { Port int `json:"port"` Protocol string `json:"protocol"` Process string `json:"process"` PID int `json:"pid"` } // NetworkStat 网络指标(Agent 上报) type NetworkStat struct { TCPEstablished int `json:"tcp_established"` TCPTimeWait int `json:"tcp_time_wait"` TCPTotal int `json:"tcp_total"` NicName string `json:"nic_name"` NetRxBPS float64 `json:"net_rx_bps"` NetTxBPS float64 `json:"net_tx_bps"` } // DiskIOStat 磁盘 IO 指标(Agent 上报) type DiskIOStat struct { ReadBPS float64 `json:"read_bps"` WriteBPS float64 `json:"write_bps"` ReadIOPS float64 `json:"read_iops"` WriteIOPS float64 `json:"write_iops"` }