Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
b4263014
Commit
b4263014
authored
Jun 21, 2015
by
Péter Szilágyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cmd/geth, eth/fetcher: polish metrics reporting, add some more
parent
6994a3da
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
16 deletions
+60
-16
admin.go
cmd/geth/admin.go
+45
-6
fetcher.go
eth/fetcher/fetcher.go
+15
-10
No files found.
cmd/geth/admin.go
View file @
b4263014
...
@@ -6,10 +6,9 @@ import (
...
@@ -6,10 +6,9 @@ import (
"fmt"
"fmt"
"math/big"
"math/big"
"strconv"
"strconv"
"strings"
"time"
"time"
"github.com/rcrowley/go-metrics"
"github.com/ethereum/ethash"
"github.com/ethereum/ethash"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/cmd/utils"
...
@@ -25,6 +24,7 @@ import (
...
@@ -25,6 +24,7 @@ import (
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/xeth"
"github.com/ethereum/go-ethereum/xeth"
"github.com/rcrowley/go-metrics"
"github.com/robertkrimen/otto"
"github.com/robertkrimen/otto"
"gopkg.in/fatih/set.v0"
"gopkg.in/fatih/set.v0"
)
)
...
@@ -723,17 +723,56 @@ func (js *jsre) waitForBlocks(call otto.FunctionCall) otto.Value {
...
@@ -723,17 +723,56 @@ func (js *jsre) waitForBlocks(call otto.FunctionCall) otto.Value {
}
}
func
(
js
*
jsre
)
metrics
(
call
otto
.
FunctionCall
)
otto
.
Value
{
func
(
js
*
jsre
)
metrics
(
call
otto
.
FunctionCall
)
otto
.
Value
{
// Create a rate formatter
units
:=
[]
string
{
""
,
"K"
,
"M"
,
"G"
,
"T"
,
"E"
,
"P"
}
round
:=
func
(
value
float64
,
prec
int
)
string
{
unit
:=
0
for
value
>=
1000
{
unit
,
value
,
prec
=
unit
+
1
,
value
/
1000
,
2
}
return
fmt
.
Sprintf
(
fmt
.
Sprintf
(
"%%.%df%s"
,
prec
,
units
[
unit
]),
value
)
}
format
:=
func
(
total
float64
,
rate
float64
)
string
{
return
fmt
.
Sprintf
(
"%s (%s/s)"
,
round
(
total
,
0
),
round
(
rate
,
2
))
}
// Iterate over all the metrics, and just dump for now
// Iterate over all the metrics, and just dump for now
counters
:=
make
(
map
[
string
]
interface
{})
counters
:=
make
(
map
[
string
]
interface
{})
metrics
.
DefaultRegistry
.
Each
(
func
(
name
string
,
metric
interface
{})
{
metrics
.
DefaultRegistry
.
Each
(
func
(
name
string
,
metric
interface
{})
{
// Create or retrieve the counter hierarchy for this metric
root
,
parts
:=
counters
,
strings
.
Split
(
name
,
"/"
)
for
_
,
part
:=
range
parts
[
:
len
(
parts
)
-
1
]
{
if
_
,
ok
:=
root
[
part
];
!
ok
{
root
[
part
]
=
make
(
map
[
string
]
interface
{})
}
root
=
root
[
part
]
.
(
map
[
string
]
interface
{})
}
name
=
parts
[
len
(
parts
)
-
1
]
// Fill the counter with the metric details
switch
metric
:=
metric
.
(
type
)
{
switch
metric
:=
metric
.
(
type
)
{
case
metrics
.
Meter
:
case
metrics
.
Meter
:
counters
[
name
+
"( 1 min)"
]
=
int
(
metric
.
Rate1
()
*
60
)
root
[
name
]
=
map
[
string
]
interface
{}{
counters
[
name
+
"( 5 min)"
]
=
int
(
metric
.
Rate5
()
*
300
)
"Avg01Min"
:
format
(
metric
.
Rate1
()
*
60
,
metric
.
Rate1
()),
counters
[
name
+
"(15 min)"
]
=
int
(
metric
.
Rate15
()
*
900
)
"Avg05Min"
:
format
(
metric
.
Rate5
()
*
300
,
metric
.
Rate5
()),
"Avg15Min"
:
format
(
metric
.
Rate15
()
*
900
,
metric
.
Rate15
()),
"Overall"
:
format
(
float64
(
metric
.
Count
()),
metric
.
RateMean
()),
}
case
metrics
.
Timer
:
root
[
name
]
=
map
[
string
]
interface
{}{
"Avg01Min"
:
format
(
metric
.
Rate1
()
*
60
,
metric
.
Rate1
()),
"Avg05Min"
:
format
(
metric
.
Rate5
()
*
300
,
metric
.
Rate5
()),
"Avg15Min"
:
format
(
metric
.
Rate15
()
*
900
,
metric
.
Rate15
()),
"Overall"
:
format
(
float64
(
metric
.
Count
()),
metric
.
RateMean
()),
"Perc01"
:
round
(
metric
.
Percentile
(
1
),
2
),
"Perc05"
:
round
(
metric
.
Percentile
(
5
),
2
),
"Perc25"
:
round
(
metric
.
Percentile
(
25
),
2
),
"Perc90"
:
round
(
metric
.
Percentile
(
90
),
2
),
}
default
:
default
:
counters
[
name
]
=
"Unknown metric type"
root
[
name
]
=
"Unknown metric type"
}
}
})
})
// Flatten the counters into some metrics and return
// Flatten the counters into some metrics and return
...
...
eth/fetcher/fetcher.go
View file @
b4263014
...
@@ -7,12 +7,11 @@ import (
...
@@ -7,12 +7,11 @@ import (
"math/rand"
"math/rand"
"time"
"time"
"github.com/rcrowley/go-metrics"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/logger/glog"
"github.com/rcrowley/go-metrics"
"gopkg.in/karalabe/cookiejar.v2/collections/prque"
"gopkg.in/karalabe/cookiejar.v2/collections/prque"
)
)
...
@@ -100,9 +99,11 @@ type Fetcher struct {
...
@@ -100,9 +99,11 @@ type Fetcher struct {
importedHook
func
(
*
types
.
Block
)
// Method to call upon successful block import
importedHook
func
(
*
types
.
Block
)
// Method to call upon successful block import
// Runtime metrics
// Runtime metrics
announceStats
metrics
.
Meter
announceMeter
metrics
.
Meter
// Counter for metering the inbound announcements
broadcastStats
metrics
.
Meter
announceTimer
metrics
.
Timer
// Counter and timer for metering the announce forwarding
discardStats
metrics
.
Meter
broadcastMeter
metrics
.
Meter
// Counter for metering the inbound propagations
broadcastTimer
metrics
.
Timer
// Counter and timer for metering the block forwarding
discardMeter
metrics
.
Meter
// Counter for metering the discarded blocks
}
}
// New creates a block fetcher to retrieve blocks based on hash announcements.
// New creates a block fetcher to retrieve blocks based on hash announcements.
...
@@ -125,9 +126,11 @@ func New(getBlock blockRetrievalFn, validateBlock blockValidatorFn, broadcastBlo
...
@@ -125,9 +126,11 @@ func New(getBlock blockRetrievalFn, validateBlock blockValidatorFn, broadcastBlo
chainHeight
:
chainHeight
,
chainHeight
:
chainHeight
,
insertChain
:
insertChain
,
insertChain
:
insertChain
,
dropPeer
:
dropPeer
,
dropPeer
:
dropPeer
,
announceStats
:
metrics
.
GetOrRegisterMeter
(
"eth/Announced Blocks"
,
metrics
.
DefaultRegistry
),
announceMeter
:
metrics
.
GetOrRegisterMeter
(
"eth/RemoteAnnounces"
,
metrics
.
DefaultRegistry
),
broadcastStats
:
metrics
.
GetOrRegisterMeter
(
"eth/Propagated Blocks"
,
metrics
.
DefaultRegistry
),
announceTimer
:
metrics
.
GetOrRegisterTimer
(
"eth/LocalAnnounces"
,
metrics
.
DefaultRegistry
),
discardStats
:
metrics
.
GetOrRegisterMeter
(
"eth/Discarded Blocks"
,
metrics
.
DefaultRegistry
),
broadcastMeter
:
metrics
.
GetOrRegisterMeter
(
"eth/RemoteBroadcasts"
,
metrics
.
DefaultRegistry
),
broadcastTimer
:
metrics
.
GetOrRegisterTimer
(
"eth/LocalBroadcasts"
,
metrics
.
DefaultRegistry
),
discardMeter
:
metrics
.
GetOrRegisterMeter
(
"eth/DiscardedBlocks"
,
metrics
.
DefaultRegistry
),
}
}
}
}
...
@@ -239,7 +242,7 @@ func (f *Fetcher) loop() {
...
@@ -239,7 +242,7 @@ func (f *Fetcher) loop() {
case
notification
:=
<-
f
.
notify
:
case
notification
:=
<-
f
.
notify
:
// A block was announced, make sure the peer isn't DOSing us
// A block was announced, make sure the peer isn't DOSing us
f
.
announce
Stats
.
Mark
(
1
)
f
.
announce
Meter
.
Mark
(
1
)
count
:=
f
.
announces
[
notification
.
origin
]
+
1
count
:=
f
.
announces
[
notification
.
origin
]
+
1
if
count
>
hashLimit
{
if
count
>
hashLimit
{
...
@@ -258,7 +261,7 @@ func (f *Fetcher) loop() {
...
@@ -258,7 +261,7 @@ func (f *Fetcher) loop() {
case
op
:=
<-
f
.
inject
:
case
op
:=
<-
f
.
inject
:
// A direct block insertion was requested, try and fill any pending gaps
// A direct block insertion was requested, try and fill any pending gaps
f
.
broadcast
Stats
.
Mark
(
1
)
f
.
broadcast
Meter
.
Mark
(
1
)
f
.
enqueue
(
op
.
origin
,
op
.
block
)
f
.
enqueue
(
op
.
origin
,
op
.
block
)
case
hash
:=
<-
f
.
done
:
case
hash
:=
<-
f
.
done
:
...
@@ -418,6 +421,7 @@ func (f *Fetcher) insert(peer string, block *types.Block) {
...
@@ -418,6 +421,7 @@ func (f *Fetcher) insert(peer string, block *types.Block) {
f
.
dropPeer
(
peer
)
f
.
dropPeer
(
peer
)
return
return
}
}
f
.
broadcastTimer
.
UpdateSince
(
block
.
ReceivedAt
)
go
f
.
broadcastBlock
(
block
,
true
)
go
f
.
broadcastBlock
(
block
,
true
)
// Run the actual import and log any issues
// Run the actual import and log any issues
...
@@ -426,6 +430,7 @@ func (f *Fetcher) insert(peer string, block *types.Block) {
...
@@ -426,6 +430,7 @@ func (f *Fetcher) insert(peer string, block *types.Block) {
return
return
}
}
// If import succeeded, broadcast the block
// If import succeeded, broadcast the block
f
.
announceTimer
.
UpdateSince
(
block
.
ReceivedAt
)
go
f
.
broadcastBlock
(
block
,
false
)
go
f
.
broadcastBlock
(
block
,
false
)
// Invoke the testing hook if needed
// Invoke the testing hook if needed
...
...
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