use nim-metrics

This commit is contained in:
Ștefan Talpalaru 2019-07-10 02:08:35 +02:00
parent 1797b76351
commit d445412297
No known key found for this signature in database
GPG Key ID: CBF7934204F1B6F9
5 changed files with 11 additions and 9 deletions

View File

@ -13,7 +13,8 @@ requires "nim >= 0.19.0",
"chronicles",
"stew",
"result",
"nat_traversal"
"nat_traversal",
"https://github.com/status-im/nim-metrics"
proc runTest(path: string) =
echo "\nRunning: ", path

View File

@ -168,9 +168,6 @@ type
OK
Error
NimbusStats* = object
num_peers*: int
when BlockNumber is int64:
## The goal of these templates is to make it easier to switch
## the block number type to a different representation

View File

@ -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)
@ -8,5 +10,5 @@ proc parseAddress*(hexString: string): EthAddress =
proc `$`*(a: EthAddress): string =
a.toHex()
var nimbusStats*: NimbusStats
var peerGauge* = newGauge("connected peers", "number of peers in the pool")

View File

@ -107,10 +107,11 @@ proc getRandomBootnode(p: PeerPool): Option[Node] =
if p.discovery.bootstrapNodes.len != 0:
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)
pool.connectedNodes[peer.remote] = peer
inc(nimbusStats.num_peers)
{.gcsafe.}:
peerGauge.inc()
for o in pool.observers.values:
if not o.onPeerConnected.isNil:
if o.protocol.isNil or peer.supports(o.protocol):

View File

@ -795,7 +795,8 @@ proc removePeer(network: EthereumNode, peer: Peer) =
# between which side disconnects first.
if network.peerPool != nil and not peer.remote.isNil and peer.remote in network.peerPool.connectedNodes:
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)
# currently can get called before the dispatcher is initialized.