From 2d1f25e1bfabb5175402796c8159e1e42f5712a6 Mon Sep 17 00:00:00 2001 From: Akizon77 Date: Sat, 6 Sep 2025 04:15:28 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=86=85=E5=AD=98?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E7=BC=93=E5=AD=98=E9=80=89=E9=A1=B9=E5=B9=B6?= =?UTF-8?q?=E5=BC=83=E7=94=A8=E6=97=A7=E6=A0=87=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/flags/flag.go | 31 ++++++++++++++++--------------- cmd/root.go | 8 +++++++- monitoring/unit/mem.go | 4 ++-- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/cmd/flags/flag.go b/cmd/flags/flag.go index 0768eb1..a415bbf 100644 --- a/cmd/flags/flag.go +++ b/cmd/flags/flag.go @@ -2,20 +2,21 @@ package flags var ( AutoDiscoveryKey string - DisableAutoUpdate bool - DisableWebSsh bool - MemoryModeAvailable bool - Token string - Endpoint string - Interval float64 - IgnoreUnsafeCert bool - MaxRetries int - ReconnectInterval int - InfoReportInterval int - IncludeNics string - ExcludeNics string - IncludeMountpoints string - MonthRotate int - CFAccessClientID string + DisableAutoUpdate bool + DisableWebSsh bool + MemoryModeAvailable bool + Token string + Endpoint string + Interval float64 + IgnoreUnsafeCert bool + MaxRetries int + ReconnectInterval int + InfoReportInterval int + IncludeNics string + ExcludeNics string + IncludeMountpoints string + MonthRotate int + CFAccessClientID string CFAccessClientSecret string + MemoryIncludeCache bool ) diff --git a/cmd/root.go b/cmd/root.go index 34539c2..f713d70 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -67,6 +67,11 @@ func Execute() { os.Args = append(os.Args[:i], os.Args[i+1:]...) break } + if arg == "-memory-mode-available" || arg == "--memory-mode-available" { + flags.MemoryIncludeCache = true + log.Println("WARNING: The --memory-mode-available flag is deprecated in version 1.0.70 and later. Use --memory-include-cache to report memory usage including cache/buffer.") + os.Args = append(os.Args[:i], os.Args[i+1:]...) + } } if err := RootCmd.Execute(); err != nil { @@ -82,7 +87,7 @@ func init() { RootCmd.PersistentFlags().StringVar(&flags.AutoDiscoveryKey, "auto-discovery", "", "Auto discovery key for the agent") RootCmd.PersistentFlags().BoolVar(&flags.DisableAutoUpdate, "disable-auto-update", false, "Disable automatic updates") RootCmd.PersistentFlags().BoolVar(&flags.DisableWebSsh, "disable-web-ssh", false, "Disable remote control(web ssh and rce)") - RootCmd.PersistentFlags().BoolVar(&flags.MemoryModeAvailable, "memory-mode-available", false, "Report memory as available instead of used.") + //RootCmd.PersistentFlags().BoolVar(&flags.MemoryModeAvailable, "memory-mode-available", false, "[deprecated]Report memory as available instead of used.") RootCmd.PersistentFlags().Float64VarP(&flags.Interval, "interval", "i", 1.0, "Interval in seconds") RootCmd.PersistentFlags().BoolVarP(&flags.IgnoreUnsafeCert, "ignore-unsafe-cert", "u", false, "Ignore unsafe certificate errors") RootCmd.PersistentFlags().IntVarP(&flags.MaxRetries, "max-retries", "r", 3, "Maximum number of retries") @@ -94,5 +99,6 @@ func init() { RootCmd.PersistentFlags().IntVar(&flags.MonthRotate, "month-rotate", 0, "Month reset for network statistics (0 to disable)") RootCmd.PersistentFlags().StringVar(&flags.CFAccessClientID, "cf-access-client-id", "", "Cloudflare Access Client ID") RootCmd.PersistentFlags().StringVar(&flags.CFAccessClientSecret, "cf-access-client-secret", "", "Cloudflare Access Client Secret") + RootCmd.PersistentFlags().BoolVar(&flags.MemoryIncludeCache, "memory-include-cache", false, "Include cache/buffer in memory usage") RootCmd.PersistentFlags().ParseErrorsWhitelist.UnknownFlags = true } diff --git a/monitoring/unit/mem.go b/monitoring/unit/mem.go index 572753a..4926398 100644 --- a/monitoring/unit/mem.go +++ b/monitoring/unit/mem.go @@ -18,9 +18,9 @@ func Ram() RamInfo { raminfo.Used = 0 return raminfo } - if flags.MemoryModeAvailable { + if flags.MemoryIncludeCache { raminfo.Total = v.Total - raminfo.Used = v.Total - v.Available + raminfo.Used = v.Total - v.Free return raminfo } raminfo.Total = v.Total