feat: 添加内存使用缓存选项并弃用旧标志

This commit is contained in:
Akizon77
2025-09-06 04:15:28 +00:00
parent 77cd944d74
commit 2d1f25e1bf
3 changed files with 25 additions and 18 deletions

View File

@@ -2,20 +2,21 @@ package flags
var ( var (
AutoDiscoveryKey string AutoDiscoveryKey string
DisableAutoUpdate bool DisableAutoUpdate bool
DisableWebSsh bool DisableWebSsh bool
MemoryModeAvailable bool MemoryModeAvailable bool
Token string Token string
Endpoint string Endpoint string
Interval float64 Interval float64
IgnoreUnsafeCert bool IgnoreUnsafeCert bool
MaxRetries int MaxRetries int
ReconnectInterval int ReconnectInterval int
InfoReportInterval int InfoReportInterval int
IncludeNics string IncludeNics string
ExcludeNics string ExcludeNics string
IncludeMountpoints string IncludeMountpoints string
MonthRotate int MonthRotate int
CFAccessClientID string CFAccessClientID string
CFAccessClientSecret string CFAccessClientSecret string
MemoryIncludeCache bool
) )

View File

@@ -67,6 +67,11 @@ func Execute() {
os.Args = append(os.Args[:i], os.Args[i+1:]...) os.Args = append(os.Args[:i], os.Args[i+1:]...)
break 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 { 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().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.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.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().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().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") 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().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.CFAccessClientID, "cf-access-client-id", "", "Cloudflare Access Client ID")
RootCmd.PersistentFlags().StringVar(&flags.CFAccessClientSecret, "cf-access-client-secret", "", "Cloudflare Access Client Secret") 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 RootCmd.PersistentFlags().ParseErrorsWhitelist.UnknownFlags = true
} }

View File

@@ -18,9 +18,9 @@ func Ram() RamInfo {
raminfo.Used = 0 raminfo.Used = 0
return raminfo return raminfo
} }
if flags.MemoryModeAvailable { if flags.MemoryIncludeCache {
raminfo.Total = v.Total raminfo.Total = v.Total
raminfo.Used = v.Total - v.Available raminfo.Used = v.Total - v.Free
return raminfo return raminfo
} }
raminfo.Total = v.Total raminfo.Total = v.Total