mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-26 21:27:19 +00:00
61026103c6
* 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
43 lines
759 B
Go
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
|
|
}
|