2022-07-17 15:16:57 +00:00
|
|
|
{.push raises: [Defect].}
|
|
|
|
|
|
|
|
import
|
|
|
|
stew/shims/net,
|
|
|
|
chronicles,
|
|
|
|
chronos,
|
|
|
|
metrics,
|
2022-10-18 17:35:26 +00:00
|
|
|
metrics/chronos_httpserver
|
|
|
|
import
|
2022-11-02 10:59:58 +00:00
|
|
|
../protocol/waku_filter/protocol_metrics as filter_metrics,
|
2022-10-25 12:55:31 +00:00
|
|
|
../protocol/waku_store/protocol_metrics as store_metrics,
|
|
|
|
../protocol/waku_lightpush/protocol_metrics as lightpush_metrics,
|
2022-10-21 08:33:36 +00:00
|
|
|
../protocol/waku_swap/waku_swap,
|
|
|
|
../protocol/waku_peer_exchange,
|
|
|
|
../utils/collector,
|
|
|
|
./peer_manager/peer_manager,
|
|
|
|
./waku_node
|
2022-10-18 17:35:26 +00:00
|
|
|
|
|
|
|
when defined(rln) or defined(rlnzerokit):
|
2022-10-21 08:33:36 +00:00
|
|
|
import ../protocol/waku_rln_relay/waku_rln_relay_metrics
|
2022-10-18 17:35:26 +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
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
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-10-18 11:37:44 +00:00
|
|
|
when defined(rln) or defined(rlnzerokit):
|
|
|
|
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-08-31 09:53:28 +00:00
|
|
|
info "Total connections initiated", count = freshConnCount
|
2022-10-21 08:33:36 +00:00
|
|
|
info "Total messages", count = collectorAsF64(waku_node_messages)
|
|
|
|
info "Total swap peers", count = collectorAsF64(waku_swap_peers_count)
|
|
|
|
info "Total filter peers", count = collectorAsF64(waku_filter_peers)
|
|
|
|
info "Total store peers", count = collectorAsF64(waku_store_peers)
|
|
|
|
info "Total lightpush peers", count = collectorAsF64(waku_lightpush_peers)
|
|
|
|
info "Total peer exchange peers", count = collectorAsF64(waku_px_peers)
|
2022-08-31 09:53:28 +00:00
|
|
|
info "Total errors", count = freshErrorCount
|
2022-10-21 08:33:36 +00:00
|
|
|
info "Total active filter subscriptions", count = collectorAsF64(waku_filter_subscribers)
|
2022-08-31 09:53:28 +00:00
|
|
|
|
2022-10-18 11:37:44 +00:00
|
|
|
# Start protocol specific metrics logging
|
|
|
|
when defined(rln) or defined(rlnzerokit):
|
|
|
|
logRlnMetrics()
|
|
|
|
|
2022-10-21 08:33:36 +00:00
|
|
|
discard setTimer(Moment.fromNow(LogInterval), logMetrics)
|
2022-09-20 11:03:34 +00:00
|
|
|
|
2022-10-21 08:33:36 +00:00
|
|
|
discard setTimer(Moment.fromNow(LogInterval), logMetrics)
|