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