|
1 | 1 | package server
|
2 | 2 |
|
3 | 3 | import (
|
4 |
| - "github.com/shirou/gopsutil/v3/cpu" |
5 |
| - "github.com/shirou/gopsutil/v3/disk" |
6 |
| - "github.com/shirou/gopsutil/v3/host" |
7 |
| - "github.com/shirou/gopsutil/v3/mem" |
| 4 | + "github.com/shirou/gopsutil/v3/cpu" |
| 5 | + "github.com/shirou/gopsutil/v3/disk" |
| 6 | + "github.com/shirou/gopsutil/v3/host" |
| 7 | + "github.com/shirou/gopsutil/v3/mem" |
8 | 8 | )
|
9 | 9 |
|
10 | 10 | // SysInfo saves the basic system information
|
11 | 11 | type SysInfo struct {
|
12 |
| - Hostname string `bson:hostname` |
13 |
| - Platform string `bson:platform` |
14 |
| - CPU string `bson:cpu` |
15 |
| - RAM uint64 `bson:ram` |
16 |
| - Disk uint64 `bson:disk` |
17 |
| - GPU *Query `xml: GpuInfo` |
| 12 | + Hostname string `bson:hostname` |
| 13 | + Platform string `bson:platform` |
| 14 | + CPU string `bson:cpu` |
| 15 | + RAM uint64 `bson:ram` |
| 16 | + Disk uint64 `bson:disk` |
| 17 | + GPU *Query `xml: GpuInfo` |
18 | 18 | }
|
19 | 19 |
|
20 |
| -func ServerInfo() interface{} { |
21 |
| - hostStat, _ := host.Info() |
22 |
| - cpuStat, _ := cpu.Info() |
23 |
| - vmStat, _ := mem.VirtualMemory() |
| 20 | +func ServerInfo() *SysInfo { |
| 21 | + hostStat, _ := host.Info() |
| 22 | + cpuStat, _ := cpu.Info() |
| 23 | + vmStat, _ := mem.VirtualMemory() |
24 | 24 |
|
25 |
| - info := new(SysInfo) |
| 25 | + info := new(SysInfo) |
26 | 26 |
|
27 |
| - filesystem := "/" |
| 27 | + filesystem := "/" |
28 | 28 |
|
29 |
| - // If the server is running windows |
30 |
| - if info.Hostname == "windows" { |
31 |
| - filesystem = "\\" |
32 |
| - } |
| 29 | + // If the server is running windows |
| 30 | + if info.Hostname == "windows" { |
| 31 | + filesystem = "\\" |
| 32 | + } |
33 | 33 |
|
34 |
| - diskStat, _ := disk.Usage(filesystem) // If you're in Unix change this "\\" for "/" |
| 34 | + diskStat, _ := disk.Usage(filesystem) // If you're in Unix change this "\\" for "/" |
35 | 35 |
|
36 |
| - info.Hostname = hostStat.Hostname |
37 |
| - info.Platform = hostStat.Platform |
38 |
| - info.CPU = cpuStat[0].ModelName |
39 |
| - info.RAM = vmStat.Total / 1024 / 1024 |
40 |
| - info.Disk = diskStat.Total / 1024 / 1024 |
| 36 | + info.Hostname = hostStat.Hostname |
| 37 | + info.Platform = hostStat.Platform |
| 38 | + info.CPU = cpuStat[0].ModelName |
| 39 | + info.RAM = vmStat.Total / 1024 / 1024 |
| 40 | + info.Disk = diskStat.Total / 1024 / 1024 |
41 | 41 |
|
42 |
| - gpu, err := GPUInfo() |
| 42 | + gpu, err := GPUInfo() |
43 | 43 |
|
44 |
| - if err == nil { |
45 |
| - info.GPU = gpu |
46 |
| - } |
| 44 | + if err == nil { |
| 45 | + info.GPU = gpu |
| 46 | + } |
47 | 47 |
|
48 |
| - return info |
| 48 | + return info |
49 | 49 |
|
50 | 50 | }
|
0 commit comments