fix: 完善Agent系统信息上报
- 持续上报系统元数据并动态更新运行时长 - 兼容旧版心跳补齐资产运行时长 - 修复监控指标当前值重复显示单位
This commit is contained in:
1 parent
0c7c63017c
commit
699560a270
4 files changed
+77
-15
No files matched your search
+6
-10
@@ -116,12 +116,11 @@ func main() {
|
||||
|
||||
sysInfo := collector.CollectSystem()
|
||||
logger.Printf("系统信息: OS=%q Kernel=%q", sysInfo.OSVersion, sysInfo.Kernel)
|
||||
agentStartedAt := time.Now()
|
||||
|
||||
localIP := detectLocalIP()
|
||||
logger.Printf("探测本机 IP: %s", localIP)
|
||||
|
||||
sysReportCount := 0
|
||||
|
||||
taskExecutor := task.New(logger)
|
||||
taskClient := task.NewClient(httpCli, cfg.Hostname, logger)
|
||||
|
||||
@@ -135,20 +134,17 @@ func main() {
|
||||
var probeConfigs []model.ProbeConfig
|
||||
|
||||
collectAndReport := func() {
|
||||
currentUptime := sysInfo.UptimeSeconds + int64(time.Since(agentStartedAt).Seconds())
|
||||
report := &model.Report{
|
||||
Hostname: cfg.Hostname,
|
||||
IP: localIP,
|
||||
Timestamp: time.Now().UTC().Format(time.RFC3339),
|
||||
AgentVersion: version,
|
||||
}
|
||||
|
||||
if sysReportCount < 3 && (sysInfo.OSVersion != "" || sysInfo.Kernel != "") {
|
||||
report.System = &model.SystemStat{
|
||||
System: &model.SystemStat{
|
||||
OSVersion: sysInfo.OSVersion,
|
||||
Kernel: sysInfo.Kernel,
|
||||
Uptime: sysInfo.UptimeSeconds,
|
||||
}
|
||||
sysReportCount++
|
||||
Uptime: currentUptime,
|
||||
},
|
||||
}
|
||||
|
||||
if stat, err := cpuCollector.Collect(); err != nil {
|
||||
@@ -211,7 +207,7 @@ func main() {
|
||||
runtime.ReadMemStats(&memStats)
|
||||
report.Heartbeat = model.AgentHeartbeat{
|
||||
Version: version,
|
||||
UptimeSec: sysInfo.UptimeSeconds,
|
||||
UptimeSec: currentUptime,
|
||||
SelfCPU: 0,
|
||||
SelfRSSMB: float64(memStats.Alloc) / 1024.0 / 1024.0,
|
||||
ReportSeq: reportSeq,
|
||||
|
||||
Reference in new issue
Block a user