mirror of
https://github.com/fankes/komari-agent.git
synced 2025-10-19 02:59:23 +08:00
refactor: 映射表简化供应商识别
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
package monitoring
|
package monitoring
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"regexp"
|
"regexp"
|
||||||
@@ -41,31 +40,30 @@ func detectByCPUID() string {
|
|||||||
return "none"
|
return "none"
|
||||||
}
|
}
|
||||||
vendor := strings.ToLower(cpuid.CPU.HypervisorVendorString)
|
vendor := strings.ToLower(cpuid.CPU.HypervisorVendorString)
|
||||||
switch {
|
|
||||||
case vendor == "kvm" || strings.Contains(vendor, "kvm"):
|
vendorMap := map[string][]string{
|
||||||
return "kvm"
|
"kvm": {"kvm"},
|
||||||
case vendor == "microsoft" || strings.Contains(vendor, "hyper-v") || strings.Contains(vendor, "msvm") || strings.Contains(vendor, "mshyperv"):
|
"microsoft": {"microsoft", "hyper-v", "msvm", "mshyperv"},
|
||||||
return "microsoft" // systemd uses "microsoft" for Hyper-V/WSL
|
"vmware": {"vmware"},
|
||||||
case strings.Contains(vendor, "vmware"):
|
"xen": {"xen"},
|
||||||
return "vmware"
|
"bhyve": {"bhyve"},
|
||||||
case strings.Contains(vendor, "xen"):
|
"qemu": {"qemu"},
|
||||||
return "xen"
|
"parallels": {"parallels"},
|
||||||
case strings.Contains(vendor, "bhyve"):
|
"oracle": {"oracle", "virtualbox", "vbox"},
|
||||||
return "bhyve"
|
"acrn": {"acrn"},
|
||||||
case strings.Contains(vendor, "qemu"):
|
|
||||||
return "qemu"
|
|
||||||
case strings.Contains(vendor, "parallels"):
|
|
||||||
return "parallels"
|
|
||||||
case strings.Contains(vendor, "oracle") || strings.Contains(vendor, "virtualbox") || strings.Contains(vendor, "vbox"):
|
|
||||||
return "oracle" // systemd reports "oracle" for VirtualBox
|
|
||||||
case strings.Contains(vendor, "acrn"):
|
|
||||||
return "acrn"
|
|
||||||
default:
|
|
||||||
if vendor != "" {
|
|
||||||
return fmt.Sprintf("hypervisor:%s", vendor)
|
|
||||||
}
|
|
||||||
return "virtualized"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for name, keys := range vendorMap {
|
||||||
|
for _, key := range keys {
|
||||||
|
if vendor == key || strings.Contains(vendor, key) {
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if vendor != "" {
|
||||||
|
return vendor
|
||||||
|
}
|
||||||
|
return "virtualized"
|
||||||
}
|
}
|
||||||
|
|
||||||
// detectContainer attempts to detect common Linux container environments when systemd isn't available.
|
// detectContainer attempts to detect common Linux container environments when systemd isn't available.
|
||||||
|
Reference in New Issue
Block a user