mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-03 22:43:09 +00:00
Split `WakuNodeConfig` object for better separation of concerns and to introduce a tree-like structure to configuration. * fix: ensure twn cluster conf is still applied when clusterId=1 * test: remove usage of `WakuNodeConf` * Remove macro, split builder files, remove wakunodeconf from tests * rm network_conf_builder module as it is not used --------- Co-authored-by: NagyZoltanPeter <113987313+NagyZoltanPeter@users.noreply.github.com> Co-authored-by: Ivan Folgueira Bande <ivansete@status.im>
89 lines
2.8 KiB
Nim
89 lines
2.8 KiB
Nim
{.push raises: [].}
|
|
|
|
import chronicles, chronos, metrics, metrics/chronos_httpserver
|
|
import
|
|
../waku_rln_relay/protocol_metrics as rln_metrics,
|
|
../utils/collector,
|
|
./peer_manager,
|
|
./waku_node
|
|
|
|
const LogInterval = 10.minutes
|
|
|
|
logScope:
|
|
topics = "waku node metrics"
|
|
|
|
type MetricsServerConf* = object
|
|
httpAddress*: IpAddress
|
|
httpPort*: Port
|
|
logging*: bool
|
|
|
|
proc startMetricsLog*() =
|
|
var logMetrics: CallbackFunc
|
|
|
|
var cumulativeErrors = 0.float64
|
|
var cumulativeConns = 0.float64
|
|
|
|
let logRlnMetrics = getRlnMetricsLogger()
|
|
|
|
logMetrics = CallbackFunc(
|
|
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.
|
|
|
|
# track cumulative values
|
|
let freshErrorCount = parseAndAccumulate(waku_node_errors, cumulativeErrors)
|
|
let freshConnCount =
|
|
parseAndAccumulate(waku_node_conns_initiated, cumulativeConns)
|
|
|
|
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)
|
|
|
|
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 errors", count = $freshErrorCount
|
|
|
|
# Start protocol specific metrics logging
|
|
logRlnMetrics()
|
|
|
|
discard setTimer(Moment.fromNow(LogInterval), logMetrics)
|
|
)
|
|
|
|
discard setTimer(Moment.fromNow(LogInterval), logMetrics)
|
|
|
|
proc startMetricsServer(
|
|
serverIp: IpAddress, serverPort: Port
|
|
): Result[MetricsHttpServerRef, string] =
|
|
info "Starting metrics HTTP server", serverIp = $serverIp, serverPort = $serverPort
|
|
|
|
let server = MetricsHttpServerRef.new($serverIp, serverPort).valueOr:
|
|
return err("metrics HTTP server start failed: " & $error)
|
|
|
|
try:
|
|
waitFor server.start()
|
|
except CatchableError:
|
|
return err("metrics HTTP server start failed: " & getCurrentExceptionMsg())
|
|
|
|
info "Metrics HTTP server started", serverIp = $serverIp, serverPort = $serverPort
|
|
return ok(server)
|
|
|
|
proc startMetricsServerAndLogging*(
|
|
conf: MetricsServerConf, portsShift: uint16
|
|
): Result[MetricsHttpServerRef, string] =
|
|
var metricsServer: MetricsHttpServerRef
|
|
metricsServer = startMetricsServer(
|
|
conf.httpAddress, Port(conf.httpPort.uint16 + portsShift)
|
|
).valueOr:
|
|
return err("Starting metrics server failed. Continuing in current state:" & $error)
|
|
|
|
if conf.logging:
|
|
startMetricsLog()
|
|
|
|
return ok(metricsServer)
|