mirror of
https://github.com/fankes/komari-agent.git
synced 2025-10-18 10:39:24 +08:00
feat: 添加内存使用缓存选项并弃用旧标志
This commit is contained in:
@@ -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
|
||||
)
|
||||
|
@@ -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
|
||||
}
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user