mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-07 00:13:06 +00:00
* feat(rln-relay): metrics * fix(rln-relay): invalid token * fix(rln-relay): return outside time * style(rln-relay): multiline proc def * fix(rln-relay): oserror * fix(rln-relay): Exception should not be raised * Revert "fix(rln-relay): oserror" This reverts commit edcf39c0088ca526ca50256d856eee20d87a3c37. * Revert "fix(rln-relay): Exception should not be raised" This reverts commit c8d09b055314a83bb4a94900a47e899773cb47df. * fix(rln-relay): revert exception removal * feat(rln-relay): granular tracking * fix(rln-relay): observe only on histogram, convert mount to hist * chore(rln-relay): add additional metrics * fix(rln-relay): missing import * fix(rln-relay): template should expand only when times is defined * fix(rln-relay): follow prometheus naming style * fix(rln-relay): explicitly assert that the root window size should be less than 10 * fix(rln-relay): outstanding issues with infinite labels, minor refactor * fix(rln-relay): typo * fix(rln-relay): screaming case to pascal case * fix(rln-relay): typos * fix(rln-relay): imports * fix(rln-relay): remove dependence on times, make durations as gauges * fix(rln-relay): import order
39 lines
987 B
Nim
39 lines
987 B
Nim
## Contains types and utilities for timestamps.
|
|
{.push raises: [Defect].}
|
|
|
|
import
|
|
std/times,
|
|
metrics
|
|
|
|
type Timestamp* = int64
|
|
|
|
proc getNanosecondTime*[T](timeInSeconds: T): Timestamp =
|
|
var ns = Timestamp(timeInSeconds.int64 * 1000_000_000.int64)
|
|
return ns
|
|
|
|
proc getMicrosecondTime*[T](timeInSeconds: T): Timestamp =
|
|
var us = Timestamp(timeInSeconds.int64 * 1000_000.int64)
|
|
return us
|
|
|
|
proc getMillisecondTime*[T](timeInSeconds: T): Timestamp =
|
|
var ms = Timestamp(timeInSeconds.int64 * 1000.int64)
|
|
return ms
|
|
|
|
proc nowInUnixFloat(): float =
|
|
return getTime().toUnixFloat()
|
|
|
|
template nanosecondTime*(collector: Summary | Histogram, body: untyped) =
|
|
when defined(metrics):
|
|
let start = nowInUnixFloat()
|
|
body
|
|
collector.observe(nowInUnixFloat() - start)
|
|
else:
|
|
body
|
|
|
|
template nanosecondTime*(collector: Gauge, body: untyped) =
|
|
when defined(metrics):
|
|
let start = nowInUnixFloat()
|
|
body
|
|
collector.set(nowInUnixFloat() - start)
|
|
else:
|
|
body |