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-unixfs
Commits
9eccce1f
Commit
9eccce1f
authored
Nov 12, 2014
by
Brian Tiger Chow
Committed by
Juan Batiz-Benet
Nov 14, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(2/diag) match ipfs output
License: MIT Signed-off-by:
Brian Tiger Chow
<
brian@perfmode.com
>
parent
3352aeee
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
25 deletions
+57
-25
core/commands2/diag.go
core/commands2/diag.go
+56
-25
diagnostics/diag.go
diagnostics/diag.go
+1
-0
No files found.
core/commands2/diag.go
View file @
9eccce1f
package
commands
package
commands
import
(
import
(
"
fmt
"
"
bytes
"
"io"
"io"
"text/template"
"time"
"time"
cmds
"github.com/jbenet/go-ipfs/commands"
cmds
"github.com/jbenet/go-ipfs/commands"
diagn
"github.com/jbenet/go-ipfs/
diagnostics
"
util
"github.com/jbenet/go-ipfs/
util
"
)
)
type
DiagnosticConnection
struct
{
type
DiagnosticConnection
struct
{
ID
string
ID
string
Latency
int64
// TODO use milliseconds or microseconds for human readability
NanosecondsLatency
uint64
}
}
type
DiagnosticPeer
struct
{
type
DiagnosticPeer
struct
{
ID
string
ID
string
LifeSpan
floa
t64
UptimeSeconds
uin
t64
BandwidthIn
uint64
Bandwidth
Bytes
In
uint64
BandwidthOut
uint64
Bandwidth
Bytes
Out
uint64
Connections
[]
DiagnosticConnection
Connections
[]
DiagnosticConnection
}
}
type
DiagnosticOutput
struct
{
type
DiagnosticOutput
struct
{
...
@@ -58,33 +60,62 @@ connected peers and latencies between them.
...
@@ -58,33 +60,62 @@ connected peers and latencies between them.
connections
:=
make
([]
DiagnosticConnection
,
len
(
peer
.
Connections
))
connections
:=
make
([]
DiagnosticConnection
,
len
(
peer
.
Connections
))
for
j
,
conn
:=
range
peer
.
Connections
{
for
j
,
conn
:=
range
peer
.
Connections
{
connections
[
j
]
=
DiagnosticConnection
{
connections
[
j
]
=
DiagnosticConnection
{
ID
:
conn
.
ID
,
ID
:
conn
.
ID
,
Latency
:
conn
.
Latency
.
Nanoseconds
(),
Nanoseconds
Latency
:
uint64
(
conn
.
Latency
.
Nanoseconds
()
)
,
}
}
}
}
output
[
i
]
=
DiagnosticPeer
{
output
[
i
]
=
DiagnosticPeer
{
ID
:
peer
.
ID
,
ID
:
peer
.
ID
,
LifeSpan
:
peer
.
LifeSpan
.
Minute
s
(),
UptimeSeconds
:
uint64
(
peer
.
LifeSpan
.
Second
s
()
)
,
BandwidthIn
:
peer
.
BwIn
,
Bandwidth
Bytes
In
:
peer
.
BwIn
,
BandwidthOut
:
peer
.
BwOut
,
Bandwidth
Bytes
Out
:
peer
.
BwOut
,
Connections
:
connections
,
Connections
:
connections
,
}
}
}
}
return
&
DiagnosticOutput
{
output
},
nil
return
&
DiagnosticOutput
{
output
},
nil
},
},
Type
:
&
DiagnosticOutput
{},
Type
:
&
DiagnosticOutput
{},
Marshallers
:
map
[
cmds
.
EncodingType
]
cmds
.
Marshaller
{
cmds
.
Text
:
func
(
r
cmds
.
Response
)
([]
byte
,
error
)
{
output
,
ok
:=
r
.
Output
()
.
(
*
DiagnosticOutput
)
if
!
ok
{
return
nil
,
util
.
ErrCast
()
}
var
buf
bytes
.
Buffer
err
:=
printDiagnostics
(
&
buf
,
output
)
if
err
!=
nil
{
return
nil
,
err
}
return
buf
.
Bytes
(),
nil
},
},
}
}
func
PrintDiagnostics
(
info
[]
*
diagn
.
DiagInfo
,
out
io
.
Writer
)
{
func
printDiagnostics
(
out
io
.
Writer
,
info
*
DiagnosticOutput
)
error
{
for
_
,
i
:=
range
info
{
fmt
.
Fprintf
(
out
,
"Peer: %s
\n
"
,
i
.
ID
)
diagTmpl
:=
`
fmt
.
Fprintf
(
out
,
"
\t
Up for: %s
\n
"
,
i
.
LifeSpan
.
String
())
{{ range $peer := .Peers }}
fmt
.
Fprintf
(
out
,
"
\t
Connected To:
\n
"
)
ID {{ $peer.ID }}
for
_
,
c
:=
range
i
.
Connections
{
up {{ $peer.UptimeSeconds }} seconds
fmt
.
Fprintf
(
out
,
"
\t
%s
\n\t\t
Latency = %s
\n
"
,
c
.
ID
,
c
.
Latency
.
String
())
connected to {{ len .Connections }}...
}
{{ range $connection := .Connections }}
fmt
.
Fprintln
(
out
)
ID {{ $connection.ID }}
latency: {{ $connection.NanosecondsLatency }} ns
{{ end }}
{{end}}
`
templ
,
err
:=
template
.
New
(
"DiagnosticOutput"
)
.
Parse
(
diagTmpl
)
if
err
!=
nil
{
return
err
}
err
=
templ
.
Execute
(
out
,
info
)
if
err
!=
nil
{
return
err
}
}
return
nil
}
}
diagnostics/diag.go
View file @
9eccce1f
...
@@ -67,6 +67,7 @@ type DiagInfo struct {
...
@@ -67,6 +67,7 @@ type DiagInfo struct {
Keys
[]
string
Keys
[]
string
// How long this node has been running for
// How long this node has been running for
// TODO rename Uptime
LifeSpan
time
.
Duration
LifeSpan
time
.
Duration
// Incoming Bandwidth Usage
// Incoming Bandwidth Usage
...
...
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