Keep a history of integration figures and draw it on each integration's page

The numbers integrations report (queries and blocked share, queue and missing
items, speeds, photos, documents, failed runs, firing rules, targets down,
monthly cost and more) are kept about every quarter of an hour for five weeks,
then as hours and days for up to two years, taken from each integration's
stored reading. Every card on the 14 integration pages gets a Show the
history button with a chart per figure, how it changed and its lowest and
highest. A stretch when the integration could not be read is a gap.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
bobbanandClaude Sonnet 5.5 committed 2026-11-12 21:12:47 +01:00
1 parent e4f3a54189
commit e7f23ba13f
30 files changed
+10532 -1

No files matched your search

+51
View File
@@ -1991,6 +1991,57 @@ export const storageSamples = sqliteTable(
(t) => [index("storage_samples_series_idx").on(t.seriesId, t.at)],
);
// ─── The figures of an integration, over time ──────────────────────────────
// A number an integration reports (queries a day, items in a queue, photos, documents, a monthly cost), one row for each, so how it has moved can be drawn — see services/integrationFigures.ts.
// `unit` says how to write it (count, percent, ms, bytes, bytes_per_s, money:SEK …); `latest` is the last reading.
export const integrationFigures = sqliteTable(
"integration_figures",
{
id: integer("id").primaryKey({ autoIncrement: true }),
integrationId: integer("integration_id")
.notNull()
.references(() => integrations.id, { onDelete: "cascade" }),
key: text("key").notNull(), // "queries", "queue", "photos" …: stable within a kind of integration
label: text("label").notNull(),
unit: text("unit").notNull(),
latest: real("latest").notNull(),
updatedAt: text("updated_at").notNull(), // ISO; the last reading
},
(t) => [uniqueIndex("integration_figures_key_idx").on(t.integrationId, t.key)],
);
// The readings themselves, one about every quarter of an hour, kept five weeks.
export const integrationFigureSamples = sqliteTable(
"integration_figure_samples",
{
id: integer("id").primaryKey({ autoIncrement: true }),
figureId: integer("figure_id")
.notNull()
.references(() => integrationFigures.id, { onDelete: "cascade" }),
at: text("at").notNull(), // ISO
value: real("value").notNull(),
},
(t) => [index("integration_figure_samples_idx").on(t.figureId, t.at)],
);
// The same, coarser and kept longer: one row for each figure and hour (grain "h", four months) or day (grain "d", over two years), like the servers' (server_metrics_rollup).
export const integrationFigureRollup = sqliteTable(
"integration_figure_rollup",
{
figureId: integer("figure_id")
.notNull()
.references(() => integrationFigures.id, { onDelete: "cascade" }),
grain: text("grain").$type<"h" | "d">().notNull(),
at: text("at").notNull(),
sum: real("sum").notNull(),
n: integer("n").notNull(),
min: real("min").notNull(),
max: real("max").notNull(),
},
(t) => [primaryKey({ columns: [t.figureId, t.grain, t.at] })],
);
// "Remind me tomorrow at 09:00": an alert hidden until a time, and announced again then if it is still there — see services/alertSnoozes.ts. Keyed like an acknowledgement.
export const alertSnoozes = sqliteTable(
"alert_snoozes",