mirror of
https://github.com/fankes/komari-agent.git
synced 2025-10-19 02:59:23 +08:00
feat: 添加虚拟化检测功能
This commit is contained in:
19
monitoring/unit/virtualization.go
Normal file
19
monitoring/unit/virtualization.go
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package monitoring
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os/exec"
|
||||||
|
"runtime"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Virtualized() string {
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
return "Unknown"
|
||||||
|
}
|
||||||
|
out, err := exec.Command("systemd-detect-virt").Output()
|
||||||
|
if err != nil {
|
||||||
|
return "Unknown"
|
||||||
|
}
|
||||||
|
virt := strings.TrimSpace(string(out))
|
||||||
|
return virt
|
||||||
|
}
|
10
monitoring/unit/virtualization_test.go
Normal file
10
monitoring/unit/virtualization_test.go
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package monitoring
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestVirtualized(t *testing.T) {
|
||||||
|
virt := Virtualized()
|
||||||
|
t.Logf("Virtualization type: %s", virt)
|
||||||
|
}
|
@@ -35,17 +35,18 @@ func uploadBasicInfo() error {
|
|||||||
ipv4, ipv6, _ := monitoring.GetIPAddress()
|
ipv4, ipv6, _ := monitoring.GetIPAddress()
|
||||||
|
|
||||||
data := map[string]interface{}{
|
data := map[string]interface{}{
|
||||||
"cpu_name": cpu.CPUName,
|
"cpu_name": cpu.CPUName,
|
||||||
"cpu_cores": cpu.CPUCores,
|
"cpu_cores": cpu.CPUCores,
|
||||||
"arch": cpu.CPUArchitecture,
|
"arch": cpu.CPUArchitecture,
|
||||||
"os": osname,
|
"os": osname,
|
||||||
"ipv4": ipv4,
|
"ipv4": ipv4,
|
||||||
"ipv6": ipv6,
|
"ipv6": ipv6,
|
||||||
"mem_total": monitoring.Ram().Total,
|
"mem_total": monitoring.Ram().Total,
|
||||||
"swap_total": monitoring.Swap().Total,
|
"swap_total": monitoring.Swap().Total,
|
||||||
"disk_total": monitoring.Disk().Total,
|
"disk_total": monitoring.Disk().Total,
|
||||||
"gpu_name": monitoring.GpuName(),
|
"gpu_name": monitoring.GpuName(),
|
||||||
"version": update.CurrentVersion,
|
"virtualization": monitoring.Virtualized(),
|
||||||
|
"version": update.CurrentVersion,
|
||||||
}
|
}
|
||||||
|
|
||||||
endpoint := strings.TrimSuffix(flags.Endpoint, "/") + "/api/clients/uploadBasicInfo?token=" + flags.Token
|
endpoint := strings.TrimSuffix(flags.Endpoint, "/") + "/api/clients/uploadBasicInfo?token=" + flags.Token
|
||||||
|
Reference in New Issue
Block a user