diff options
author | Wei-Ning Huang <w@dexon.org> | 2019-01-18 22:22:07 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-18 22:22:07 +0800 |
commit | 9eedd53cfdc2a29dac3cacc92244bd00c5d4afe1 (patch) | |
tree | 7f92ffdfd3f238a9afc584a7140d12de35b955b5 /p2p | |
parent | ae63267dddb5fccf94cc63e2b90466adc505d1fa (diff) | |
download | dexon-9eedd53cfdc2a29dac3cacc92244bd00c5d4afe1.tar.gz dexon-9eedd53cfdc2a29dac3cacc92244bd00c5d4afe1.tar.zst dexon-9eedd53cfdc2a29dac3cacc92244bd00c5d4afe1.zip |
p2p: report latency and relative latency to datadog (#162)
Diffstat (limited to 'p2p')
-rw-r--r-- | p2p/metrics.go | 5 | ||||
-rw-r--r-- | p2p/peer.go | 12 |
2 files changed, 14 insertions, 3 deletions
diff --git a/p2p/metrics.go b/p2p/metrics.go index 8bd902286..4ed164431 100644 --- a/p2p/metrics.go +++ b/p2p/metrics.go @@ -37,6 +37,8 @@ const ( MetricsInboundTraffic = "p2p/InboundTraffic" // Name for the registered inbound traffic meter MetricsOutboundConnects = "p2p/OutboundConnects" // Name for the registered outbound connects meter MetricsOutboundTraffic = "p2p/OutboundTraffic" // Name for the registered outbound traffic meter + MetricsLatency = "p2p/Latency" // Name for the registered Latency gauge + MetricsRelativeLatency = "p2p/RelativeLatency" // Name for the registered Relative Latency gauge MeteredPeerLimit = 1024 // This amount of peers are individually metered ) @@ -52,6 +54,9 @@ var ( meteredPeerFeed event.Feed // Event feed for peer metrics meteredPeerCount int32 // Actually stored peer connection count + + peerLatency = metrics.NewRegisteredGauge(MetricsLatency, nil) // Gauge latency + peerRelativeLatency = metrics.NewRegisteredGauge(MetricsRelativeLatency, nil) // Gauge Relative latency ) // MeteredPeerEventType is the type of peer events emitted by a metered connection. diff --git a/p2p/peer.go b/p2p/peer.go index 3d6ce9dcd..9183082a1 100644 --- a/p2p/peer.go +++ b/p2p/peer.go @@ -260,7 +260,7 @@ func (p *Peer) pingLoop() { for { select { case <-ping.C: - if err := SendItems(p.rw, pingMsg); err != nil { + if err := SendItems(p.rw, pingMsg, uint64(time.Now().UnixNano())); err != nil { p.protoErr <- err return } @@ -290,8 +290,14 @@ func (p *Peer) readLoop(errc chan<- error) { func (p *Peer) handle(msg Msg) error { switch { case msg.Code == pingMsg: - msg.Discard() - go SendItems(p.rw, pongMsg) + var pingTime [1]uint64 + rlp.Decode(msg.Payload, &pingTime) + peerRelativeLatency.Update((time.Now().UnixNano() - int64(pingTime[0])) / 1000) + go SendItems(p.rw, pongMsg, pingTime[0]) + case msg.Code == pongMsg: + var pingTime [1]uint64 + rlp.Decode(msg.Payload, &pingTime) + peerLatency.Update((time.Now().UnixNano() - int64(pingTime[0])) / 2 / 1000) case msg.Code == discMsg: var reason [1]DiscReason // This is the last message. We don't need to discard or |