SQLite3 mem usage metric

This commit is contained in:
Ștefan Talpalaru 2020-05-09 01:30:50 +02:00 committed by zah
parent f730557baa
commit 9da92b5415
1 changed files with 34 additions and 2 deletions

View File

@ -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,
),
]