feat: Initial commit for health monitoring widget with graphs (Work in Progress)
This commit is contained in:
1 parent
94263c445b
commit
3b20c96c35
20 files changed
+665
-670
No files matched your search
@@ -2,32 +2,30 @@ import dayjs from "dayjs";
|
||||
|
||||
import type { IntegrationKindByCategory } from "@homarr/definitions";
|
||||
import { createIntegrationAsync } from "@homarr/integrations";
|
||||
import type { HealthMonitoring, ProxmoxClusterInfo } from "@homarr/integrations/types";
|
||||
import type { HealthMonitoring } from "@homarr/integrations/types";
|
||||
import { createIntegrationHistoryChannel } from "@homarr/redis";
|
||||
|
||||
import { createCachedIntegrationRequestHandler } from "./lib/cached-integration-request-handler";
|
||||
|
||||
export const systemInfoRequestHandler = createCachedIntegrationRequestHandler<
|
||||
HealthMonitoring,
|
||||
Exclude<IntegrationKindByCategory<"healthMonitoring">, "proxmox">,
|
||||
Record<string, never>
|
||||
IntegrationKindByCategory<"healthMonitoring">,
|
||||
{ pointCount: number; maxElements: number }
|
||||
>({
|
||||
async requestAsync(integration, _input) {
|
||||
async requestAsync(integration, { pointCount, maxElements }) {
|
||||
const integrationInstance = await createIntegrationAsync(integration);
|
||||
return await integrationInstance.getSystemInfoAsync();
|
||||
const data = await integrationInstance.getSystemInfoAsync();
|
||||
const historyHandler = createIntegrationHistoryChannel<HealthMonitoring["history"][number]>(
|
||||
integration.id,
|
||||
"healthMonitoring",
|
||||
maxElements,
|
||||
);
|
||||
await historyHandler.pushAsync(data.history[0]);
|
||||
if (pointCount === 1) return data;
|
||||
const dbHistory = (await historyHandler.getSliceAsync(-pointCount, -1)).map(({ data }) => data);
|
||||
const history = (dbHistory.length > 0 ? dbHistory : data.history) as HealthMonitoring["history"];
|
||||
return { ...data, history } as HealthMonitoring;
|
||||
},
|
||||
cacheDuration: dayjs.duration(5, "seconds"),
|
||||
queryKey: "systemInfo",
|
||||
});
|
||||
|
||||
export const clusterInfoRequestHandler = createCachedIntegrationRequestHandler<
|
||||
ProxmoxClusterInfo,
|
||||
"proxmox",
|
||||
Record<string, never>
|
||||
>({
|
||||
async requestAsync(integration, _input) {
|
||||
const integrationInstance = await createIntegrationAsync(integration);
|
||||
return await integrationInstance.getClusterInfoAsync();
|
||||
},
|
||||
cacheDuration: dayjs.duration(5, "seconds"),
|
||||
queryKey: "clusterInfo",
|
||||
});
|
||||
Reference in new issue
Block a user