mirror of
https://github.com/oneclickvirt/basics.git
synced 2025-10-05 16:48:09 +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) {
|
||||
ret.CpuModel = ci[i].ModelName + fmt.Sprintf(" %d %s Core", len(ci), cpuType) + " @ " +
|
||||
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的三缓
|
||||
ret.CpuCache = string(ci[i].CacheSize)
|
||||
}
|
||||
|
@@ -1,13 +1,15 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"github.com/shirou/gopsutil/disk"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/shirou/gopsutil/disk"
|
||||
)
|
||||
|
||||
// getDiskInfo 获取硬盘信息
|
||||
func getDiskInfo() (string, string, string, error) {
|
||||
var diskTotalStr, diskUsageStr, bootPath string
|
||||
tempDiskTotal, tempDiskUsage := getDiskTotalAndUsed()
|
||||
@@ -24,6 +26,7 @@ func getDiskInfo() (string, string, string, error) {
|
||||
} else {
|
||||
diskUsageStr = strconv.FormatFloat(diskUsageGB, 'f', 2, 64) + " GB"
|
||||
}
|
||||
if runtime.GOOS == "windows" {
|
||||
parts, err := disk.Partitions(true)
|
||||
if err != nil {
|
||||
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
|
||||
}
|
||||
|
||||
|
@@ -2,9 +2,10 @@ package system
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/oneclickvirt/basics/system/model"
|
||||
"github.com/oneclickvirt/basics/system/utils"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
var (
|
||||
|
Reference in New Issue
Block a user