2022-11-04 09:52:27 +00:00
|
|
|
when (NimMajor, NimMinor) < (1, 4):
|
|
|
|
{.push raises: [Defect].}
|
|
|
|
else:
|
|
|
|
{.push raises: [].}
|
2022-07-17 15:16:57 +00:00
|
|
|
|
|
|
|
import
|
|
|
|
chronicles,
|
|
|
|
chronos,
|
|
|
|
metrics,
|
2022-10-18 17:35:26 +00:00
|
|
|
metrics/chronos_httpserver
|
|
|
|
import
|
2023-04-18 13:22:10 +00:00
|
|
|
../waku_filter/protocol_metrics as filter_metrics,
|
2022-10-21 08:33:36 +00:00
|
|
|
../utils/collector,
|
2023-02-06 09:03:30 +00:00
|
|
|
./peer_manager,
|
2022-10-21 08:33:36 +00:00
|
|
|
./waku_node
|
2022-10-18 17:35:26 +00:00
|
|
|
|
2022-11-09 18:45:04 +00:00
|
|
|
when defined(rln):
|
2023-04-18 13:22:10 +00:00
|
|
|
import ../waku_rln_relay/protocol_metrics as rln_metrics
|
2022-10-18 17:35:26 +00:00
|
|
|
|
2022-11-04 09:52:08 +00:00
|
|
|
|
2022-10-21 08:33:36 +00:00
|
|
|
const LogInterval = 30.seconds
|
2022-07-17 15:16:57 +00:00
|
|
|
|
|
|
|
logScope:
|
2022-11-03 15:36:24 +00:00
|
|
|
topics = "waku node metrics"
|
2022-07-17 15:16:57 +00:00
|
|
|
|
|
|
|
|
2022-10-21 08:33:36 +00:00
|
|
|
type
|
|
|
|
# https://github.com/nim-lang/Nim/issues/17369
|
|
|
|
MetricsLogger = proc(udata: pointer) {.gcsafe, raises: [Defect].}
|
2022-07-17 15:16:57 +00:00
|
|
|
|
|
|
|
proc startMetricsLog*() =
|
2022-10-21 08:33:36 +00:00
|
|
|
var logMetrics: MetricsLogger
|
2022-07-17 15:16:57 +00:00
|
|
|
|
2022-08-31 09:53:28 +00:00
|
|
|
var cumulativeErrors = 0.float64
|
|
|
|
var cumulativeConns = 0.float64
|
|
|
|
|
2022-11-09 18:45:04 +00:00
|
|
|
when defined(rln):
|
2022-10-18 11:37:44 +00:00
|
|
|
let logRlnMetrics = getRlnMetricsLogger()
|
|
|
|
|
2022-07-17 15:16:57 +00:00
|
|
|
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.
|
2022-08-31 09:53:28 +00:00
|
|
|
|
2022-10-18 11:37:44 +00:00
|
|
|
# track cumulative values
|
|
|
|
let freshErrorCount = parseAndAccumulate(waku_node_errors, cumulativeErrors)
|
|
|
|
let freshConnCount = parseAndAccumulate(waku_node_conns_initiated, cumulativeConns)
|
2022-10-21 08:33:36 +00:00
|
|
|
|
2022-12-07 11:30:32 +00:00
|
|
|
let totalMessages = collectorAsF64(waku_node_messages)
|
|
|
|
let storePeers = collectorAsF64(waku_store_peers)
|
|
|
|
let pxPeers = collectorAsF64(waku_px_peers)
|
|
|
|
let lightpushPeers = collectorAsF64(waku_lightpush_peers)
|
|
|
|
let filterPeers = collectorAsF64(waku_filter_peers)
|
2023-04-11 08:12:54 +00:00
|
|
|
let filterSubscribers = collectorAsF64(waku_legacy_filter_subscribers)
|
2022-12-07 11:30:32 +00:00
|
|
|
|
|
|
|
info "Total connections initiated", count = $freshConnCount
|
|
|
|
info "Total messages", count = totalMessages
|
|
|
|
info "Total store peers", count = storePeers
|
|
|
|
info "Total peer exchange peers", count = pxPeers
|
|
|
|
info "Total lightpush peers", count = lightpushPeers
|
|
|
|
info "Total filter peers", count = filterPeers
|
|
|
|
info "Total active filter subscriptions", count = filterSubscribers
|
|
|
|
info "Total errors", count = $freshErrorCount
|
2022-08-31 09:53:28 +00:00
|
|
|
|
2022-10-18 11:37:44 +00:00
|
|
|
# Start protocol specific metrics logging
|
2022-11-09 18:45:04 +00:00
|
|
|
when defined(rln):
|
2022-10-18 11:37:44 +00:00
|
|
|
logRlnMetrics()
|
|
|
|
|
2022-10-21 08:33:36 +00:00
|
|
|
discard setTimer(Moment.fromNow(LogInterval), logMetrics)
|
2022-12-07 11:30:32 +00:00
|
|
|
|
2022-10-21 08:33:36 +00:00
|
|
|
discard setTimer(Moment.fromNow(LogInterval), logMetrics)
|