Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
xzyaoi
committed
Dec 9, 2018
1 parent
a1b27e5
commit 9e907a6
Showing
4 changed files
with
67 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/shirou/gopsutil/cpu" | ||
"github.com/shirou/gopsutil/host" | ||
"github.com/shirou/gopsutil/mem" | ||
) | ||
|
||
type SystemInfo struct { | ||
CpuName string `json:"cpu"` | ||
Memory uint64 `json:"memory"` | ||
Platform string `json:"platform"` | ||
Os string `json:"os"` | ||
PlatformVersion string `json:"platformVersion"` | ||
} | ||
|
||
func getSystemInfo() SystemInfo { | ||
var systemInfo SystemInfo | ||
v, _ := mem.VirtualMemory() | ||
systemInfo.Memory = v.Total | ||
platform, _ := host.Info() | ||
systemInfo.Platform = platform.Platform | ||
systemInfo.PlatformVersion = platform.PlatformVersion | ||
systemInfo.Os = platform.OS | ||
|
||
// Handle CPU | ||
cpuInfo, _ := cpu.Info() | ||
systemInfo.CpuName = cpuInfo[0].ModelName | ||
return systemInfo | ||
} |