prysm-pulse/shared/p2p/monitoring.go
Raul Jordan 61026103c6
Validator Attester Rewrite (#1487)
* initial validator attesthead rewrite based on proposer rewrite

* proceed with fetching committees and tree hashing the canonical head at assigned attester slot

* complete filling the properties of attestation data and all associated root hashes

* add when to attest todo

* finish entire attester client logic

* tests with mocks checked in

* tests passing in client

* stubbed out server implementation

* fixed build due to old property

* regen mocks with new mockgen version

* fixed broken tests

* complete bazel build fix

* address some review comments

* deep proto test

* tests passing after checking for empty committee and crosslink root

* address nishant comments
2019-02-06 10:20:38 -06:00

43 lines
759 B
Go

package p2p
import (
"context"
"time"
host "github.com/libp2p/go-libp2p-host"
"github.com/prometheus/client_golang/prometheus"
)
var (
peerCountMetric = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "p2p_peer_count",
Help: "The number of currently connected peers",
})
)
func init() {
prometheus.MustRegister(peerCountMetric)
}
func startPeerWatcher(ctx context.Context, h host.Host) {
go (func() {
for {
select {
case <-ctx.Done():
return
default:
peerCountMetric.Set(float64(peerCount(h)))
// Wait 1 second to update again
time.Sleep(1 * time.Second)
}
}
})()
}
func peerCount(h host.Host) int {
// Return number of peers in peerstore, excluding our own host.
return len(h.Peerstore().Peers()) - 1
}