Commit 99fa135
Changed files (1)
cmd
cmd/get/get_system_info.go
@@ -21,13 +21,20 @@ func convertKBtoGB(kb uint64) float64 {
}
type SystemInfo struct {
- Username string
- Hostname string
- Platform string
+ Username string
+ Hostname string
+ Platform string
+
+ // cpu
CPUModelName string
CPUThreads int
- RAM string
- Disk string
+
+ // memory
+ MemoryUsed float64
+ MemoryTotal float64
+
+ // disk
+ Disk string
}
func getSystemInfo() (SystemInfo, error) {
@@ -74,7 +81,8 @@ func getSystemInfo() (SystemInfo, error) {
Platform: fmt.Sprintf("%s %s", hostStat.Platform, hostStat.PlatformVersion),
CPUModelName: cpuStat[0].ModelName,
CPUThreads: cpuThreads,
- RAM: fmt.Sprintf("%.2f / %.2f GB", convertKBtoGB(vmStat.Used), convertKBtoGB(vmStat.Total)),
+ MemoryUsed: convertKBtoGB(vmStat.Used),
+ MemoryTotal: convertKBtoGB(vmStat.Total),
Disk: fmt.Sprintf("%.2f / %.2f GB", convertKBtoGB(diskStat.Used), convertKBtoGB(diskStat.Total)),
}, err
}
@@ -92,12 +100,13 @@ var getSystemInfoCmd = &cobra.Command{
green := color.New(color.FgHiGreen).SprintFunc()
cpuInfo := fmt.Sprintf("%s (%v)", systemInfo.CPUModelName, systemInfo.CPUThreads)
+ memoryInfo := fmt.Sprintf("%.2f / %.2f GB", systemInfo.MemoryUsed, systemInfo.MemoryTotal)
systemInfoStr := "" +
fmt.Sprintf("%s@%s\n", green(systemInfo.Username), green(systemInfo.Hostname)) +
fmt.Sprintf("%s: %s\n", green("OS"), systemInfo.Platform) +
fmt.Sprintf("%s: %s\n", green("CPU"), cpuInfo) +
- fmt.Sprintf("%s: %s\n", green("Memory"), systemInfo.RAM) +
+ fmt.Sprintf("%s: %s\n", green("Memory"), memoryInfo) +
fmt.Sprintf("%s: %s", green("Disk"), systemInfo.Disk)
fmt.Println(systemInfoStr)