Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2a1eb40

Browse files
committedOct 13, 2015
WIP: system diagnostics command
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
1 parent bc0f0c2 commit 2a1eb40

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed
 

‎core/commands/sysdiag.go

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package commands
2+
3+
import (
4+
"bytes"
5+
"errors"
6+
"fmt"
7+
"io"
8+
"os"
9+
"runtime"
10+
"strings"
11+
12+
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
13+
key "github.com/ipfs/go-ipfs/blocks/key"
14+
cmds "github.com/ipfs/go-ipfs/commands"
15+
"github.com/ipfs/go-ipfs/core"
16+
dag "github.com/ipfs/go-ipfs/merkledag"
17+
path "github.com/ipfs/go-ipfs/path"
18+
u "github.com/ipfs/go-ipfs/util"
19+
20+
psud "github.com/shirou/gopsutil/disk"
21+
)
22+
23+
var sysDiagCmd = &cmds.Command{
24+
Helptext: cmds.HelpText{
25+
Tagline: "prints out system diagnostic information.",
26+
ShortDescription: `
27+
Prints out information about your computer to aid in easier debugging.
28+
`,
29+
},
30+
Run: func(req cmds.Request, res cmds.Response) {
31+
n, err := req.InvocContext().GetNode()
32+
if err != nil {
33+
res.SetError(err, cmds.ErrNormal)
34+
return
35+
}
36+
37+
info := make(map[string]interface{})
38+
err = runtimeInfo(info)
39+
if err != nil {
40+
res.SetError(err, cmds.ErrNormal)
41+
return
42+
}
43+
44+
err = envVarInfo(out)
45+
if err != nil {
46+
res.SetError(err, cmds.ErrNormal)
47+
return
48+
}
49+
50+
err = diskSpaceInfo(out)
51+
if err != nil {
52+
res.SetError(err, cmds.ErrNormal)
53+
return
54+
}
55+
56+
},
57+
}
58+
59+
func runtimeInfo(out map[string]interface{}) error {
60+
rt := make(map[string]interface{})
61+
rt["os"] = runtime.GOOS
62+
rt["arch"] = runtime.GOARCH
63+
rt["compiler"] = runtime.Compiler
64+
rt["version"] = runtime.Version()
65+
rt["numcpu"] = runtime.NumCPU()
66+
rt["gomaxprocs"] = runtime.GOMAXPROCS(0)
67+
rt["numgoroutines"] = runtime.NumGoroutine()
68+
69+
out["runtime"] = rt
70+
return nil
71+
}
72+
73+
func envVarInfo(out map[string]interface{}) error {
74+
ev := make(map[string]interface{})
75+
ev["GOPATH"] = os.Getenv("GOPATH")
76+
ev["IPFS_PATH"] = os.Getenv("IPFS_PATH")
77+
78+
out["environment"] = ev
79+
return nil
80+
}
81+
82+
func diskSpaceInfo(out map[string]interface{}) error {
83+
di := make(map[string]interface{})
84+
dinfo, err := psud.DiskUsage(os.Getenv("IPFS_PATH"))
85+
if err != nil {
86+
return err
87+
}
88+
89+
di["fstype"] = dinfo.Fstype
90+
di["total_space"] = dinfo.Total
91+
di["used_space"] = dinfo.Used
92+
di["free_space"] = dinfo.Free
93+
94+
out["diskinfo"] = di
95+
return nil
96+
}

0 commit comments

Comments
 (0)
Please sign in to comment.