mirror of
https://github.com/waku-org/nwaku.git
synced 2025-01-30 00:25:45 +00:00
refactor(wakunode2): Split wankunode2 metrics setup to its own file
This commit is contained in:
parent
732f853f55
commit
538ee12a25
@ -65,36 +65,6 @@ proc startRpc*(node: WakuNode, rpcIp: ValidIpAddress, rpcPort: Port, conf: WakuN
|
||||
rpcServer.start()
|
||||
info "RPC Server started", ta
|
||||
|
||||
proc startMetricsServer*(serverIp: ValidIpAddress, serverPort: Port) =
|
||||
info "Starting metrics HTTP server", serverIp, serverPort
|
||||
|
||||
try:
|
||||
startMetricsHttpServer($serverIp, serverPort)
|
||||
except Exception as e:
|
||||
raiseAssert("Exception while starting metrics HTTP server: " & e.msg)
|
||||
|
||||
info "Metrics HTTP server started", serverIp, serverPort
|
||||
|
||||
proc startMetricsLog*() =
|
||||
# https://github.com/nim-lang/Nim/issues/17369
|
||||
var logMetrics: proc(udata: pointer) {.gcsafe, raises: [Defect].}
|
||||
logMetrics = proc(udata: pointer) =
|
||||
{.gcsafe.}:
|
||||
# TODO: libp2p_pubsub_peers is not public, so we need to make this either
|
||||
# public in libp2p or do our own peer counting after all.
|
||||
var
|
||||
totalMessages = 0.float64
|
||||
|
||||
for key in waku_node_messages.metrics.keys():
|
||||
try:
|
||||
totalMessages = totalMessages + waku_node_messages.value(key)
|
||||
except KeyError:
|
||||
discard
|
||||
|
||||
info "Node metrics", totalMessages
|
||||
discard setTimer(Moment.fromNow(2.seconds), logMetrics)
|
||||
discard setTimer(Moment.fromNow(2.seconds), logMetrics)
|
||||
|
||||
proc runMigrations*(sqliteDatabase: SqliteDatabase, conf: WakuNodeConf) =
|
||||
# Run migration scripts on persistent storage
|
||||
|
||||
|
@ -791,7 +791,11 @@ when isMainModule:
|
||||
../../common/utils/nat,
|
||||
./config,
|
||||
./waku_setup,
|
||||
<<<<<<< HEAD
|
||||
./wakunode2_setup_rest,
|
||||
=======
|
||||
./wakunode2_setup_metrics,
|
||||
>>>>>>> 37a9c0c1 (refactor(wakunode2): Split wankunode2 metrics setup to its own file)
|
||||
./storage/message/waku_message_store,
|
||||
./storage/peer/waku_peer_storage
|
||||
|
||||
|
47
waku/v2/node/wakunode2_setup_metrics.nim
Normal file
47
waku/v2/node/wakunode2_setup_metrics.nim
Normal file
@ -0,0 +1,47 @@
|
||||
{.push raises: [Defect].}
|
||||
|
||||
import
|
||||
stew/results,
|
||||
stew/shims/net,
|
||||
chronicles,
|
||||
chronos,
|
||||
metrics,
|
||||
metrics/chronos_httpserver,
|
||||
./config,
|
||||
./wakunode2
|
||||
|
||||
logScope:
|
||||
topics = "wakunode.setup.metrics"
|
||||
|
||||
|
||||
proc startMetricsServer*(serverIp: ValidIpAddress, serverPort: Port) =
|
||||
info "Starting metrics HTTP server", serverIp, serverPort
|
||||
|
||||
try:
|
||||
startMetricsHttpServer($serverIp, serverPort)
|
||||
except Exception as e:
|
||||
raiseAssert("Exception while starting metrics HTTP server: " & e.msg)
|
||||
|
||||
info "Metrics HTTP server started", serverIp, serverPort
|
||||
|
||||
|
||||
proc startMetricsLog*() =
|
||||
# https://github.com/nim-lang/Nim/issues/17369
|
||||
var logMetrics: proc(udata: pointer) {.gcsafe, raises: [Defect].}
|
||||
|
||||
logMetrics = proc(udata: pointer) =
|
||||
{.gcsafe.}:
|
||||
# TODO: libp2p_pubsub_peers is not public, so we need to make this either
|
||||
# public in libp2p or do our own peer counting after all.
|
||||
var totalMessages = 0.float64
|
||||
for key in waku_node_messages.metrics.keys():
|
||||
try:
|
||||
totalMessages = totalMessages + waku_node_messages.value(key)
|
||||
except KeyError:
|
||||
discard
|
||||
|
||||
info "Node metrics", totalMessages
|
||||
discard setTimer(Moment.fromNow(2.seconds), logMetrics)
|
||||
|
||||
discard setTimer(Moment.fromNow(2.seconds), logMetrics)
|
||||
|
Loading…
x
Reference in New Issue
Block a user