mirror of
https://github.com/fankes/komari-agent.git
synced 2025-10-19 02:59:23 +08:00
feat: 添加对Darwin和FreeBSD的GPU及操作系统名称获取功能
This commit is contained in:
28
monitoring/unit/gpu_darwin.go
Normal file
28
monitoring/unit/gpu_darwin.go
Normal file
@@ -0,0 +1,28 @@
|
||||
//go:build darwin
|
||||
// +build darwin
|
||||
|
||||
package monitoring
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// GpuName returns the name of the GPU on Darwin (macOS)
|
||||
func GpuName() string {
|
||||
cmd := exec.Command("system_profiler", "SPDisplaysDataType")
|
||||
output, err := cmd.Output()
|
||||
if err != nil {
|
||||
return "Unknown"
|
||||
}
|
||||
|
||||
lines := strings.Split(string(output), "\n")
|
||||
for _, line := range lines {
|
||||
line = strings.TrimSpace(line)
|
||||
if strings.HasPrefix(line, "Chipset Model:") {
|
||||
return strings.TrimSpace(strings.TrimPrefix(line, "Chipset Model:"))
|
||||
}
|
||||
}
|
||||
|
||||
return "Unknown"
|
||||
}
|
28
monitoring/unit/gpu_freebsd.go
Normal file
28
monitoring/unit/gpu_freebsd.go
Normal file
@@ -0,0 +1,28 @@
|
||||
//go:build freebsd
|
||||
// +build freebsd
|
||||
|
||||
package monitoring
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// GpuName returns the name of the GPU on FreeBSD
|
||||
func GpuName() string {
|
||||
cmd := exec.Command("pciconf", "-lv")
|
||||
output, err := cmd.Output()
|
||||
if err != nil {
|
||||
return "Unknown"
|
||||
}
|
||||
|
||||
lines := strings.Split(string(output), "\n")
|
||||
for _, line := range lines {
|
||||
line = strings.TrimSpace(line)
|
||||
if strings.Contains(line, "VGA") || strings.Contains(line, "Display") {
|
||||
return line
|
||||
}
|
||||
}
|
||||
|
||||
return "Unknown"
|
||||
}
|
21
monitoring/unit/os_darwin.go
Normal file
21
monitoring/unit/os_darwin.go
Normal file
@@ -0,0 +1,21 @@
|
||||
//go:build darwin
|
||||
// +build darwin
|
||||
|
||||
package monitoring
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// OSName returns the name of the operating system on Darwin (macOS)
|
||||
func OSName() string {
|
||||
cmd := exec.Command("sw_vers", "-productName")
|
||||
output, err := cmd.Output()
|
||||
if err != nil {
|
||||
return "macOS"
|
||||
}
|
||||
|
||||
name := strings.TrimSpace(string(output))
|
||||
return name
|
||||
}
|
21
monitoring/unit/os_freebsd.go
Normal file
21
monitoring/unit/os_freebsd.go
Normal file
@@ -0,0 +1,21 @@
|
||||
//go:build freebsd
|
||||
// +build freebsd
|
||||
|
||||
package monitoring
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// OSName returns the name of the operating system on FreeBSD
|
||||
func OSName() string {
|
||||
cmd := exec.Command("uname", "-sr")
|
||||
output, err := cmd.Output()
|
||||
if err != nil {
|
||||
return "FreeBSD"
|
||||
}
|
||||
|
||||
name := strings.TrimSpace(string(output))
|
||||
return name
|
||||
}
|
27
monitoring/unit/process_darwin.go
Normal file
27
monitoring/unit/process_darwin.go
Normal file
@@ -0,0 +1,27 @@
|
||||
//go:build darwin
|
||||
// +build darwin
|
||||
|
||||
package monitoring
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// ProcessCount returns the number of running processes on Darwin (macOS)
|
||||
func ProcessCount() (count int) {
|
||||
return processCountDarwin()
|
||||
}
|
||||
|
||||
// processCountDarwin counts processes using the `ps` command
|
||||
func processCountDarwin() (count int) {
|
||||
cmd := exec.Command("ps", "-A")
|
||||
output, err := cmd.Output()
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
// Count the number of lines in the output, excluding the header line
|
||||
lines := strings.Split(string(output), "\n")
|
||||
return len(lines) - 1
|
||||
}
|
27
monitoring/unit/process_freebsd.go
Normal file
27
monitoring/unit/process_freebsd.go
Normal file
@@ -0,0 +1,27 @@
|
||||
//go:build freebsd
|
||||
// +build freebsd
|
||||
|
||||
package monitoring
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// ProcessCount returns the number of running processes on FreeBSD
|
||||
func ProcessCount() (count int) {
|
||||
return processCountFreeBSD()
|
||||
}
|
||||
|
||||
// processCountFreeBSD counts processes using the `ps` command
|
||||
func processCountFreeBSD() (count int) {
|
||||
cmd := exec.Command("ps", "-ax")
|
||||
output, err := cmd.Output()
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
// Count the number of lines in the output, excluding the header line
|
||||
lines := strings.Split(string(output), "\n")
|
||||
return len(lines) - 1
|
||||
}
|
Reference in New Issue
Block a user