- 主菜单「监控告警」→「监控中心」 - 「告警中心」→「告警服务」移至链路追踪下方 - 新增资源监控 Tab 页(主机/中间件/SNMP/站点拨测) - Agent 新增网络采集器(network)和磁盘IO采集器(diskio) - 后端扩展 Agent 上报模型,支持 NetworkStat/DiskIOStat - 前端 ServerTableRow 展示网络和磁盘IO实时指标 - WebSocket MetricsUpdate 推送扩展
94 lines
3.5 KiB
Go
94 lines
3.5 KiB
Go
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"
|
|
}
|
|
|
|
// AgentReportRequest Agent 上报请求体 // Logan.Li
|
|
type AgentReportRequest struct {
|
|
Hostname string `json:"hostname" binding:"required"`
|
|
Timestamp string `json:"timestamp"`
|
|
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"`
|
|
}
|