2024-06-28 10:34:57 +00:00
|
|
|
{.push raises: [].}
|
2022-10-21 08:33:36 +00:00
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
import metrics
|
2022-10-18 11:37:44 +00:00
|
|
|
|
2024-05-16 20:29:11 +00:00
|
|
|
proc parseCollectorIntoF64(collector: SimpleCollector): float64 {.gcsafe, raises: [].} =
|
2022-10-21 08:33:36 +00:00
|
|
|
{.gcsafe.}:
|
|
|
|
var total = 0.float64
|
2024-01-30 15:57:03 +00:00
|
|
|
for metrics in collector.metrics:
|
|
|
|
for metric in metrics:
|
|
|
|
try:
|
|
|
|
total = total + metric.value
|
|
|
|
except KeyError:
|
|
|
|
discard
|
2022-10-21 08:33:36 +00:00
|
|
|
return total
|
2022-10-18 11:37:44 +00:00
|
|
|
|
|
|
|
template parseAndAccumulate*(collector: Collector, cumulativeValue: float64): float64 =
|
|
|
|
## This template is used to get metrics in a window
|
|
|
|
## according to a cumulative value passed in
|
2022-10-21 08:33:36 +00:00
|
|
|
{.gcsafe.}:
|
|
|
|
let total = parseCollectorIntoF64(collector)
|
|
|
|
let freshCount = total - cumulativeValue
|
|
|
|
cumulativeValue = total
|
|
|
|
freshCount
|
|
|
|
|
|
|
|
template collectorAsF64*(collector: Collector): float64 =
|
|
|
|
## This template is used to get metrics from 0
|
|
|
|
## Serves as a wrapper for parseCollectorIntoF64 which is gcsafe
|
|
|
|
{.gcsafe.}:
|
|
|
|
let total = parseCollectorIntoF64(collector)
|
2024-03-15 23:08:47 +00:00
|
|
|
total
|