network: add network size estimation metric
This commit is contained in:
parent
ec4983e88e
commit
dc62046019
2 changed files with 22 additions and 0 deletions
|
@ -87,6 +87,7 @@ func (d *DefaultDiscovery) BackFill(addrs ...string) {
|
|||
d.unconnectedAddrs[addr] = connRetries
|
||||
d.pushToPoolOrDrop(addr)
|
||||
}
|
||||
d.updateNetSize()
|
||||
d.lock.Unlock()
|
||||
}
|
||||
|
||||
|
@ -127,6 +128,7 @@ func (d *DefaultDiscovery) RegisterBadAddr(addr string) {
|
|||
delete(d.unconnectedAddrs, addr)
|
||||
delete(d.goodAddrs, addr)
|
||||
}
|
||||
d.updateNetSize()
|
||||
d.lock.Unlock()
|
||||
}
|
||||
|
||||
|
@ -181,6 +183,7 @@ func (d *DefaultDiscovery) RegisterGoodAddr(s string, c capability.Capabilities)
|
|||
func (d *DefaultDiscovery) UnregisterConnectedAddr(s string) {
|
||||
d.lock.Lock()
|
||||
delete(d.connectedAddrs, s)
|
||||
d.updateNetSize()
|
||||
d.lock.Unlock()
|
||||
}
|
||||
|
||||
|
@ -189,9 +192,15 @@ func (d *DefaultDiscovery) RegisterConnectedAddr(addr string) {
|
|||
d.lock.Lock()
|
||||
delete(d.unconnectedAddrs, addr)
|
||||
d.connectedAddrs[addr] = true
|
||||
d.updateNetSize()
|
||||
d.lock.Unlock()
|
||||
}
|
||||
|
||||
// updateNetSize updates network size estimation metric. Must be called under read lock.
|
||||
func (d *DefaultDiscovery) updateNetSize() {
|
||||
updateNetworkSizeMetric(len(d.connectedAddrs) + len(d.unconnectedAddrs))
|
||||
}
|
||||
|
||||
func (d *DefaultDiscovery) tryAddress(addr string) {
|
||||
err := d.transport.Dial(addr, d.dialTimeout)
|
||||
d.lock.Lock()
|
||||
|
|
|
@ -6,6 +6,14 @@ import (
|
|||
|
||||
// Metric used in monitoring service.
|
||||
var (
|
||||
estimatedNetworkSize = prometheus.NewGauge(
|
||||
prometheus.GaugeOpts{
|
||||
Help: "Estimated network size",
|
||||
Name: "network_size",
|
||||
Namespace: "neogo",
|
||||
},
|
||||
)
|
||||
|
||||
peersConnected = prometheus.NewGauge(
|
||||
prometheus.GaugeOpts{
|
||||
Help: "Number of connected peers",
|
||||
|
@ -42,6 +50,7 @@ var (
|
|||
|
||||
func init() {
|
||||
prometheus.MustRegister(
|
||||
estimatedNetworkSize,
|
||||
peersConnected,
|
||||
servAndNodeVersion,
|
||||
poolCount,
|
||||
|
@ -49,6 +58,10 @@ func init() {
|
|||
)
|
||||
}
|
||||
|
||||
func updateNetworkSizeMetric(sz int) {
|
||||
estimatedNetworkSize.Set(float64(sz))
|
||||
}
|
||||
|
||||
func updateBlockQueueLenMetric(bqLen int) {
|
||||
blockQueueLength.Set(float64(bqLen))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue