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

+12
View File
@@ -30,6 +30,7 @@ import { getSourceStatus } from "../services/integrationHealthMonitor.js";
import { dockerVulnSyncStatuses, findingsOf, imageAgeDays, imagesOf, isDockerVulnFresh } from "../services/dockerVulnSync.js";
import { invalidateAlertsCache } from "../services/alerts.js";
import { forgetReading, readAfterChange, readIntegrationNow } from "../services/integrationSyncs.js";
import { getIntegrationFigures, hasFigures } from "../services/integrationFigures.js";
import { getSettings, updateSettings } from "../services/settingsStore.js";
import { asyncHandler } from "../utils/asyncHandler.js";
import { ID_PATTERNS, isValidId } from "../utils/pathSegment.js";
@@ -293,6 +294,17 @@ integrationsRouter.post("/:id/test", requireRole("admin"), asyncHandler(async (r
// Reads one integration now, instead of waiting for its next turn: a kind with a stored reading is read the way its schedule reads it (and what it says is judged again at once); a kind that is read live
// is asked whether it answers. Operators and administrators — it only reads, but some systems limit how often they may be asked, so the same integration is not read again within 20 seconds.
// How the figures an integration reports (queries a day, items in a queue, photos, documents …) have moved: a day to a year, drawn from what is kept (services/integrationFigures.ts). Anyone signed in.
integrationsRouter.get("/:id/figures", asyncHandler(async (req, res) => {
const id = Number(req.params.id);
if (!Number.isInteger(id)) return res.status(400).json({ error: "invalid_id" });
const [row] = await db.select({ type: integrations.type }).from(integrations).where(eq(integrations.id, id)).limit(1);
if (!row) return res.status(404).json({ error: "not_found" });
const asked = Number(req.query.days);
const days = Number.isFinite(asked) ? asked : 7;
res.json({ kept: hasFigures(row.type), days: Math.min(365, Math.max(1, Math.round(days))), figures: hasFigures(row.type) ? await getIntegrationFigures(id, days) : [] });
}));
integrationsRouter.post("/:id/read-now", requireRole("operator"), asyncHandler(async (req, res) => {
const id = Number(req.params.id);
if (!Number.isInteger(id)) return res.status(400).json({ error: "invalid_id" });