mirror of https://github.com/status-im/nim-eth.git
SQLite3 mem usage metric
This commit is contained in:
parent
f730557baa
commit
9da92b5415
|
@ -3,8 +3,8 @@
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
import
|
import
|
||||||
os,
|
os, tables, times,
|
||||||
sqlite3_abi,
|
chronicles, metrics, sqlite3_abi,
|
||||||
./kvstore
|
./kvstore
|
||||||
|
|
||||||
export kvstore
|
export kvstore
|
||||||
|
@ -162,3 +162,35 @@ proc init*(
|
||||||
delStmt: delStmt,
|
delStmt: delStmt,
|
||||||
containsStmt: containsStmt
|
containsStmt: containsStmt
|
||||||
))
|
))
|
||||||
|
|
||||||
|
when defined(metrics):
|
||||||
|
type Sqlite3Info = ref object of Gauge
|
||||||
|
|
||||||
|
proc newSqlite3Info*(name: string, help: string, registry = defaultRegistry): Sqlite3Info {.raises: [Exception].} =
|
||||||
|
validateName(name)
|
||||||
|
result = Sqlite3Info(name: name,
|
||||||
|
help: help,
|
||||||
|
typ: "gauge",
|
||||||
|
creationThreadId: getThreadId())
|
||||||
|
result.register(registry)
|
||||||
|
|
||||||
|
var sqlite3Info* {.global.} = newSqlite3Info("sqlite3_info", "SQLite3 info")
|
||||||
|
|
||||||
|
method collect*(collector: Sqlite3Info): Metrics =
|
||||||
|
result = initOrderedTable[Labels, seq[Metric]]()
|
||||||
|
result[@[]] = @[]
|
||||||
|
var
|
||||||
|
timestamp = getTime().toMilliseconds()
|
||||||
|
currentMem, highwaterMem: cint
|
||||||
|
|
||||||
|
if (let res = sqlite3_status(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