Compare commits

...

5 Commits

Author SHA1 Message Date
Akizon77
ec28397f8b fix: 内存包含共享内存的使用量 2026-02-04 23:36:08 +08:00
Akizon
ed2c7684fa Merge pull request #60 from joy0x1/main
fix: support counting host processes inside containers
2026-01-15 23:25:50 +08:00
Akizon
d77e9c52e9 Merge pull request #67 from xrgzs/feat/fnos
feat: 增加对 fnOS 的检测功能
2026-01-15 23:21:45 +08:00
MadDogOwner
456b71d395 feat: 增加对 fnOS 的检测功能
Signed-off-by: MadDogOwner <xiaoran@xrgzs.top>
2026-01-14 16:38:51 +08:00
joy0x1
a463360836 fix: support counting host processes inside containers
Allow configuring custom `/proc` path to count host processes via volume
mount.
2025-12-27 16:36:00 +09:00
4 changed files with 35 additions and 8 deletions

View File

@@ -26,6 +26,7 @@ type Config struct {
CustomIpv4 string `json:"custom_ipv4" env:"AGENT_CUSTOM_IPV4"` // 自定义 IPv4 地址 CustomIpv4 string `json:"custom_ipv4" env:"AGENT_CUSTOM_IPV4"` // 自定义 IPv4 地址
CustomIpv6 string `json:"custom_ipv6" env:"AGENT_CUSTOM_IPV6"` // 自定义 IPv6 地址 CustomIpv6 string `json:"custom_ipv6" env:"AGENT_CUSTOM_IPV6"` // 自定义 IPv6 地址
GetIpAddrFromNic bool `json:"get_ip_addr_from_nic" env:"AGENT_GET_IP_ADDR_FROM_NIC"` // 从网卡获取IP地址 GetIpAddrFromNic bool `json:"get_ip_addr_from_nic" env:"AGENT_GET_IP_ADDR_FROM_NIC"` // 从网卡获取IP地址
HostProc string `json:"host_proc" env:"HOST_PROC"` // 容器环境下宿主机/proc目录的挂载点用于监控宿主机进程
ConfigFile string `json:"config_file" env:"AGENT_CONFIG_FILE"` // JSON配置文件路径 ConfigFile string `json:"config_file" env:"AGENT_CONFIG_FILE"` // JSON配置文件路径
} }

View File

@@ -104,15 +104,15 @@ func GetMemHtopLike() RamInfo {
} else { } else {
raminfo.Used = info.MemTotal - info.MemFree raminfo.Used = info.MemTotal - info.MemFree
} }
raminfo.Used += info.Shmem
// Adjust for Zswap //if info.Zswap > 0 || info.Zswapped > 0 {
if info.Zswap > 0 || info.Zswapped > 0 { // if raminfo.Used > info.Zswap {
if raminfo.Used > info.Zswap { // raminfo.Used -= info.Zswap
raminfo.Used -= info.Zswap // } else {
} else { // raminfo.Used = 0
raminfo.Used = 0 // }
} //}
}
return raminfo return raminfo
} }
} }

View File

@@ -26,6 +26,11 @@ func OSName() string {
return synologyName return synologyName
} }
// Check if it's a fnOS
if fnOSName := detectFnOS(); fnOSName != "" {
return fnOSName
}
file, err := os.Open("/etc/os-release") file, err := os.Open("/etc/os-release")
if err != nil { if err != nil {
return "Linux" return "Linux"
@@ -47,6 +52,21 @@ func OSName() string {
return "Linux" return "Linux"
} }
func detectFnOS() string {
if info, err := os.Stat("/usr/trim/BUILD_VERSION"); err == nil && !info.IsDir() {
if data, err := os.ReadFile("/usr/trim/BUILD_VERSION"); err == nil {
// format like "1.1.11"
if version := strings.TrimSpace(string(data)); version != "" {
return "fnOS " + version
}
}
}
if info, err := os.Stat("/usr/trim"); err == nil && info.IsDir() {
return "fnOS"
}
return ""
}
func detectSynology() string { func detectSynology() string {
synologyFiles := []string{ synologyFiles := []string{
"/etc/synoinfo.conf", "/etc/synoinfo.conf",

View File

@@ -17,6 +17,12 @@ func ProcessCount() (count int) {
func processCountLinux() (count int) { func processCountLinux() (count int) {
procDir := "/proc" procDir := "/proc"
if flags.HostProc != "" {
if info, err := os.Stat(flags.HostProc); err == nil && info.IsDir() {
procDir = flags.HostProc
}
}
entries, err := os.ReadDir(procDir) entries, err := os.ReadDir(procDir)
if err != nil { if err != nil {
return 0 return 0