chore(logging): Periodic logging for additional metrics (#1094)

* chore: enable metrics logging by default

* feat(logging): add additional logging metrics, change period to 30 seconds

* chore(logging): s/var/let

* chore(logging): import filter directly

* chore(logging): add store/lightpush peer count, fix style
This commit is contained in:
Aaryamann Challani 2022-08-31 15:23:28 +05:30 committed by GitHub
parent 0deedf0d7a
commit ed53bcdec6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 11 deletions

View File

@ -324,7 +324,7 @@ type
metricsLogging* {.
desc: "Enable metrics logging: true|false"
defaultValue: false
defaultValue: true
name: "metrics-logging" }: bool
## DNS discovery config

View File

@ -8,7 +8,10 @@ import
metrics,
metrics/chronos_httpserver,
./config,
./wakunode2
./wakunode2,
../protocol/waku_filter,
../protocol/waku_store,
../protocol/waku_lightpush
logScope:
topics = "wakunode.setup.metrics"
@ -24,24 +27,46 @@ proc startMetricsServer*(serverIp: ValidIpAddress, serverPort: Port) =
info "Metrics HTTP server started", serverIp, serverPort
proc parseCollectorIntoF64(collector: Collector): float64 =
var total = 0.float64
for key in collector.metrics.keys():
try:
total = total + collector.value(key)
except KeyError:
discard
return total
proc startMetricsLog*() =
# https://github.com/nim-lang/Nim/issues/17369
var logMetrics: proc(udata: pointer) {.gcsafe, raises: [Defect].}
var cumulativeErrors = 0.float64
var cumulativeConns = 0.float64
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)
let totalErrors = parseCollectorIntoF64(waku_node_errors)
let totalConnections = parseCollectorIntoF64(waku_node_conns_initiated)
# track cumulative, and then max.
let freshErrorCount = max(totalErrors - cumulativeErrors, 0)
let freshConnCount = max(totalConnections - cumulativeConns, 0)
cumulativeErrors = totalErrors
cumulativeConns = totalConnections
info "Total connections initiated", count = freshConnCount
info "Total messages", count = parseCollectorIntoF64(waku_node_messages)
info "Total swap peers", count = parseCollectorIntoF64(waku_swap_peers_count)
info "Total filter peers", count = parseCollectorIntoF64(waku_filter_peers)
info "Total store peers", count = parseCollectorIntoF64(waku_store_peers)
info "Total lightpush peers", count = parseCollectorIntoF64(waku_lightpush_peers)
info "Total errors", count = freshErrorCount
info "Total active filter subscriptions", count = parseCollectorIntoF64(waku_filter_subscribers)
discard setTimer(Moment.fromNow(30.seconds), logMetrics)
discard setTimer(Moment.fromNow(2.seconds), logMetrics)
discard setTimer(Moment.fromNow(30.seconds), logMetrics)