mirror of https://github.com/status-im/go-waku.git
feat: metrics dashboard (#980)
This commit is contained in:
parent
bad57fcb0c
commit
71aec6d37b
|
@ -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
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue