feat: Agent采集uptime, 后端持久化kernel/uptime/diskIO, 前端磁盘BPS+IOPS展示

- Agent: system.go 添加 readUptime(), SystemStat 携带 Uptime
- Backend: Server 模型新增 Kernel 字段, ReceiveReport 持久化 kernel+uptime
- Backend: /agent/latest 返回 kernel/uptime/port_info/disk_io_info/disk_total
- Frontend: 磁盘监控改为 BPS+IOPS (4张卡片), 系统信息修复内核/运行时长/监听端口/磁盘容量
- 图表单位从 MB/s 改为 KB/s, 添加 formatBPS 工具函数
This commit is contained in:
attacker committed 2026-06-19 01:10:00 +00:00
1 parent 31c2e338a3
commit 5949ec5d0c
48 files changed
+2182 -956

No files matched your search

+32 -2
View File
@@ -12,8 +12,9 @@ import (
// SystemInfo 包含系统静态信息(Agent 版本通过编译时注入,非运行时采集)
type SystemInfo struct {
OSVersion string // OS 发行版版本 (如 "Ubuntu 22.04.4 LTS")
Kernel string // 内核版本 (如 "Linux 6.8.0-90-generic")
OSVersion string // OS 发行版版本 (如 "Ubuntu 22.04.4 LTS")
Kernel string // 内核版本 (如 "6.8.0-90-generic")
UptimeSeconds int64 // 系统运行时长(秒)
}
// CollectSystem 采集系统静态信息。
@@ -28,6 +29,9 @@ func CollectSystem() SystemInfo {
// 读取 /proc/version 获取内核版本
info.Kernel = readProcVersion()
// 读取 /proc/uptime 获取运行时长
info.UptimeSeconds = readUptime()
return info
}
@@ -67,3 +71,29 @@ func readProcVersion() string {
}
return ""
}
// readUptime 从 /proc/uptime 读取系统运行秒数
func readUptime() int64 {
data, err := os.ReadFile("/proc/uptime")
if err != nil {
return 0
}
// 格式: "12345.67 98765.43"
// 第一个值是系统总运行秒数(含小数)
fields := strings.Fields(strings.TrimSpace(string(data)))
if len(fields) < 1 {
return 0
}
// 截断小数部分,只取整数
parts := strings.SplitN(fields[0], ".", 2)
if len(parts) > 0 {
var sec int64
for _, c := range parts[0] {
if c >= '0' && c <= '9' {
sec = sec*10 + int64(c-'0')
}
}
return sec
}
return 0
}
+3 -2
View File
@@ -103,8 +103,9 @@ func main() {
// 前 3 次上报携带系统信息
if sysReportCount < 3 && (sysInfo.OSVersion != "" || sysInfo.Kernel != "") {
report.System = &model.SystemStat{
OSVersion: sysInfo.OSVersion,
Kernel: sysInfo.Kernel,
OSVersion: sysInfo.OSVersion,
Kernel: sysInfo.Kernel,
Uptime: sysInfo.UptimeSeconds,
}
sysReportCount++
}