Unify telemetry storage and add repo filtering
Refactor telemetry backend to store all telemetry in a single collection and add repo_source-based filtering. Key changes: - Added detect_repo_source() in misc/api.func to auto-detect/export REPO_SOURCE (ProxmoxVE/ProxmoxVED/external) when scripts are sourced. - Consolidated PocketBase collections into a single default collection (_telemetry_data) across service, migration, and scripts; updated defaults in migrate.go, migration.go, migrate.sh and migration shell scripts. - Simplified PBClient to use one targetColl and removed collection resolution logic; updated create/update/find/fetch functions to use targetColl. - Introduced repo_source field (values: "ProxmoxVE", "ProxmoxVED", "external") on telemetry records and telemetry payloads; updated validation and logging. - Added repo filtering to dashboard endpoints, FetchDashboardData and FetchRecordsPaginated, plus a repo selector in the dashboard UI; default filter is ProxmoxVE (production), with an "all" option. - Adjusted API handlers and callers to pass repo filters and include repo_source when upserting telemetry. - Misc: updated comments, error messages, and logging to reflect the new model; added telemetry-service.exe binary. Purpose: simplify data model (single collection), make telemetry attributable to repository sources, and enable dashboard filtering by repo/source.
This commit is contained in:
@@ -134,7 +134,7 @@ func (a *Alerter) checkAndAlert() {
|
||||
defer cancel()
|
||||
|
||||
// Fetch last hour's data
|
||||
data, err := a.pb.FetchDashboardData(ctx, 1)
|
||||
data, err := a.pb.FetchDashboardData(ctx, 1, "ProxmoxVE")
|
||||
if err != nil {
|
||||
log.Printf("WARN: alert check failed: %v", err)
|
||||
return
|
||||
@@ -410,13 +410,13 @@ func (a *Alerter) fetchWeeklyReportData(ctx context.Context) (*WeeklyReportData,
|
||||
year, week := lastMonday.ISOWeek()
|
||||
|
||||
// Fetch current week's data (7 days)
|
||||
currentData, err := a.pb.FetchDashboardData(ctx, 7)
|
||||
currentData, err := a.pb.FetchDashboardData(ctx, 7, "ProxmoxVE")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to fetch current week data: %w", err)
|
||||
}
|
||||
|
||||
// Fetch previous week's data for comparison (14 days, we'll compare)
|
||||
prevData, err := a.pb.FetchDashboardData(ctx, 14)
|
||||
prevData, err := a.pb.FetchDashboardData(ctx, 14, "ProxmoxVE")
|
||||
if err != nil {
|
||||
// Non-fatal, just log
|
||||
log.Printf("WARN: could not fetch previous week data: %v", err)
|
||||
|
||||
Reference in New Issue
Block a user