Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
f28da4f6
G
go-ethereum
项目概览
whqwjb
/
go-ethereum
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
go-ethereum
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f28da4f6
编写于
1月 24, 2019
作者:
J
Jerzy Lasyk
提交者:
Anton Evangelatov
1月 24, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
swarm/metrics: Send the accounting registry to InfluxDB (#18470)
上级
2abeb35d
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
50 addition
and
43 deletion
+50
-43
metrics/registry.go
metrics/registry.go
+3
-2
p2p/protocols/accounting.go
p2p/protocols/accounting.go
+11
-24
p2p/protocols/reporter_test.go
p2p/protocols/reporter_test.go
+17
-11
swarm/metrics/flags.go
swarm/metrics/flags.go
+19
-6
未找到文件。
metrics/registry.go
浏览文件 @
f28da4f6
...
...
@@ -312,8 +312,9 @@ func (r *PrefixedRegistry) UnregisterAll() {
}
var
(
DefaultRegistry
=
NewRegistry
()
EphemeralRegistry
=
NewRegistry
()
DefaultRegistry
=
NewRegistry
()
EphemeralRegistry
=
NewRegistry
()
AccountingRegistry
=
NewRegistry
()
// registry used in swarm
)
// Call the given function for each registered metric.
...
...
p2p/protocols/accounting.go
浏览文件 @
f28da4f6
...
...
@@ -27,23 +27,21 @@ var (
// All metrics are cumulative
// total amount of units credited
mBalanceCredit
metrics
.
Counter
mBalanceCredit
=
metrics
.
NewRegisteredCounterForced
(
"account.balance.credit"
,
metrics
.
AccountingRegistry
)
// total amount of units debited
mBalanceDebit
metrics
.
Counter
mBalanceDebit
=
metrics
.
NewRegisteredCounterForced
(
"account.balance.debit"
,
metrics
.
AccountingRegistry
)
// total amount of bytes credited
mBytesCredit
metrics
.
Counter
mBytesCredit
=
metrics
.
NewRegisteredCounterForced
(
"account.bytes.credit"
,
metrics
.
AccountingRegistry
)
// total amount of bytes debited
mBytesDebit
metrics
.
Counter
mBytesDebit
=
metrics
.
NewRegisteredCounterForced
(
"account.bytes.debit"
,
metrics
.
AccountingRegistry
)
// total amount of credited messages
mMsgCredit
metrics
.
Counter
mMsgCredit
=
metrics
.
NewRegisteredCounterForced
(
"account.msg.credit"
,
metrics
.
AccountingRegistry
)
// total amount of debited messages
mMsgDebit
metrics
.
Counter
mMsgDebit
=
metrics
.
NewRegisteredCounterForced
(
"account.msg.debit"
,
metrics
.
AccountingRegistry
)
// how many times local node had to drop remote peers
mPeerDrops
metrics
.
Counter
mPeerDrops
=
metrics
.
NewRegisteredCounterForced
(
"account.peerdrops"
,
metrics
.
AccountingRegistry
)
// how many times local node overdrafted and dropped
mSelfDrops
metrics
.
Counter
MetricsRegistry
metrics
.
Registry
mSelfDrops
=
metrics
.
NewRegisteredCounterForced
(
"account.selfdrops"
,
metrics
.
AccountingRegistry
)
)
// Prices defines how prices are being passed on to the accounting instance
...
...
@@ -110,24 +108,13 @@ func NewAccounting(balance Balance, po Prices) *Accounting {
return
ah
}
// SetupAccountingMetrics
creat
es a separate registry for p2p accounting metrics;
// SetupAccountingMetrics
us
es a separate registry for p2p accounting metrics;
// this registry should be independent of any other metrics as it persists at different endpoints.
// It also
instantiates the given metrics and
starts the persisting go-routine which
// It also starts the persisting go-routine which
// at the passed interval writes the metrics to a LevelDB
func
SetupAccountingMetrics
(
reportInterval
time
.
Duration
,
path
string
)
*
AccountingMetrics
{
// create an empty registry
MetricsRegistry
=
metrics
.
NewRegistry
()
// instantiate the metrics
mBalanceCredit
=
metrics
.
NewRegisteredCounterForced
(
"account.balance.credit"
,
MetricsRegistry
)
mBalanceDebit
=
metrics
.
NewRegisteredCounterForced
(
"account.balance.debit"
,
MetricsRegistry
)
mBytesCredit
=
metrics
.
NewRegisteredCounterForced
(
"account.bytes.credit"
,
MetricsRegistry
)
mBytesDebit
=
metrics
.
NewRegisteredCounterForced
(
"account.bytes.debit"
,
MetricsRegistry
)
mMsgCredit
=
metrics
.
NewRegisteredCounterForced
(
"account.msg.credit"
,
MetricsRegistry
)
mMsgDebit
=
metrics
.
NewRegisteredCounterForced
(
"account.msg.debit"
,
MetricsRegistry
)
mPeerDrops
=
metrics
.
NewRegisteredCounterForced
(
"account.peerdrops"
,
MetricsRegistry
)
mSelfDrops
=
metrics
.
NewRegisteredCounterForced
(
"account.selfdrops"
,
MetricsRegistry
)
// create the DB and start persisting
return
NewAccountingMetrics
(
Metrics
Registry
,
reportInterval
,
path
)
return
NewAccountingMetrics
(
metrics
.
Accounting
Registry
,
reportInterval
,
path
)
}
// Send takes a peer, a size and a msg and
...
...
p2p/protocols/reporter_test.go
浏览文件 @
f28da4f6
...
...
@@ -43,21 +43,27 @@ func TestReporter(t *testing.T) {
metrics
:=
SetupAccountingMetrics
(
reportInterval
,
filepath
.
Join
(
dir
,
"test.db"
))
log
.
Debug
(
"Done."
)
//
do som
e metrics
//
chang
e metrics
mBalanceCredit
.
Inc
(
12
)
mBytesCredit
.
Inc
(
34
)
mMsgDebit
.
Inc
(
9
)
//store expected metrics
expectedBalanceCredit
:=
mBalanceCredit
.
Count
()
expectedBytesCredit
:=
mBytesCredit
.
Count
()
expectedMsgDebit
:=
mMsgDebit
.
Count
()
//give the reporter time to write the metrics to DB
time
.
Sleep
(
20
*
time
.
Millisecond
)
//set the metrics to nil - this effectively simulates the node having shut down...
mBalanceCredit
=
nil
mBytesCredit
=
nil
mMsgDebit
=
nil
//close the DB also, or we can't create a new one
metrics
.
Close
()
//clear the metrics - this effectively simulates the node having shut down...
mBalanceCredit
.
Clear
()
mBytesCredit
.
Clear
()
mMsgDebit
.
Clear
()
//setup the metrics again
log
.
Debug
(
"Setting up metrics second time"
)
metrics
=
SetupAccountingMetrics
(
reportInterval
,
filepath
.
Join
(
dir
,
"test.db"
))
...
...
@@ -65,13 +71,13 @@ func TestReporter(t *testing.T) {
log
.
Debug
(
"Done."
)
//now check the metrics, they should have the same value as before "shutdown"
if
mBalanceCredit
.
Count
()
!=
12
{
t
.
Fatalf
(
"Expected counter to be %d, but is %d"
,
12
,
mBalanceCredit
.
Count
())
if
mBalanceCredit
.
Count
()
!=
expectedBalanceCredit
{
t
.
Fatalf
(
"Expected counter to be %d, but is %d"
,
expectedBalanceCredit
,
mBalanceCredit
.
Count
())
}
if
mBytesCredit
.
Count
()
!=
34
{
t
.
Fatalf
(
"Expected counter to be %d, but is %d"
,
23
,
mBytesCredit
.
Count
())
if
mBytesCredit
.
Count
()
!=
expectedBytesCredit
{
t
.
Fatalf
(
"Expected counter to be %d, but is %d"
,
expectedBytesCredit
,
mBytesCredit
.
Count
())
}
if
mMsgDebit
.
Count
()
!=
9
{
t
.
Fatalf
(
"Expected counter to be %d, but is %d"
,
9
,
mMsgDebit
.
Count
())
if
mMsgDebit
.
Count
()
!=
expectedMsgDebit
{
t
.
Fatalf
(
"Expected counter to be %d, but is %d"
,
expectedMsgDebit
,
mMsgDebit
.
Count
())
}
}
swarm/metrics/flags.go
浏览文件 @
f28da4f6
...
...
@@ -31,6 +31,10 @@ var (
Name
:
"metrics.influxdb.export"
,
Usage
:
"Enable metrics export/push to an external InfluxDB database"
,
}
MetricsEnableInfluxDBAccountingExportFlag
=
cli
.
BoolFlag
{
Name
:
"metrics.influxdb.accounting"
,
Usage
:
"Enable accounting metrics export/push to an external InfluxDB database"
,
}
MetricsInfluxDBEndpointFlag
=
cli
.
StringFlag
{
Name
:
"metrics.influxdb.endpoint"
,
Usage
:
"Metrics InfluxDB endpoint"
,
...
...
@@ -66,6 +70,7 @@ var (
var
Flags
=
[]
cli
.
Flag
{
utils
.
MetricsEnabledFlag
,
MetricsEnableInfluxDBExportFlag
,
MetricsEnableInfluxDBAccountingExportFlag
,
MetricsInfluxDBEndpointFlag
,
MetricsInfluxDBDatabaseFlag
,
MetricsInfluxDBUsernameFlag
,
...
...
@@ -77,12 +82,13 @@ func Setup(ctx *cli.Context) {
if
gethmetrics
.
Enabled
{
log
.
Info
(
"Enabling swarm metrics collection"
)
var
(
enableExport
=
ctx
.
GlobalBool
(
MetricsEnableInfluxDBExportFlag
.
Name
)
endpoint
=
ctx
.
GlobalString
(
MetricsInfluxDBEndpointFlag
.
Name
)
database
=
ctx
.
GlobalString
(
MetricsInfluxDBDatabaseFlag
.
Name
)
username
=
ctx
.
GlobalString
(
MetricsInfluxDBUsernameFlag
.
Name
)
password
=
ctx
.
GlobalString
(
MetricsInfluxDBPasswordFlag
.
Name
)
hosttag
=
ctx
.
GlobalString
(
MetricsInfluxDBHostTagFlag
.
Name
)
enableExport
=
ctx
.
GlobalBool
(
MetricsEnableInfluxDBExportFlag
.
Name
)
enableAccountingExport
=
ctx
.
GlobalBool
(
MetricsEnableInfluxDBAccountingExportFlag
.
Name
)
endpoint
=
ctx
.
GlobalString
(
MetricsInfluxDBEndpointFlag
.
Name
)
database
=
ctx
.
GlobalString
(
MetricsInfluxDBDatabaseFlag
.
Name
)
username
=
ctx
.
GlobalString
(
MetricsInfluxDBUsernameFlag
.
Name
)
password
=
ctx
.
GlobalString
(
MetricsInfluxDBPasswordFlag
.
Name
)
hosttag
=
ctx
.
GlobalString
(
MetricsInfluxDBHostTagFlag
.
Name
)
)
// Start system runtime metrics collection
...
...
@@ -94,5 +100,12 @@ func Setup(ctx *cli.Context) {
"host"
:
hosttag
,
})
}
if
enableAccountingExport
{
log
.
Info
(
"Exporting accounting metrics to InfluxDB"
)
go
influxdb
.
InfluxDBWithTags
(
gethmetrics
.
AccountingRegistry
,
10
*
time
.
Second
,
endpoint
,
database
,
username
,
password
,
"accounting."
,
map
[
string
]
string
{
"host"
:
hosttag
,
})
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录