mirror of
https://github.com/oneclickvirt/basics.git
synced 2025-10-06 00:57:35 +08:00
update
This commit is contained in:
@@ -47,7 +47,7 @@ func getCpuInfo(ret *model.SystemInfo, cpuType string) (*model.SystemInfo, error
|
|||||||
if len(ret.CpuModel) < len(ci[i].ModelName) {
|
if len(ret.CpuModel) < len(ci[i].ModelName) {
|
||||||
ret.CpuModel = ci[i].ModelName + fmt.Sprintf(" %d %s Core", len(ci), cpuType) + " @ " +
|
ret.CpuModel = ci[i].ModelName + fmt.Sprintf(" %d %s Core", len(ci), cpuType) + " @ " +
|
||||||
strconv.FormatFloat(ci[i].Mhz, 'f', 2, 64) + " MHz"
|
strconv.FormatFloat(ci[i].Mhz, 'f', 2, 64) + " MHz"
|
||||||
ret.CpuCores = fmt.Sprintf("%d vCPU(s)", int(ci[i].Cores))
|
ret.CpuCores = fmt.Sprintf("%d vCPU(s)", runtime.NumCPU())
|
||||||
if ci[i].CacheSize != 0 { // Windows查不到CPU的三缓
|
if ci[i].CacheSize != 0 { // Windows查不到CPU的三缓
|
||||||
ret.CpuCache = string(ci[i].CacheSize)
|
ret.CpuCache = string(ci[i].CacheSize)
|
||||||
}
|
}
|
||||||
|
@@ -1,13 +1,15 @@
|
|||||||
package system
|
package system
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/shirou/gopsutil/disk"
|
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/shirou/gopsutil/disk"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// getDiskInfo 获取硬盘信息
|
||||||
func getDiskInfo() (string, string, string, error) {
|
func getDiskInfo() (string, string, string, error) {
|
||||||
var diskTotalStr, diskUsageStr, bootPath string
|
var diskTotalStr, diskUsageStr, bootPath string
|
||||||
tempDiskTotal, tempDiskUsage := getDiskTotalAndUsed()
|
tempDiskTotal, tempDiskUsage := getDiskTotalAndUsed()
|
||||||
@@ -24,6 +26,7 @@ func getDiskInfo() (string, string, string, error) {
|
|||||||
} else {
|
} else {
|
||||||
diskUsageStr = strconv.FormatFloat(diskUsageGB, 'f', 2, 64) + " GB"
|
diskUsageStr = strconv.FormatFloat(diskUsageGB, 'f', 2, 64) + " GB"
|
||||||
}
|
}
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
parts, err := disk.Partitions(true)
|
parts, err := disk.Partitions(true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
bootPath = ""
|
bootPath = ""
|
||||||
@@ -42,6 +45,28 @@ func getDiskInfo() (string, string, string, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
cmd := exec.Command("df", "-x", "tmpfs", "/")
|
||||||
|
output, err := cmd.Output()
|
||||||
|
if err == nil {
|
||||||
|
awkCmd := exec.Command("awk", "NR>1")
|
||||||
|
awkCmd.Stdin = strings.NewReader(string(output))
|
||||||
|
awkOutput, err := awkCmd.Output()
|
||||||
|
if err == nil {
|
||||||
|
sedCmd := exec.Command("sed", ":a;N;s/\\n//g;ta")
|
||||||
|
sedCmd.Stdin = strings.NewReader(string(awkOutput))
|
||||||
|
sedOutput, err := sedCmd.Output()
|
||||||
|
if err != nil {
|
||||||
|
finalAwkCmd := exec.Command("awk", "{print $1}")
|
||||||
|
finalAwkCmd.Stdin = strings.NewReader(string(sedOutput))
|
||||||
|
finalOutput, err := finalAwkCmd.Output()
|
||||||
|
if err != nil {
|
||||||
|
bootPath = string(finalOutput)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return diskTotalStr, diskUsageStr, bootPath, nil
|
return diskTotalStr, diskUsageStr, bootPath, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -2,9 +2,10 @@ package system
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/oneclickvirt/basics/system/model"
|
"github.com/oneclickvirt/basics/system/model"
|
||||||
"github.com/oneclickvirt/basics/system/utils"
|
"github.com/oneclickvirt/basics/system/utils"
|
||||||
"strconv"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
Reference in New Issue
Block a user