mirror of https://github.com/status-im/nim-eth.git
use nim-metrics
This commit is contained in:
parent
1797b76351
commit
d445412297
|
@ -13,7 +13,8 @@ requires "nim >= 0.19.0",
|
||||||
"chronicles",
|
"chronicles",
|
||||||
"stew",
|
"stew",
|
||||||
"result",
|
"result",
|
||||||
"nat_traversal"
|
"nat_traversal",
|
||||||
|
"https://github.com/status-im/nim-metrics"
|
||||||
|
|
||||||
proc runTest(path: string) =
|
proc runTest(path: string) =
|
||||||
echo "\nRunning: ", path
|
echo "\nRunning: ", path
|
||||||
|
|
|
@ -168,9 +168,6 @@ type
|
||||||
OK
|
OK
|
||||||
Error
|
Error
|
||||||
|
|
||||||
NimbusStats* = object
|
|
||||||
num_peers*: int
|
|
||||||
|
|
||||||
when BlockNumber is int64:
|
when BlockNumber is int64:
|
||||||
## The goal of these templates is to make it easier to switch
|
## The goal of these templates is to make it easier to switch
|
||||||
## the block number type to a different representation
|
## the block number type to a different representation
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
import nimcrypto, hashes, stew/byteutils, eth_types
|
import nimcrypto, hashes, stew/byteutils, eth_types, metrics
|
||||||
|
|
||||||
|
export metrics
|
||||||
|
|
||||||
proc hash*(d: MDigest): Hash {.inline.} = hash(d.data)
|
proc hash*(d: MDigest): Hash {.inline.} = hash(d.data)
|
||||||
|
|
||||||
|
@ -8,5 +10,5 @@ proc parseAddress*(hexString: string): EthAddress =
|
||||||
proc `$`*(a: EthAddress): string =
|
proc `$`*(a: EthAddress): string =
|
||||||
a.toHex()
|
a.toHex()
|
||||||
|
|
||||||
var nimbusStats*: NimbusStats
|
var peerGauge* = newGauge("connected peers", "number of peers in the pool")
|
||||||
|
|
||||||
|
|
|
@ -107,10 +107,11 @@ proc getRandomBootnode(p: PeerPool): Option[Node] =
|
||||||
if p.discovery.bootstrapNodes.len != 0:
|
if p.discovery.bootstrapNodes.len != 0:
|
||||||
result = option(p.discovery.bootstrapNodes.rand())
|
result = option(p.discovery.bootstrapNodes.rand())
|
||||||
|
|
||||||
proc addPeer*(pool: PeerPool, peer: Peer) =
|
proc addPeer*(pool: PeerPool, peer: Peer) {.gcsafe.} =
|
||||||
doAssert(peer.remote notin pool.connectedNodes)
|
doAssert(peer.remote notin pool.connectedNodes)
|
||||||
pool.connectedNodes[peer.remote] = peer
|
pool.connectedNodes[peer.remote] = peer
|
||||||
inc(nimbusStats.num_peers)
|
{.gcsafe.}:
|
||||||
|
peerGauge.inc()
|
||||||
for o in pool.observers.values:
|
for o in pool.observers.values:
|
||||||
if not o.onPeerConnected.isNil:
|
if not o.onPeerConnected.isNil:
|
||||||
if o.protocol.isNil or peer.supports(o.protocol):
|
if o.protocol.isNil or peer.supports(o.protocol):
|
||||||
|
|
|
@ -795,7 +795,8 @@ proc removePeer(network: EthereumNode, peer: Peer) =
|
||||||
# between which side disconnects first.
|
# between which side disconnects first.
|
||||||
if network.peerPool != nil and not peer.remote.isNil and peer.remote in network.peerPool.connectedNodes:
|
if network.peerPool != nil and not peer.remote.isNil and peer.remote in network.peerPool.connectedNodes:
|
||||||
network.peerPool.connectedNodes.del(peer.remote)
|
network.peerPool.connectedNodes.del(peer.remote)
|
||||||
dec(nimbusStats.num_peers)
|
{.gcsafe.}:
|
||||||
|
peerGauge.dec()
|
||||||
|
|
||||||
# Note: we need to do this check as disconnect (and thus removePeer)
|
# Note: we need to do this check as disconnect (and thus removePeer)
|
||||||
# currently can get called before the dispatcher is initialized.
|
# currently can get called before the dispatcher is initialized.
|
||||||
|
|
Loading…
Reference in New Issue