diff --git a/waku/v2/node/connectedness.go b/waku/v2/node/connectedness.go index e1d5321a..7aa50960 100644 --- a/waku/v2/node/connectedness.go +++ b/waku/v2/node/connectedness.go @@ -82,6 +82,7 @@ func (c ConnectionNotifier) Connected(n network.Network, cc network.Conn) { } c.metrics.RecordPeerConnected() + c.metrics.SetPeerStoreSize(c.h.Peerstore().Peers().Len()) } // Disconnected is called when a connection closed @@ -96,6 +97,7 @@ func (c ConnectionNotifier) Disconnected(n network.Network, cc network.Conn) { c.log.Warn("subscriber is too slow") } } + c.metrics.SetPeerStoreSize(c.h.Peerstore().Peers().Len()) } // OpenedStream is called when a stream opened diff --git a/waku/v2/node/metrics.go b/waku/v2/node/metrics.go index cad8c27c..7bcf5122 100644 --- a/waku/v2/node/metrics.go +++ b/waku/v2/node/metrics.go @@ -27,10 +27,17 @@ var connectedPeers = prometheus.NewGauge( Help: "Number of connected peers", }) +var peerStoreSize = prometheus.NewGauge( + prometheus.GaugeOpts{ + Name: "waku_peer_store_size", + Help: "Size of Peer Store", + }) + var collectors = []prometheus.Collector{ gitVersion, peerDials, connectedPeers, + peerStoreSize, } // Metrics exposes the functions required to update prometheus metrics for the waku node @@ -39,6 +46,7 @@ type Metrics interface { RecordDial() RecordPeerConnected() RecordPeerDisconnected() + SetPeerStoreSize(int) } type metricsImpl struct { @@ -72,3 +80,7 @@ func (m *metricsImpl) RecordPeerConnected() { func (m *metricsImpl) RecordPeerDisconnected() { connectedPeers.Dec() } + +func (m *metricsImpl) SetPeerStoreSize(size int) { + peerStoreSize.Set(float64(size)) +} diff --git a/waku/v2/protocol/relay/metrics.go b/waku/v2/protocol/relay/metrics.go index 35cddbc7..b642c497 100644 --- a/waku/v2/protocol/relay/metrics.go +++ b/waku/v2/protocol/relay/metrics.go @@ -22,14 +22,22 @@ var messageSize = prometheus.NewHistogram(prometheus.HistogramOpts{ Buckets: []float64{0.0, 5.0, 15.0, 50.0, 100.0, 300.0, 700.0, 1000.0}, }) +var pubsubTopics = prometheus.NewGauge( + prometheus.GaugeOpts{ + Name: "waku_pubsub_topics", + Help: "Number of PubSub Topics node is subscribed to", + }) + var collectors = []prometheus.Collector{ messages, messageSize, + pubsubTopics, } // Metrics exposes the functions required to update prometheus metrics for relay protocol type Metrics interface { RecordMessage(envelope *waku_proto.Envelope) + SetPubSubTopics(int) } type metricsImpl struct { @@ -56,3 +64,7 @@ func (m *metricsImpl) RecordMessage(envelope *waku_proto.Envelope) { m.log.Debug("waku.relay received", zap.String("pubsubTopic", pubsubTopic), logging.HexBytes("hash", envelope.Hash()), zap.Int64("receivedTime", envelope.Index().ReceiverTime), zap.Int("payloadSizeBytes", payloadSizeInBytes)) }() } + +func (m *metricsImpl) SetPubSubTopics(size int) { + pubsubTopics.Set(float64(size)) +} diff --git a/waku/v2/protocol/relay/waku_relay.go b/waku/v2/protocol/relay/waku_relay.go index f2f35801..4492b3ca 100644 --- a/waku/v2/protocol/relay/waku_relay.go +++ b/waku/v2/protocol/relay/waku_relay.go @@ -243,7 +243,7 @@ func (w *WakuRelay) subscribeToPubsubTopic(topic string) (*pubsubTopicSubscripti } w.log.Info("gossipsub subscription", zap.String("pubsubTopic", subscription.Topic())) - + w.metrics.SetPubSubTopics(len(w.topics)) result = w.topics[topic] } @@ -491,6 +491,7 @@ func (w *WakuRelay) Unsubscribe(ctx context.Context, contentFilter waku_proto.Co if err != nil { return err } + w.metrics.SetPubSubTopics(len(w.topics)) } } return nil