mirror of https://github.com/status-im/nim-eth.git
support nim-metrics 0.1.0+ (#651)
This commit is contained in:
parent
5aaeb67ebe
commit
0fc5dc03c5
|
@ -694,35 +694,43 @@ proc createCustomFunction*(
|
||||||
ok()
|
ok()
|
||||||
|
|
||||||
when defined(metrics):
|
when defined(metrics):
|
||||||
import locks, tables, times,
|
import chronicles, metrics
|
||||||
chronicles, metrics
|
|
||||||
|
|
||||||
type Sqlite3Info = ref object of Gauge
|
type Sqlite3Info = ref object of Collector
|
||||||
|
|
||||||
proc newSqlite3Info*(name: string, help: string, registry = defaultRegistry): Sqlite3Info {.raises: [Exception].} =
|
proc newSqlite3Info*(name: string, help: string, registry = defaultRegistry): Sqlite3Info {.raises: [CatchableError].} =
|
||||||
validateName(name)
|
Sqlite3Info.newCollector(name, help, registry = registry)
|
||||||
result = Sqlite3Info(name: name,
|
|
||||||
help: help,
|
|
||||||
typ: "gauge",
|
|
||||||
creationThreadId: getThreadId())
|
|
||||||
result.lock.initLock()
|
|
||||||
result.register(registry)
|
|
||||||
|
|
||||||
var sqlite3Info* {.global.} = newSqlite3Info("sqlite3_info", "SQLite3 info")
|
let sqlite3Info* = newSqlite3Info("sqlite3_info", "SQLite3 info")
|
||||||
|
|
||||||
method collect*(collector: Sqlite3Info): Metrics =
|
when declared(MetricHandler): # nim-metrics 0.1.0+
|
||||||
result = initOrderedTable[Labels, seq[Metric]]()
|
method collect*(collector: Sqlite3Info, output: MetricHandler) =
|
||||||
result[@[]] = @[]
|
let timestamp = collector.now()
|
||||||
let timestamp = getTime().toMilliseconds()
|
|
||||||
var currentMem, highwaterMem: int64
|
|
||||||
|
|
||||||
if (let res = sqlite3_status64(SQLITE_STATUS_MEMORY_USED, currentMem.addr, highwaterMem.addr, 0); res != SQLITE_OK):
|
var currentMem, highwaterMem: int64
|
||||||
error "SQLite3 error", msg = sqlite3_errstr(res)
|
|
||||||
else:
|
if (let res = sqlite3_status64(SQLITE_STATUS_MEMORY_USED, currentMem.addr, highwaterMem.addr, 0); res != SQLITE_OK):
|
||||||
result[@[]] = @[
|
error "SQLite3 error", msg = sqlite3_errstr(res)
|
||||||
Metric(
|
else:
|
||||||
name: "sqlite3_memory_used_bytes",
|
output(
|
||||||
value: currentMem.float64,
|
name = "sqlite3_memory_used_bytes",
|
||||||
timestamp: timestamp,
|
value = currentMem.float64,
|
||||||
),
|
timestamp = timestamp,
|
||||||
]
|
)
|
||||||
|
else: # nim-metrics 0.0.1
|
||||||
|
method collect*(collector: Sqlite3Info): Metrics =
|
||||||
|
result = initOrderedTable[Labels, seq[Metric]]()
|
||||||
|
result[@[]] = @[]
|
||||||
|
let timestamp = getTime().toMilliseconds()
|
||||||
|
var currentMem, highwaterMem: int64
|
||||||
|
|
||||||
|
if (let res = sqlite3_status64(SQLITE_STATUS_MEMORY_USED, currentMem.addr, highwaterMem.addr, 0); res != SQLITE_OK):
|
||||||
|
error "SQLite3 error", msg = sqlite3_errstr(res)
|
||||||
|
else:
|
||||||
|
result[@[]] = @[
|
||||||
|
Metric(
|
||||||
|
name: "sqlite3_memory_used_bytes",
|
||||||
|
value: currentMem.float64,
|
||||||
|
timestamp: timestamp,
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
Loading…
Reference in New Issue