-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
49 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import {createTRPCRouter, publicProcedure} from "../../trpc"; | ||
import {createManyIntegrationMiddleware} from "../../middlewares/integration"; | ||
import {createItemAndIntegrationChannel} from "@homarr/redis"; | ||
import {CpuLoad} from "@homarr/integrations"; | ||
|
||
export const hardwareUsageRouter = createTRPCRouter({ | ||
getCpuHistory: publicProcedure | ||
.unstable_concat(createManyIntegrationMiddleware("query", "getDashDot")) | ||
.query(async ({ ctx }) => { | ||
return await Promise.all( | ||
ctx.integrations.map(async (integration) => { | ||
const channel = createItemAndIntegrationChannel<CpuLoad[]>("hardwareUsage", integration.id); | ||
const data = await channel.getAsync(); | ||
return { | ||
integrationId: integration.id, | ||
sessions: data?.data ?? [], | ||
}; | ||
}), | ||
); | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,24 @@ | ||
import {Integration} from "../base/integration"; | ||
import type {CpuLoad} from "../interfaces/hardware-usage/cpu-load"; | ||
|
||
export class DashDotIntegration extends Integration { | ||
public async testConnectionAsync(): Promise<void> { | ||
const response = await fetch(this.integration.url + (this.integration.url.endsWith("/") ? "info" : "/info")); | ||
await response.json(); | ||
} | ||
|
||
public async getCurrentCpuLoadAsync(): Promise<CpuLoad> { | ||
const cpu = await fetch(this.integration.url + (this.integration.url.endsWith("/") ? "load/cpu" : "/load/cpu")); | ||
const data = (await cpu.json()) as CpuLoadApi[]; | ||
return { | ||
sumLoad: data.reduce((acc, current) => acc + current.load, 0), | ||
}; | ||
} | ||
} | ||
|
||
/** | ||
* CPU load per core | ||
*/ | ||
interface CpuLoadApi { | ||
load: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
packages/integrations/src/interfaces/hardware-usage/cpu-load.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface CpuLoad { | ||
sumLoad: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters