Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add helptext, default logic to ipfs stats #2681

Merged
merged 1 commit into from
May 16, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 47 additions & 14 deletions core/commands/stat.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ import (

var StatsCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "Query IPFS statistics.",
ShortDescription: ``,
Tagline: "Query ipfs statistics.",
Synopsis: "ipfs stats <command>",
ShortDescription: `'ipfs stats' is a set of commands to help look at statistics for your ipfs node.`,
LongDescription: `'ipfs stats' is a set of commands to help look at statistics for your ipfs node.`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can probably add some logic that sets the long description to the short description if unset

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(not that you have to change anything here, just saying that might be a nice feature)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened #2691.

},

Subcommands: map[string]*cmds.Command{
Expand All @@ -30,13 +32,48 @@ var StatsCmd = &cmds.Command{
var statBwCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "Print ipfs bandwidth information.",
ShortDescription: ``,
Synopsis: "ipfs stats bw [--peer <peerId> | -p] [--proto <protocol> | -t] [--poll] [--interval <timeInterval> | -i]",
ShortDescription: `'ipfs stats bw' prints bandwidth information for the ipfs daemon.
It displays: TotalIn, TotalOut, RateIn, RateOut.
`,
LongDescription: `'ipfs stats bw' prints bandwidth information for the ipfs daemon.
It displays: TotalIn, TotalOut, RateIn, RateOut.

By default, overall bandwidth and all protocols are shown. To limit bandwidth to
a particular peer, use the 'peer' option along with that peer's multihash id. To
specify a specific protocol, use the 'proto' option. The 'peer' and 'proto'
options cannot be specified simultaneously. The protocols that be queried using
this method are outlined in the specification: https://github.com/ipfs/specs/blob/master/libp2p/7-properties.md#757-protocol-multicodecs

Example protocol options:
- /ipfs/id/1.0.0
- /ipfs/bitswap
- /ipfs/dht

Example:

> ipfs stats bw -t /ipfs/bitswap
Bandwidth
TotalIn: 5.0MB
TotalOut: 0B
RateIn: 343B/s
RateOut: 0B/s
> ipfs stats bw -p QmepgFW7BHEtU4pZJdxaNiv75mKLLRQnPi1KaaXmQN4V1a
Bandwidth
TotalIn: 4.9MB
TotalOut: 12MB
RateIn: 0B/s
RateOut: 0B/s
`,
},
Options: []cmds.Option{
cmds.StringOption("peer", "p", "Specify a peer to print bandwidth for."),
cmds.StringOption("proto", "t", "Specify a protocol to print bandwidth for."),
cmds.BoolOption("poll", "Print bandwidth at an interval. Default: false."),
cmds.StringOption("interval", "i", "Time interval to wait between updating output, if 'poll' is true."),
cmds.BoolOption("poll", "Print bandwidth at an interval.").Default(false),
cmds.StringOption("interval", "i", `Time interval to wait between updating output, if 'poll' is true.

This accepts durations such as "300s", "1.5h" or "2h45m". Valid time units are:
"ns", "us" (or "µs"), "ms", "s", "m", "h".`).Default("1s"),
},

Run: func(req cmds.Request, res cmds.Response) {
Expand Down Expand Up @@ -78,19 +115,15 @@ var statBwCmd = &cmds.Command{
pid = checkpid
}

interval := time.Second
timeS, found, err := req.Option("interval").String()
timeS, _, err := req.Option("interval").String()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this change isnt right. The existing logic says to halt execution after the first print if we arent in polling mode.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is what will happen over here.

If doPoll is false it will go straight to the `return statement in line 160.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but the change is that now if doPoll is true, it still exits. It just waits, and then exits

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted.

if found {
v, err := time.ParseDuration(timeS)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
interval = v
interval, err := time.ParseDuration(timeS)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}

doPoll, _, err := req.Option("poll").Bool()
Expand Down