fix monitor error

This commit is contained in:
larssand
2026-07-06 13:02:10 +02:00
parent 35282bca7f
commit d314c94dee
6 changed files with 30 additions and 24 deletions

View File

@@ -556,6 +556,7 @@ class BaselineStore:
value_retention_days: int = DEFAULT_VALUE_RETENTION_DAYS,
max_values_per_field: int = DEFAULT_MAX_VALUES_PER_FIELD,
vacuum: bool = False,
include_rows: bool = False,
) -> dict[str, object]:
now = int(time.time())
bucket_cutoff = now - max(1, retention_days) * 86400
@@ -597,35 +598,39 @@ class BaselineStore:
if vacuum:
with self._connect() as connection:
connection.execute("vacuum")
stats = self.stats()
stats = self.stats(include_rows=include_rows)
return {"retention_days": retention_days, "value_retention_days": value_retention_days, "max_values_per_field": max_values_per_field, "vacuum": vacuum, "deleted": deleted, **stats}
def stats(self) -> dict[str, object]:
def stats(self, *, include_rows: bool = False) -> dict[str, object]:
with self._connect() as connection:
tables = (
"seen_events",
"source_buckets",
"source_values",
"profile_seen_events",
"profile_buckets",
"profile_temporal_buckets",
"profile_detector_buckets",
"profile_detector_temporal_buckets",
"profile_values",
)
rows = {table: int(connection.execute(f"select count(*) from {table}").fetchone()[0]) for table in tables}
page_size = int(connection.execute("pragma page_size").fetchone()[0])
page_count = int(connection.execute("pragma page_count").fetchone()[0])
freelist_count = int(connection.execute("pragma freelist_count").fetchone()[0])
rows = {}
if include_rows:
tables = (
"seen_events",
"source_buckets",
"source_values",
"profile_seen_events",
"profile_buckets",
"profile_temporal_buckets",
"profile_detector_buckets",
"profile_detector_temporal_buckets",
"profile_values",
)
rows = {table: int(connection.execute(f"select count(*) from {table}").fetchone()[0]) for table in tables}
size_bytes = self.path.stat().st_size if self.path.exists() else 0
return {
stats: dict[str, object] = {
"size_bytes": size_bytes,
"page_size": page_size,
"page_count": page_count,
"freelist_count": freelist_count,
"reclaimable_bytes": freelist_count * page_size,
"rows": rows,
}
if include_rows:
stats["rows"] = rows
return stats
def profile_readiness(self, profiles: dict[str, object], *, min_training_days: int = 0) -> list[dict[str, object]]:
rows: list[dict[str, object]] = []