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

@@ -18,4 +18,5 @@ var (
MonthRotate int
CFAccessClientID string
CFAccessClientSecret string
MemoryIncludeCache bool
)

View File

@@ -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
}

View File

@@ -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