@@ -18,8 +18,10 @@ import (
18
18
19
19
var StatsCmd = & cmds.Command {
20
20
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.` ,
23
25
},
24
26
25
27
Subcommands : map [string ]* cmds.Command {
@@ -30,13 +32,48 @@ var StatsCmd = &cmds.Command{
30
32
var statBwCmd = & cmds.Command {
31
33
Helptext : cmds.HelpText {
32
34
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
+ ` ,
34
68
},
35
69
Options : []cmds.Option {
36
70
cmds .StringOption ("peer" , "p" , "Specify a peer to print bandwidth for." ),
37
71
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" ),
40
77
},
41
78
42
79
Run : func (req cmds.Request , res cmds.Response ) {
@@ -78,20 +115,17 @@ var statBwCmd = &cmds.Command{
78
115
pid = checkpid
79
116
}
80
117
81
- interval := time .Second
82
- timeS , found , err := req .Option ("interval" ).String ()
118
+ timeS , _ , err := req .Option ("interval" ).String ()
83
119
if err != nil {
84
120
res .SetError (err , cmds .ErrNormal )
85
121
return
86
122
}
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
94
127
}
128
+ interval := v
95
129
96
130
doPoll , _ , err := req .Option ("poll" ).Bool ()
97
131
if err != nil {
@@ -116,14 +150,14 @@ var statBwCmd = &cmds.Command{
116
150
totals := nd .Reporter .GetBandwidthTotals ()
117
151
out <- & totals
118
152
}
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
+ }
126
159
}
160
+ return
127
161
}
128
162
}()
129
163
},
0 commit comments