2024-06-28 16:04:57 +05:30
|
|
|
{.push raises: [].}
|
2022-10-21 14:03:36 +05:30
|
|
|
|
2024-03-16 00:08:47 +01:00
|
|
|
import metrics
|
2022-10-18 17:07:44 +05:30
|
|
|
|
2024-05-16 22:29:11 +02:00
|
|
|
proc parseCollectorIntoF64(collector: SimpleCollector): float64 {.gcsafe, raises: [].} =
|
2022-10-21 14:03:36 +05:30
|
|
|
{.gcsafe.}:
|
|
|
|
var total = 0.float64
|
2024-01-30 10:57:03 -05:00
|
|
|
for metrics in collector.metrics:
|
|
|
|
for metric in metrics:
|
|
|
|
try:
|
|
|
|
total = total + metric.value
|
|
|
|
except KeyError:
|
|
|
|
discard
|
2022-10-21 14:03:36 +05:30
|
|
|
return total
|
2022-10-18 17:07:44 +05:30
|
|
|
|
|
|
|
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 14:03:36 +05:30
|
|
|
{.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-16 00:08:47 +01:00
|
|
|
total
|