logos-delivery/waku/v2/utils/collector.nim
Aaryamann Challani 9a6a7334ef
feat(rln-relay): periodically log metrics (#1262)
* feat(rln-relay): periodically log metrics

* chore(rln-relay): log rln metrics immediately

* fix(metrics): calculation etc

* chore(metrics): parseAndAccumulate into collector utils

* fix(metrics): use standard logging interval
2022-10-18 17:07:44 +05:30

19 lines
566 B
Nim

import
metrics
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
template parseAndAccumulate*(collector: Collector, cumulativeValue: float64): float64 =
## This template is used to get metrics in a window
## according to a cumulative value passed in
let total = parseCollectorIntoF64(collector)
let freshCount = total - cumulativeValue
cumulativeValue = total
freshCount