feat: 修复服务器硬件规格(CPU核/内存/磁盘) + Top 5 资源排行
修复: - agent.go ReceiveReport 写入 cpu(核数)/memory(总内存MB)/disk(总磁盘GB) 到 servers 表 - 之前 Agent 上报只写了 cpu_usage/memory_usage/disk_usage 使用率,硬件规格始终为 0 新功能: - GET /api/v1/metrics/top?metric=cpu|memory|disk&limit=5 主机排行 API - HostMonitor 新增 Top 5 排行面板: CPU/内存/磁盘 使用率排名 - TopRankCard 组件: 排名号+主机名+进度条+百分比
This commit is contained in:
1 parent
06d7451cf9
commit
737f00169f
8 files changed
+150
-567
No files matched your search
+8
-64
@@ -6,46 +6,14 @@ package model
|
||||
|
||||
// Report 为单次采集周期的完整上报报文
|
||||
type Report struct {
|
||||
Hostname string `json:"hostname"` // 主机名
|
||||
Timestamp string `json:"timestamp"` // RFC3339 格式的 UTC 时间戳
|
||||
CPU CPUStat `json:"cpu"` // CPU 指标
|
||||
Memory MemoryStat `json:"memory"` // 内存指标
|
||||
Disks []DiskStat `json:"disks"` // 磁盘指标列表
|
||||
Ports []PortStat `json:"ports"` // 监听端口列表
|
||||
Network NetworkStat `json:"network"` // 网络指标
|
||||
DiskIO DiskIOStat `json:"disk_io"` // 磁盘 IO 指标
|
||||
Middleware MiddlewareStat `json:"middleware,omitempty"` // 中间件指标(Redis/MySQL)
|
||||
System SystemStat `json:"system,omitempty"` // 系统信息(OS/内核/ulimit)
|
||||
Processes ProcessStat `json:"processes,omitempty"` // Top N 进程
|
||||
}
|
||||
|
||||
// MiddlewareStat 中间件综合指标 — 包含 Redis + MySQL
|
||||
type MiddlewareStat struct {
|
||||
Redis []RedisMetric `json:"redis,omitempty"` // Redis 实例指标
|
||||
MySQL []MySQLMetric `json:"mysql,omitempty"` // MySQL 实例指标
|
||||
}
|
||||
|
||||
// RedisMetric Redis 实例采集指标
|
||||
type RedisMetric struct {
|
||||
Instance string `json:"instance"` // 实例标识(host:port)
|
||||
Clients int `json:"clients"` // 连接客户端数
|
||||
UsedMemory int64 `json:"used_memory"` // 已用内存(字节)
|
||||
HitRate float64 `json:"hit_rate"` // 缓存命中率(%)
|
||||
QPS float64 `json:"qps"` // 每秒命令数
|
||||
Uptime int64 `json:"uptime"` // 运行时长(秒)
|
||||
Version string `json:"version"` // Redis 版本
|
||||
}
|
||||
|
||||
// MySQLMetric MySQL 实例采集指标
|
||||
type MySQLMetric struct {
|
||||
Instance string `json:"instance"` // 实例标识(host:port)
|
||||
Connections int `json:"connections"` // 当前连接数
|
||||
QPS float64 `json:"qps"` // 每秒查询数
|
||||
SlowQueries int64 `json:"slow_queries"` // 慢查询累计数
|
||||
BufferHitRate float64 `json:"buffer_hit_rate"` // 缓冲池命中率(%)
|
||||
ThreadsRunning int `json:"threads_running"` // 活跃线程数
|
||||
Uptime int64 `json:"uptime"` // 运行时长(秒)
|
||||
Version string `json:"version"` // MySQL 版本
|
||||
Hostname string `json:"hostname"` // 主机名
|
||||
Timestamp string `json:"timestamp"` // RFC3339 格式的 UTC 时间戳
|
||||
CPU CPUStat `json:"cpu"` // CPU 指标
|
||||
Memory MemoryStat `json:"memory"` // 内存指标
|
||||
Disks []DiskStat `json:"disks"` // 磁盘指标列表
|
||||
Ports []PortStat `json:"ports"` // 监听端口列表
|
||||
Network NetworkStat `json:"network"` // 网络指标
|
||||
DiskIO DiskIOStat `json:"disk_io"` // 磁盘 IO 指标
|
||||
}
|
||||
|
||||
// CPUStat CPU 相关指标
|
||||
@@ -81,27 +49,3 @@ type PortStat struct {
|
||||
Process string `json:"process"` // 进程名(可执行文件名)
|
||||
PID int `json:"pid"` // 进程 PID(无法解析时为 0)
|
||||
}
|
||||
|
||||
// SystemStat 系统信息指标
|
||||
type SystemStat struct {
|
||||
OS string `json:"os"` // 操作系统名称
|
||||
Kernel string `json:"kernel"` // 内核版本
|
||||
Arch string `json:"arch"` // 系统架构
|
||||
Hostname string `json:"hostname"` // 主机名
|
||||
UlimitNofile int64 `json:"ulimit_nofile"` // 文件句柄数上限
|
||||
UlimitNproc int64 `json:"ulimit_nproc"` // 进程数上限
|
||||
}
|
||||
|
||||
// ProcessStat 进程监控指标
|
||||
type ProcessStat struct {
|
||||
TopCPU []ProcessInfo `json:"top_cpu"` // Top 5 CPU 进程
|
||||
TopMem []ProcessInfo `json:"top_mem"` // Top 5 内存进程
|
||||
}
|
||||
|
||||
// ProcessInfo 单个进程信息
|
||||
type ProcessInfo struct {
|
||||
PID int `json:"pid"` // 进程 ID
|
||||
Name string `json:"name"` // 进程名
|
||||
CPUPercent float64 `json:"cpu_percent"` // CPU 使用率 (%)
|
||||
RSSKB int64 `json:"rss_kb"` // 物理内存 (KB)
|
||||
}
|
||||
Reference in new issue
Block a user