mirror of
https://github.com/fankes/komari-agent.git
synced 2025-10-18 18:49:23 +08:00
feat: 添加memory-mode-available,使用available内存
This commit is contained in:
@@ -1,12 +1,13 @@
|
|||||||
package flags
|
package flags
|
||||||
|
|
||||||
var (
|
var (
|
||||||
DisableAutoUpdate bool
|
DisableAutoUpdate bool
|
||||||
DisableWebSsh bool
|
DisableWebSsh bool
|
||||||
Token string
|
MemoryModeAvailable bool
|
||||||
Endpoint string
|
Token string
|
||||||
Interval float64
|
Endpoint string
|
||||||
IgnoreUnsafeCert bool
|
Interval float64
|
||||||
MaxRetries int
|
IgnoreUnsafeCert bool
|
||||||
ReconnectInterval int
|
MaxRetries int
|
||||||
|
ReconnectInterval int
|
||||||
)
|
)
|
||||||
|
@@ -58,8 +58,9 @@ func init() {
|
|||||||
RootCmd.MarkPersistentFlagRequired("token")
|
RootCmd.MarkPersistentFlagRequired("token")
|
||||||
RootCmd.PersistentFlags().StringVarP(&flags.Endpoint, "endpoint", "e", "", "API endpoint")
|
RootCmd.PersistentFlags().StringVarP(&flags.Endpoint, "endpoint", "e", "", "API endpoint")
|
||||||
RootCmd.MarkPersistentFlagRequired("endpoint")
|
RootCmd.MarkPersistentFlagRequired("endpoint")
|
||||||
RootCmd.PersistentFlags().BoolVarP(&flags.DisableAutoUpdate, "disable-auto-update", "d", false, "Disable automatic updates")
|
RootCmd.PersistentFlags().BoolVar(&flags.DisableAutoUpdate, "disable-auto-update", false, "Disable automatic updates")
|
||||||
RootCmd.PersistentFlags().BoolVarP(&flags.DisableWebSsh, "disable-web-ssh", "w", false, "Disable web SSH")
|
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().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")
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
package monitoring
|
package monitoring
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/komari-monitor/komari-agent/cmd/flags"
|
||||||
"github.com/shirou/gopsutil/mem"
|
"github.com/shirou/gopsutil/mem"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -15,10 +16,16 @@ func Ram() RamInfo {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
raminfo.Total = 0
|
raminfo.Total = 0
|
||||||
raminfo.Used = 0
|
raminfo.Used = 0
|
||||||
} else {
|
return raminfo
|
||||||
raminfo.Total = v.Total
|
|
||||||
raminfo.Used = v.Used
|
|
||||||
}
|
}
|
||||||
|
if flags.MemoryModeAvailable {
|
||||||
|
raminfo.Total = v.Total
|
||||||
|
raminfo.Used = v.Total - v.Available
|
||||||
|
return raminfo
|
||||||
|
}
|
||||||
|
raminfo.Total = v.Total
|
||||||
|
raminfo.Used = v.Used
|
||||||
|
|
||||||
return raminfo
|
return raminfo
|
||||||
}
|
}
|
||||||
func Swap() RamInfo {
|
func Swap() RamInfo {
|
||||||
|
Reference in New Issue
Block a user