Skip to content

Commit 6245903

Browse files
committed
Add helptext, default logic to ipfs stats
I've added: Synopsis, shortDescription, and longDescription for stats and stats bw. I also added default(false) for poll and default("1s") for interval, and modified the logic to make it fit. Part of #2484 and #2647. License: MIT Signed-off-by: Richard Littauer <richard.littauer@gmail.com>
1 parent a2bcec4 commit 6245903

File tree

7 files changed

+57
-21
lines changed

7 files changed

+57
-21
lines changed

bin/gx

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
gx-v0.7.0

bin/gx-go

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
gx-go-v1.2.0

bin/gx-go-v1.2.0

9.86 MB
Binary file not shown.

bin/gx-v0.7.0

10.4 MB
Binary file not shown.

bin/tmp/gx-go.tar.gz

2.9 MB
Binary file not shown.

bin/tmp/gx.tar.gz

3.04 MB
Binary file not shown.

core/commands/stat.go

+55-21
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ import (
1818

1919
var StatsCmd = &cmds.Command{
2020
Helptext: cmds.HelpText{
21-
Tagline: "Query IPFS statistics.",
22-
ShortDescription: ``,
21+
Tagline: "Query ipfs statistics.",
22+
Synopsis: "ipfs stats <command>",
23+
ShortDescription: `'ipfs stats' is a set of commands to help look at statistics for your ipfs node.`,
24+
LongDescription: `'ipfs stats' is a set of commands to help look at statistics for your ipfs node.`,
2325
},
2426

2527
Subcommands: map[string]*cmds.Command{
@@ -30,13 +32,48 @@ var StatsCmd = &cmds.Command{
3032
var statBwCmd = &cmds.Command{
3133
Helptext: cmds.HelpText{
3234
Tagline: "Print ipfs bandwidth information.",
33-
ShortDescription: ``,
35+
Synopsis: "ipfs stats bw [--peer <peerId> | -p] [--proto <protocol> | -t] [--poll] [--interval <timeInterval> | -i]",
36+
ShortDescription: `'ipfs stats bw' prints bandwidth information for the ipfs daemon.
37+
It displays: TotalIn, TotalOut, RateIn, RateOut.
38+
`,
39+
LongDescription: `'ipfs stats bw' prints bandwidth information for the ipfs daemon.
40+
It displays: TotalIn, TotalOut, RateIn, RateOut.
41+
42+
By default, overall bandwidth and all protocols are shown. To limit bandwidth to
43+
a particular peer, use the 'peer' option along with that peer's multihash id. To
44+
specify a specific protocol, use the 'proto' option. The 'peer' and 'proto'
45+
options cannot be specified simultaneously. The protocols that be queried using
46+
this method are outlined in the specification: https://github.com/ipfs/specs/blob/master/libp2p/7-properties.md#757-protocol-multicodecs
47+
48+
Example protocol options:
49+
- /ipfs/id/1.0.0
50+
- /ipfs/bitswap
51+
- /ipfs/dht
52+
53+
Example:
54+
55+
> ipfs stats bw -t /ipfs/bitswap
56+
Bandwidth
57+
TotalIn: 5.0MB
58+
TotalOut: 0B
59+
RateIn: 343B/s
60+
RateOut: 0B/s
61+
> ipfs stats bw -p QmepgFW7BHEtU4pZJdxaNiv75mKLLRQnPi1KaaXmQN4V1a
62+
Bandwidth
63+
TotalIn: 4.9MB
64+
TotalOut: 12MB
65+
RateIn: 0B/s
66+
RateOut: 0B/s
67+
`,
3468
},
3569
Options: []cmds.Option{
3670
cmds.StringOption("peer", "p", "Specify a peer to print bandwidth for."),
3771
cmds.StringOption("proto", "t", "Specify a protocol to print bandwidth for."),
38-
cmds.BoolOption("poll", "Print bandwidth at an interval. Default: false."),
39-
cmds.StringOption("interval", "i", "Time interval to wait between updating output, if 'poll' is true."),
72+
cmds.BoolOption("poll", "Print bandwidth at an interval.").Default(false),
73+
cmds.StringOption("interval", "i", `Time interval to wait between updating output, if 'poll' is true.
74+
75+
This accepts durations such as "300s", "1.5h" or "2h45m". Valid time units are:
76+
"ns", "us" (or "µs"), "ms", "s", "m", "h".`).Default("1s"),
4077
},
4178

4279
Run: func(req cmds.Request, res cmds.Response) {
@@ -78,20 +115,17 @@ var statBwCmd = &cmds.Command{
78115
pid = checkpid
79116
}
80117

81-
interval := time.Second
82-
timeS, found, err := req.Option("interval").String()
118+
timeS, _, err := req.Option("interval").String()
83119
if err != nil {
84120
res.SetError(err, cmds.ErrNormal)
85121
return
86122
}
87-
if found {
88-
v, err := time.ParseDuration(timeS)
89-
if err != nil {
90-
res.SetError(err, cmds.ErrNormal)
91-
return
92-
}
93-
interval = v
123+
v, err := time.ParseDuration(timeS)
124+
if err != nil {
125+
res.SetError(err, cmds.ErrNormal)
126+
return
94127
}
128+
interval := v
95129

96130
doPoll, _, err := req.Option("poll").Bool()
97131
if err != nil {
@@ -116,14 +150,14 @@ var statBwCmd = &cmds.Command{
116150
totals := nd.Reporter.GetBandwidthTotals()
117151
out <- &totals
118152
}
119-
if !doPoll {
120-
return
121-
}
122-
select {
123-
case <-time.After(interval):
124-
case <-req.Context().Done():
125-
return
153+
if doPoll {
154+
select {
155+
case <-time.After(interval):
156+
case <-req.Context().Done():
157+
return
158+
}
126159
}
160+
return
127161
}
128162
}()
129163
},

0 commit comments

Comments
 (0)