Files
komari-agent/monitoring/unit/mem.go
Akizon77 e34367de69 Refactor monitoring package: remove platform-specific files and consolidate OS detection and process counting logic
- Deleted os_windows.go and process_windows.go, replacing them with platform-agnostic implementations in unit directory.
- Removed Linux-specific process counting logic from process_linux.go and integrated it into unit.
- Consolidated uptime and OS name retrieval into unit files for better organization.
- Updated update mechanism to use global variables for current version and repository.
- Introduced command-line flags for configuration, including disabling auto-update and web SSH.
- Implemented WebSocket connection handling and terminal interaction for both Unix and Windows systems.
- Added basic info upload functionality to server package, enhancing monitoring capabilities.
2025-05-16 19:56:22 +08:00

36 lines
574 B
Go

package monitoring
import (
"github.com/shirou/gopsutil/mem"
)
type RamInfo struct {
Total uint64 `json:"total"`
Used uint64 `json:"used"`
}
func Ram() RamInfo {
raminfo := RamInfo{}
v, err := mem.VirtualMemory()
if err != nil {
raminfo.Total = 0
raminfo.Used = 0
} else {
raminfo.Total = v.Total
raminfo.Used = v.Used
}
return raminfo
}
func Swap() RamInfo {
swapinfo := RamInfo{}
s, err := mem.SwapMemory()
if err != nil {
swapinfo.Total = 0
swapinfo.Used = 0
} else {
swapinfo.Total = s.Total
swapinfo.Used = s.Used
}
return swapinfo
}