Grafana¶
mt5cli.grafana ¶
Grafana-oriented SQLite views, indexes, and snapshot tables.
create_grafana_indexes ¶
Create Grafana query performance indexes idempotently.
Source code in mt5cli/grafana.py
create_grafana_views ¶
Create all Grafana-facing views idempotently.
Missing source tables cause the affected view to be skipped with a warning; other views are unaffected. Stale views whose source table or required columns have disappeared are dropped before rebuild.
Source code in mt5cli/grafana.py
create_snapshot_tables ¶
ensure_grafana_schema ¶
Create snapshot tables, Grafana views, and indexes idempotently.
insert_account_snapshot ¶
Append one account state row to account_snapshots.
Source code in mt5cli/grafana.py
insert_order_snapshots ¶
insert_order_snapshots(
conn: Connection,
run_id: int,
login: int | None,
rows: list[dict[str, object]],
) -> None
Append order rows to order_snapshots; no-op when rows is empty.
Source code in mt5cli/grafana.py
insert_position_snapshots ¶
insert_position_snapshots(
conn: Connection,
run_id: int,
login: int | None,
rows: list[dict[str, object]],
) -> None
Append position rows to position_snapshots; no-op when rows is empty.
Source code in mt5cli/grafana.py
insert_terminal_snapshot ¶
Append one terminal state row to terminal_snapshots.
Source code in mt5cli/grafana.py
publish_grafana_copy ¶
Publish a consistent SQLite copy for Grafana using the backup API.
Uses the SQLite online backup API for a WAL-safe, consistent snapshot of the source database. Writes to a temporary file beside the target, then atomically replaces it so that a previous published copy is preserved if publishing fails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str | Path
|
Path to the source SQLite database. |
required |
target
|
str | Path
|
Destination path for the published copy. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
The resolved absolute target path. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the source database does not exist. |
ValueError
|
If source and target resolve to the same path. |
Source code in mt5cli/grafana.py
record_snapshot_run ¶
record_snapshot_run(
conn: Connection,
run_id: int,
status: str,
detail: str | None = None,
) -> None
Finalize a snapshot run by setting its status.
Source code in mt5cli/grafana.py
start_snapshot_run ¶
Insert a snapshot_runs row with status 'running' and return its run_id.
Returns:
| Type | Description |
|---|---|
int
|
The auto-assigned run_id for the new row. |
Source code in mt5cli/grafana.py
Grafana-ready SQLite workflow¶
Use ensure_grafana_schema(conn) or the grafana-schema CLI command to create
the snapshot tables, grafana_* views, and supporting indexes in one step.
publish_grafana_copy(source, target) creates a consistent SQLite copy via the
SQLite backup API, which is useful when the primary database is running in WAL
mode and Grafana should read from a separate published file.
Main APIs¶
ensure_grafana_schema(): idempotently creates snapshot tables, Grafana views, and indexes.create_grafana_views(): rebuilds the shippedgrafana_*views.create_grafana_indexes(): creates read-oriented indexes for Grafana queries.publish_grafana_copy(): writes an atomic, WAL-safe published copy for a Grafana datasource.
For end-to-end snapshot collection examples, see the Grafana and observability
section in the project README.md.