monitor.db

MetricDB — SQLite persistence for monitor metrics and events.

Owns the aiosqlite connection, the schema, the WAL-vs-DELETE journal choice (network filesystems can’t WAL), and the flock guard that stops two live collectors writing one database. Extracted from MetricCollector; behavior is identical.

class otto.monitor.db.MetricDB(path: str)

Bases: object

Persistent async SQLite store for one monitor database file.

async open() None

Acquire the flock guard, open the connection, apply schema + migration.

async close() None

Close the persistent DB connection and release the file lock.

async write_point(ts: datetime, host: str, label: str, value: float) None

Insert one metric point. No-op if the connection is not open.

async write_log_event(ts: datetime, host: str, tab: str, fields: dict[str, str]) None

Insert one log-event row (fields JSON-encoded). No-op if not open.

async write_event(event: MonitorEvent) int

Insert event into the DB and return the rowid (0 if no DB configured).

async delete_event(event_id: int) None

Delete the event with the given id. No-op if the connection is not open.

async update_event(event: MonitorEvent) None

Update an existing event’s label, color, dash, and end_ts. No-op if not open.