mirror of
https://github.com/fankes/komari-agent.git
synced 2025-10-18 18:49:23 +08:00
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.
This commit is contained in:
33
monitoring/unit/process_linux.go
Normal file
33
monitoring/unit/process_linux.go
Normal file
@@ -0,0 +1,33 @@
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package monitoring
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// ProcessCount returns the number of running processes
|
||||
func ProcessCount() (count int) {
|
||||
return processCountLinux()
|
||||
}
|
||||
|
||||
// processCountLinux counts processes by reading /proc directory
|
||||
func processCountLinux() (count int) {
|
||||
procDir := "/proc"
|
||||
|
||||
entries, err := os.ReadDir(procDir)
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
for _, entry := range entries {
|
||||
if _, err := strconv.ParseInt(entry.Name(), 10, 64); err == nil {
|
||||
//if _, err := filepath.ParseInt(entry.Name(), 10, 64); err == nil {
|
||||
count++
|
||||
}
|
||||
}
|
||||
|
||||
return count
|
||||
}
|
Reference in New Issue
Block a user