-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathhost_info.go
65 lines (59 loc) · 1.23 KB
/
host_info.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package statgo
// #cgo LDFLAGS: -lstatgrab
// #include <statgrab.h>
import "C"
import (
"fmt"
"time"
)
// HostInfos contains informations related to the system
type HostInfos struct {
OSName string
OSRelease string
OSVersion string
Platform string
HostName string
NCPUs int
MaxCPUs int
BitWidth int //32, 64 bits
uptime time.Time
systime time.Time
}
// HostInfos get the host informations
// Go equivalent to sg_host_info
func (s *Stat) HostInfos() *HostInfos {
s.Lock()
stats := C.sg_get_host_info(nil)
s.Unlock()
hi := &HostInfos{
OSName: C.GoString(stats.os_name),
OSRelease: C.GoString(stats.os_release),
OSVersion: C.GoString(stats.os_version),
Platform: C.GoString(stats.platform),
HostName: C.GoString(stats.hostname),
NCPUs: int(stats.ncpus),
MaxCPUs: int(stats.maxcpus),
BitWidth: int(stats.bitwidth),
//TODO: uptime
}
return hi
}
func (h *HostInfos) String() string {
return fmt.Sprintf(
"OSName:\t\t%s\n"+
"OSRelease:\t%s\n"+
"OSVersion:\t%s\n"+
"Platform:\t%s\n"+
"HostName:\t%s\n"+
"NCPUs:\t\t%d\n"+
"MaxCPUs:\t%d\n"+
"BitWidth:\t%d\n",
h.OSName,
h.OSRelease,
h.OSVersion,
h.Platform,
h.HostName,
h.NCPUs,
h.MaxCPUs,
h.BitWidth)
}