Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ping time metric #2498

Merged
merged 5 commits into from
Sep 14, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/hive/hive.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,16 @@ func (s *Service) checkAndAddPeers(ctx context.Context, peers pb.Peers) {
ctx, cancel := context.WithTimeout(ctx, pingTimeout)
defer cancel()

start := time.Now()

// check if the underlay is usable by doing a raw ping using libp2p
if _, err = s.streamer.Ping(ctx, multiUnderlay); err != nil {
s.metrics.PingFailureTime.Observe(time.Since(start).Seconds())
s.metrics.UnreachablePeers.Inc()
s.logger.Debugf("hive: peer %s: underlay %s not reachable", hex.EncodeToString(newPeer.Overlay), multiUnderlay)
return
}
s.metrics.PingTime.Observe(time.Since(start).Seconds())

bzzAddress := bzz.Address{
Overlay: swarm.NewAddress(newPeer.Overlay),
Expand Down
15 changes: 15 additions & 0 deletions pkg/hive/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ type metrics struct {
PeersHandler prometheus.Counter
PeersHandlerPeers prometheus.Counter
UnreachablePeers prometheus.Counter

PingTime prometheus.Histogram
PingFailureTime prometheus.Histogram
}

func newMetrics() metrics {
Expand Down Expand Up @@ -59,6 +62,18 @@ func newMetrics() metrics {
Name: "unreachable_peers_count",
Help: "Number of peers that are unreachable.",
}),
PingTime: prometheus.NewHistogram(prometheus.HistogramOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "ping_time",
Help: "The time spent for pings.",
acud marked this conversation as resolved.
Show resolved Hide resolved
}),
PingFailureTime: prometheus.NewHistogram(prometheus.HistogramOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "fail_ping_time",
Help: "The time spent for unsuccessful pings.",
}),
acud marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down