feat(beszel): add SSE subscription endpoint and per-period cache TTL
- Add subscribeSystemStats tRPC subscription bridging PocketBase SSE - Add subscribeRealtimeMetrics to BeszelIntegration with SSE parsing - Add error handling: try/catch in subscription, response check in topic POST - Add cacheDurationForInput to request handler for per-period cache TTL - Add mock subscribeRealtimeMetrics with 1s interval for dev testing
This commit is contained in:
6 files changed
+272
-49
No files matched your search
@@ -330,6 +330,35 @@ export class BeszelMockService {
|
||||
];
|
||||
}
|
||||
|
||||
public async subscribeRealtimeMetrics(
|
||||
systemId: string,
|
||||
onMessage: (data: { stats: BeszelSystemStatsRecord; containerStats: BeszelContainerStatsRecord | null }) => void,
|
||||
signal: AbortSignal,
|
||||
): Promise<void> {
|
||||
const sys = resolveSystem(systemId);
|
||||
const emit = () => {
|
||||
if (signal.aborted) return;
|
||||
const [stats] = generateSystemStatsSeries(1, sys);
|
||||
if (!stats) return;
|
||||
const record: BeszelSystemStatsRecord = {
|
||||
id: `mock-rt-${Date.now()}`,
|
||||
system: systemId,
|
||||
stats,
|
||||
type: "1m",
|
||||
created: new Date().toISOString(),
|
||||
updated: new Date().toISOString(),
|
||||
};
|
||||
onMessage({ stats: record, containerStats: null });
|
||||
};
|
||||
await new Promise<void>((resolve) => {
|
||||
const interval = setInterval(emit, 1000);
|
||||
signal.addEventListener("abort", () => {
|
||||
clearInterval(interval);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public async getAlertHistoryAsync(_systemId?: string, perPage = 10): Promise<BeszelAlertHistory[]> {
|
||||
const now = Date.now();
|
||||
const names = ["CPU", "Memory", "Disk", "Temperature", "Bandwidth"];
|
||||
|
||||
Reference in new issue
Block a user