Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
9eccce1f
提交
9eccce1f
authored
11月 12, 2014
作者:
Brian Tiger Chow
提交者:
Juan Batiz-Benet
11月 14, 2014
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(2/diag) match ipfs output
License: MIT Signed-off-by:
Brian Tiger Chow
<
brian@perfmode.com
>
上级
3352aeee
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
57 行增加
和
25 行删除
+57
-25
diag.go
core/commands2/diag.go
+56
-25
diag.go
diagnostics/diag.go
+1
-0
没有找到文件。
core/commands2/diag.go
浏览文件 @
9eccce1f
package
commands
import
(
"
fmt
"
"
bytes
"
"io"
"text/template"
"time"
cmds
"github.com/jbenet/go-ipfs/commands"
diagn
"github.com/jbenet/go-ipfs/diagnostics
"
util
"github.com/jbenet/go-ipfs/util
"
)
type
DiagnosticConnection
struct
{
ID
string
Latency
int64
ID
string
// TODO use milliseconds or microseconds for human readability
NanosecondsLatency
uint64
}
type
DiagnosticPeer
struct
{
ID
string
LifeSpan
floa
t64
BandwidthIn
uint64
BandwidthOut
uint64
Connections
[]
DiagnosticConnection
ID
string
UptimeSeconds
uin
t64
Bandwidth
Bytes
In
uint64
Bandwidth
Bytes
Out
uint64
Connections
[]
DiagnosticConnection
}
type
DiagnosticOutput
struct
{
...
...
@@ -58,33 +60,62 @@ connected peers and latencies between them.
connections
:=
make
([]
DiagnosticConnection
,
len
(
peer
.
Connections
))
for
j
,
conn
:=
range
peer
.
Connections
{
connections
[
j
]
=
DiagnosticConnection
{
ID
:
conn
.
ID
,
Latency
:
conn
.
Latency
.
Nanoseconds
(
),
ID
:
conn
.
ID
,
NanosecondsLatency
:
uint64
(
conn
.
Latency
.
Nanoseconds
()
),
}
}
output
[
i
]
=
DiagnosticPeer
{
ID
:
peer
.
ID
,
LifeSpan
:
peer
.
LifeSpan
.
Minutes
(
),
BandwidthIn
:
peer
.
BwIn
,
BandwidthOut
:
peer
.
BwOut
,
Connections
:
connections
,
ID
:
peer
.
ID
,
UptimeSeconds
:
uint64
(
peer
.
LifeSpan
.
Seconds
()
),
Bandwidth
Bytes
In
:
peer
.
BwIn
,
Bandwidth
Bytes
Out
:
peer
.
BwOut
,
Connections
:
connections
,
}
}
return
&
DiagnosticOutput
{
output
},
nil
},
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
)
{
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
)
func
printDiagnostics
(
out
io
.
Writer
,
info
*
DiagnosticOutput
)
error
{
diagTmpl
:=
`
{{ range $peer := .Peers }}
ID {{ $peer.ID }}
up {{ $peer.UptimeSeconds }} seconds
connected to {{ len .Connections }}...
{{ range $connection := .Connections }}
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
浏览文件 @
9eccce1f
...
...
@@ -67,6 +67,7 @@ type DiagInfo struct {
Keys
[]
string
// How long this node has been running for
// TODO rename Uptime
LifeSpan
time
.
Duration
// Incoming Bandwidth Usage
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论