Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
61e8ad99
Commit
61e8ad99
authored
Nov 04, 2014
by
Matt Bell
Committed by
Juan Batiz-Benet
Nov 14, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core/commands2: Added 'diag' command
parent
79b88ee0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
80 additions
and
0 deletions
+80
-0
core/commands2/diag.go
core/commands2/diag.go
+79
-0
core/commands2/root.go
core/commands2/root.go
+1
-0
No files found.
core/commands2/diag.go
0 → 100644
View file @
61e8ad99
package
commands
import
(
"errors"
"fmt"
"io"
"time"
cmds
"github.com/jbenet/go-ipfs/commands"
diagn
"github.com/jbenet/go-ipfs/diagnostics"
)
type
DiagnosticConnection
struct
{
ID
string
Latency
int64
}
type
DiagnosticPeer
struct
{
ID
string
LifeSpan
float64
BandwidthIn
uint64
BandwidthOut
uint64
Connections
[]
DiagnosticConnection
}
type
DiagnosticOutput
struct
{
Peers
[]
DiagnosticPeer
}
var
diagCmd
=
&
cmds
.
Command
{
Run
:
func
(
res
cmds
.
Response
,
req
cmds
.
Request
)
{
n
:=
req
.
Context
()
.
Node
if
n
.
Diagnostics
==
nil
{
res
.
SetError
(
errors
.
New
(
"Cannot run diagnostic in offline mode!"
),
cmds
.
ErrNormal
)
return
}
info
,
err
:=
n
.
Diagnostics
.
GetDiagnostic
(
time
.
Second
*
20
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
output
:=
make
([]
DiagnosticPeer
,
len
(
info
))
for
i
,
peer
:=
range
info
{
connections
:=
make
([]
DiagnosticConnection
,
len
(
peer
.
Connections
))
for
j
,
conn
:=
range
peer
.
Connections
{
connections
[
j
]
=
DiagnosticConnection
{
ID
:
conn
.
ID
,
Latency
:
conn
.
Latency
.
Nanoseconds
(),
}
}
output
[
i
]
=
DiagnosticPeer
{
ID
:
peer
.
ID
,
LifeSpan
:
peer
.
LifeSpan
.
Minutes
(),
BandwidthIn
:
peer
.
BwIn
,
BandwidthOut
:
peer
.
BwOut
,
Connections
:
connections
,
}
}
res
.
SetOutput
(
&
DiagnosticOutput
{
output
})
},
Type
:
&
DiagnosticOutput
{},
}
func
PrintDiagnostics
(
info
[]
*
diagn
.
DiagInfo
,
out
io
.
Writer
)
{
for
_
,
i
:=
range
info
{
fmt
.
Fprintf
(
out
,
"Peer: %s
\n
"
,
i
.
ID
)
fmt
.
Fprintf
(
out
,
"
\t
Up for: %s
\n
"
,
i
.
LifeSpan
.
String
())
fmt
.
Fprintf
(
out
,
"
\t
Connected To:
\n
"
)
for
_
,
c
:=
range
i
.
Connections
{
fmt
.
Fprintf
(
out
,
"
\t
%s
\n\t\t
Latency = %s
\n
"
,
c
.
ID
,
c
.
Latency
.
String
())
}
fmt
.
Fprintln
(
out
)
}
}
core/commands2/root.go
View file @
61e8ad99
...
@@ -62,6 +62,7 @@ var rootSubcommands = map[string]*cmds.Command{
...
@@ -62,6 +62,7 @@ var rootSubcommands = map[string]*cmds.Command{
"publish"
:
publishCmd
,
"publish"
:
publishCmd
,
"add"
:
addCmd
,
"add"
:
addCmd
,
"log"
:
logCmd
,
"log"
:
logCmd
,
"diag"
:
diagCmd
,
// test subcommands
// test subcommands
// TODO: remove these when we don't need them anymore
// TODO: remove these when we don't need them anymore
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment