From bbba67c29129b08fd8fb73e95ce4e04788725a74 Mon Sep 17 00:00:00 2001 From: attacker Date: Wed, 24 Jun 2026 14:05:25 +0000 Subject: [PATCH] =?UTF-8?q?fix(agent):=20flag.Parse()=20=E6=97=B6=E6=9C=BA?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E5=AF=BC=E8=87=B4-server=E6=B0=B8=E8=BF=9C?= =?UTF-8?q?=E4=B8=BA=E7=A9=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- agent/main.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/agent/main.go b/agent/main.go index 416cbed..984f355 100644 --- a/agent/main.go +++ b/agent/main.go @@ -49,15 +49,21 @@ type Config struct { } func main() { - cfg := Config{ - Server: *flag.String("server", "", "AIOps 后端上报地址(output/discover 模式不需要)"), - Token: *flag.String("token", "", "Bearer 鉴权令牌"), - Hostname: *flag.String("hostname", "", "上报主机名,默认使用系统主机名"), - Interval: *flag.Int("interval", 10, "采集与上报间隔,单位:秒"), - TopN: *flag.Int("top-n", 3, "进程 TOP N 数量"), - } + serverFlag := flag.String("server", "", "AIOps 后端上报地址(output/discover 模式不需要)") + tokenFlag := flag.String("token", "", "Bearer 鉴权令牌") + hostnameFlag := flag.String("hostname", "", "上报主机名,默认使用系统主机名") + intervalFlag := flag.Int("interval", 10, "采集与上报间隔,单位:秒") + topNFlag := flag.Int("top-n", 3, "进程 TOP N 数量") flag.Parse() + cfg := Config{ + Server: *serverFlag, + Token: *tokenFlag, + Hostname: *hostnameFlag, + Interval: *intervalFlag, + TopN: *topNFlag, + } + if cfg.Hostname == "" { if h, err := os.Hostname(); err == nil { cfg.Hostname = h