-
Notifications
You must be signed in to change notification settings - Fork 0
/
sysdiag.go
135 lines (112 loc) · 2.73 KB
/
sysdiag.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package commands
import (
"os"
"path"
"runtime"
cmds "github.com/ipfs/go-ipfs/commands"
config "github.com/ipfs/go-ipfs/repo/config"
manet "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr-net"
sysi "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/whyrusleeping/go-sysinfo"
)
var sysDiagCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "Prints out system diagnostic information.",
ShortDescription: `
Prints out information about your computer to aid in easier debugging.
`,
},
Run: func(req cmds.Request, res cmds.Response) {
info := make(map[string]interface{})
err := runtimeInfo(info)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
err = envVarInfo(info)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
err = diskSpaceInfo(info)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
err = memInfo(info)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
err = netInfo(info)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
info["ipfs_version"] = config.CurrentVersionNumber
info["ipfs_commit"] = config.CurrentCommit
res.SetOutput(info)
},
}
func runtimeInfo(out map[string]interface{}) error {
rt := make(map[string]interface{})
rt["os"] = runtime.GOOS
rt["arch"] = runtime.GOARCH
rt["compiler"] = runtime.Compiler
rt["version"] = runtime.Version()
rt["numcpu"] = runtime.NumCPU()
rt["gomaxprocs"] = runtime.GOMAXPROCS(0)
rt["numgoroutines"] = runtime.NumGoroutine()
out["runtime"] = rt
return nil
}
func envVarInfo(out map[string]interface{}) error {
ev := make(map[string]interface{})
ev["GOPATH"] = os.Getenv("GOPATH")
ev["IPFS_PATH"] = os.Getenv("IPFS_PATH")
out["environment"] = ev
return nil
}
func ipfsPath() string {
p := os.Getenv("IPFS_PATH")
if p == "" {
p = path.Join(os.Getenv("HOME"), ".ipfs")
}
return p
}
func diskSpaceInfo(out map[string]interface{}) error {
di := make(map[string]interface{})
dinfo, err := sysi.DiskUsage(ipfsPath())
if err != nil {
return err
}
di["fstype"] = dinfo.FsType
di["total_space"] = dinfo.Total
di["free_space"] = dinfo.Free
out["diskinfo"] = di
return nil
}
func memInfo(out map[string]interface{}) error {
m := make(map[string]interface{})
meminf, err := sysi.MemoryInfo()
if err != nil {
return err
}
m["swap"] = meminf.Swap
m["virt"] = meminf.Used
out["memory"] = m
return nil
}
func netInfo(out map[string]interface{}) error {
n := make(map[string]interface{})
addrs, err := manet.InterfaceMultiaddrs()
if err != nil {
return err
}
var straddrs []string
for _, a := range addrs {
straddrs = append(straddrs, a.String())
}
n["interface_addresses"] = straddrs
out["net"] = n
return nil
}