Skip to content

A modern and easy to use dashboard. 80+ integrations. 20K+ icons built in. Authentication out of the box. No YAML, drag and drop configuration.

feat: add healthchecks (#1187)

Manuel08c6303fa64a
diff --git a/.gitignore b/.gitignore
index 91c18132f..bdc55c860 100644
--- a/.gitignore
+++ b/.gitignore
@@ -56,6 +56,7 @@ yarn-error.log*
apps/tasks/tasks.cjs
apps/websocket/wssServer.cjs
apps/nextjs/.million/
+packages/cli/cli.cjs
#personal backgrounds
diff --git a/apps/nextjs/package.json b/apps/nextjs/package.json
index 41773076c..2f4c89193 100644
--- a/apps/nextjs/package.json
+++ b/apps/nextjs/package.json
@@ -30,6 +30,7 @@
"@homarr/modals-collection": "workspace:^0.1.0",
"@homarr/notifications": "workspace:^0.1.0",
"@homarr/old-schema": "workspace:^0.1.0",
+ "@homarr/redis": "workspace:^0.1.0",
"@homarr/server-settings": "workspace:^0.1.0",
"@homarr/spotlight": "workspace:^0.1.0",
"@homarr/translation": "workspace:^0.1.0",
diff --git a/apps/nextjs/src/app/api/health/live/route.ts b/apps/nextjs/src/app/api/health/live/route.ts
new file mode 100644
index 000000000..57cc9b207
--- /dev/null
+++ b/apps/nextjs/src/app/api/health/live/route.ts
@@ -0,0 +1,91 @@
+import { performance } from "perf_hooks";
+
+import { db } from "@homarr/db";
+import { logger } from "@homarr/log";
+import { handshakeAsync } from "@homarr/redis";
+
+export async function GET() {
+ const timeBeforeHealthCheck = performance.now();
+ const response = await executeAndAggregateAllHealthChecksAsync();
+ logger.info(`Completed healthcheck after ${performance.now() - timeBeforeHealthCheck}ms`);
+
+ if (response.status === "healthy") {
+ return new Response(JSON.stringify(response), {
+ status: 200,
+ });
+ }
+
+ return new Response(JSON.stringify(response), {
+ status: 500,
+ });
+}
+
+const executeAndAggregateAllHealthChecksAsync = async (): Promise<{
+ healthChecks: Record<string, object>;
+ status: "healthy" | "unhealthy";
+}> => {
+ const healthChecks = [
+ executeHealthCheckSafelyAsync("database", async () => {
+ // sqlite driver does not support raw query execution. this is for a heartbeat check only - it doesn't matter if data is returned or not
+ await db.query.serverSettings.findFirst();
+ return {};
+ }),
+ executeHealthCheckSafelyAsync("redis", async () => {
+ await handshakeAsync();
+ return {};
+ }),
+ ];
+
+ const healthCheckResults = await Promise.all(healthChecks);
+ const anyUnhealthy = healthCheckResults.some((healthCheck) => healthCheck.status === "unhealthy");
+
+ const healthCheckValues = healthCheckResults.reduce(
+ (acc, healthCheck) => {
+ acc[healthCheck.name] = {
+ status: healthCheck.status,
+ ...healthCheck.values,
+ };
+ return acc;
+ },
+ {} as Record<string, object>,
+ );
+
+ return {
+ status: anyUnhealthy ? "unhealthy" : "healthy",
+ healthChecks: healthCheckValues,
+ };
+};
+
+const executeHealthCheckSafelyAsync = async (
+ name: string,
+ callback: () => Promise<object>,
+): Promise<HealthCheckResult> => {
+ try {
+ const currentTimeBeforeCallback = performance.now();
+ const values = await callback();
+ return {
+ name,
+ status: "healthy",
+ values: {
+ ...values,
+ latency: performance.now() - currentTimeBeforeCallback,
+ },
+ };
+ } catch (error) {
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
+ logger.error(`Healthcheck '${name}' has failed: ${error}`);
+ return {
+ status: "unhealthy",
+ values: {
+ error,
+ },
+ name,
+ };
+ }
+};
+
+interface HealthCheckResult {
+ status: "healthy" | "unhealthy";
+ name: string;
+ values: object;
+}
diff --git a/apps/nextjs/src/app/api/health/ready/route.ts b/apps/nextjs/src/app/api/health/ready/route.ts
new file mode 100644
index 000000000..40bcdf0c6
--- /dev/null
+++ b/apps/nextjs/src/app/api/health/ready/route.ts
@@ -0,0 +1,5 @@
+export function GET() {
+ return new Response(undefined, {
+ status: 200,
+ });
+}
diff --git a/packages/redis/src/index.ts b/packages/redis/src/index.ts
index 61c3e42b9..67373769e 100644
--- a/packages/redis/src/index.ts
+++ b/packages/redis/src/index.ts
@@ -1,6 +1,6 @@
import { createListChannel, createQueueChannel, createSubPubChannel } from "./lib/channel";
-export { createCacheChannel, createItemAndIntegrationChannel, createItemChannel } from "./lib/channel";
+export { createCacheChannel, createItemAndIntegrationChannel, createItemChannel, handshakeAsync } from "./lib/channel";
export const exampleChannel = createSubPubChannel<{ message: string }>("example");
export const pingChannel = createSubPubChannel<{ url: string; statusCode: number } | { url: string; error: string }>(
diff --git a/packages/redis/src/lib/channel.ts b/packages/redis/src/lib/channel.ts
index f707e20c0..698bafb7c 100644
--- a/packages/redis/src/lib/channel.ts
+++ b/packages/redis/src/lib/channel.ts
@@ -260,3 +260,7 @@ export const createQueueChannel = <TItem>(name: string) => {
},
};
};
+
+export const handshakeAsync = async () => {
+ await getSetClient.hello();
+};
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index add488c79..b18c4a83d 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -21,10 +21,10 @@ importers:
version: 2.1.2(@types/[email protected])([email protected])
'@vitejs/plugin-react':
specifier: ^4.3.1
'@vitest/coverage-v8':
specifier: ^2.1.1
'@vitest/ui':
specifier: ^2.1.1
version: 2.1.1([email protected])
@@ -48,10 +48,10 @@ importers:
version: 5.6.2
vite-tsconfig-paths:
specifier: ^5.0.1
vitest:
specifier: ^2.1.1
apps/nextjs:
dependencies:
@@ -100,6 +100,9 @@ importers:
'@homarr/old-schema':
specifier: workspace:^0.1.0
version: link:../../packages/old-schema
+ '@homarr/redis':
+ specifier: workspace:^0.1.0
+ version: link:../../packages/redis
'@homarr/server-settings':
specifier: workspace:^0.1.0
version: link:../../packages/server-settings
@@ -153,16 +156,16 @@ importers:
'@trpc/client':
specifier: next
- version: 11.0.0-rc.544(@trpc/[email protected])
+ version: 11.0.0-rc.552(@trpc/[email protected])
'@trpc/next':
specifier: next
'@trpc/react-query':
specifier: next
'@trpc/server':
specifier: next
- version: 11.0.0-rc.544
+ version: 11.0.0-rc.552
'@xterm/addon-canvas':
specifier: ^0.7.0
version: 0.7.0(@xterm/[email protected])
@@ -502,13 +505,13 @@ importers:
version: link:../validation
'@trpc/client':
specifier: next
- version: 11.0.0-rc.544(@trpc/[email protected])
+ version: 11.0.0-rc.552(@trpc/[email protected])
'@trpc/react-query':
specifier: next
'@trpc/server':
specifier: next
- version: 11.0.0-rc.544
+ version: 11.0.0-rc.552
dockerode:
specifier: ^4.0.2
version: 4.0.2
@@ -523,7 +526,7 @@ importers:
version: 2.2.1
trpc-swagger:
specifier: ^1.2.6
- version: 1.2.6(patch_hash=6s72z7zx33c52iesv5sewipn6i)(@trpc/[email protected](@trpc/[email protected]))(@trpc/[email protected])([email protected])
+ version: 1.2.6(patch_hash=6s72z7zx33c52iesv5sewipn6i)(@trpc/[email protected](@trpc/[email protected]))(@trpc/[email protected])([email protected])
devDependencies:
'@homarr/eslint-config':
specifier: workspace:^0.2.0
@@ -3215,18 +3218,18 @@ packages:
'@tootallnate/[email protected]':
resolution: {integrity: sha512-C5Mc6rdnsaJDjO3UpGW/CQTHtCKaYlScZTly4JIu97Jxo/odCiH0ITnDXSJPTOrEKk/ycSZ0AOgTmkDtkOsvIA==}
- resolution: {integrity: sha512-VympvY3/j597XUNEm8ywcH9Q78rC8f7qvLRpfU6u7Bjm7YgWLNaWlBYLpnOjhej0gXjFQjRLsnF1Ffek8KDtZg==}
+ resolution: {integrity: sha512-jFDclTMI4QLcLNMmEZdAXOZWTXlaSzfdOqhvj0FQLDu38T/Wt6F2EWUY51ALYv6WU0u7dIpH/yi1/XbULz4LUg==}
peerDependencies:
- '@trpc/server': 11.0.0-rc.544+f8e8d1715
+ '@trpc/server': 11.0.0-rc.552+268308497
- resolution: {integrity: sha512-hSneXAUgapL17RXyTdN9G5ZeN73B/bZ0j2XqduATfD/UgwvTaUuS4uYybgBy3RMLnaOnjr9lxcrYAf4ysiKxCg==}
+ resolution: {integrity: sha512-7JzIcXbUBDqqTNaI4wpz8vt1lOw+9vPo6cBZl8pyBBw+Jy64L2dRoLfBa2r3/RljDWBfPvV0kHNuZx8Ky8vshA==}
peerDependencies:
'@tanstack/react-query': ^5.54.1
- '@trpc/client': 11.0.0-rc.544+f8e8d1715
- '@trpc/react-query': 11.0.0-rc.544+f8e8d1715
- '@trpc/server': 11.0.0-rc.544+f8e8d1715
+ '@trpc/client': 11.0.0-rc.552+268308497
+ '@trpc/react-query': 11.0.0-rc.552+268308497
+ '@trpc/server': 11.0.0-rc.552+268308497
next: '*'
react: '>=16.8.0'
react-dom: '>=16.8.0'
@@ -3236,17 +3239,17 @@ packages:
'@trpc/react-query':
optional: true
- resolution: {integrity: sha512-lieAIbIdbwWsQcZuyUUzIGMB+ouMfkiPoK/H7N864eftiAmZgIuvtaarnO/7wTtLGsJoMOTzTJLE503UvEu0FA==}
+ resolution: {integrity: sha512-E2mV9kdAPcUlFKK0HHW5LuPthuobI+ooN7eg0+KJAI2nr+yzERcreF9kXQiOtXPFDDob8hS+2zJ/H/rGYz4lHA==}
peerDependencies:
'@tanstack/react-query': ^5.54.1
- '@trpc/client': 11.0.0-rc.544+f8e8d1715
- '@trpc/server': 11.0.0-rc.544+f8e8d1715
+ '@trpc/client': 11.0.0-rc.552+268308497
+ '@trpc/server': 11.0.0-rc.552+268308497
react: '>=18.2.0'
react-dom: '>=18.2.0'
- resolution: {integrity: sha512-Hv7w6PV9MQgD+TzX1LI1P1E2siweQaf4fS/xW+b6NCC15REgcYuWNPu69YFFpwcdkl3PuAkh+DL/0NPUpHdiHg==}
+ resolution: {integrity: sha512-3t8jOfs6EmZXQtwRD+FliAZW9WJmG1wC3SlFj/0hBMjwHqYtLttM/gmR1qKEeFmL5VdUhMojfaLQiGg5fxQEZw==}
'@tsconfig/[email protected]':
resolution: {integrity: sha512-DcRjDCujK/kCk/cUe8Xz8ZSpm8mS3mNNpta+jGCA6USEDfktlNvm1+IuZ9eTcDbNk41BHwpHHeW+N1lKCz4zOw==}
@@ -9394,30 +9397,30 @@ snapshots:
'@tootallnate/[email protected]': {}
dependencies:
- '@trpc/server': 11.0.0-rc.544
+ '@trpc/server': 11.0.0-rc.552
dependencies:
- '@trpc/client': 11.0.0-rc.544(@trpc/[email protected])
- '@trpc/server': 11.0.0-rc.544
+ '@trpc/client': 11.0.0-rc.552(@trpc/[email protected])
+ '@trpc/server': 11.0.0-rc.552
react: 18.3.1
react-dom: 18.3.1([email protected])
optionalDependencies:
'@tanstack/react-query': 5.56.2([email protected])
dependencies:
'@tanstack/react-query': 5.56.2([email protected])
- '@trpc/client': 11.0.0-rc.544(@trpc/[email protected])
- '@trpc/server': 11.0.0-rc.544
+ '@trpc/client': 11.0.0-rc.552(@trpc/[email protected])
+ '@trpc/server': 11.0.0-rc.552
react: 18.3.1
react-dom: 18.3.1([email protected])
- '@trpc/[email protected]': {}
+ '@trpc/[email protected]': {}
'@tsconfig/[email protected]': {}
@@ -9772,18 +9775,18 @@ snapshots:
global: 4.4.0
is-function: 1.0.2
dependencies:
'@babel/core': 7.25.2
'@babel/plugin-transform-react-jsx-self': 7.24.7(@babel/[email protected])
'@babel/plugin-transform-react-jsx-source': 7.24.7(@babel/[email protected])
'@types/babel__core': 7.20.5
react-refresh: 0.14.2
transitivePeerDependencies:
- supports-color
dependencies:
'@ampproject/remapping': 2.3.0
'@bcoe/v8-coverage': 0.2.3
@@ -9797,7 +9800,7 @@ snapshots:
std-env: 3.7.0
test-exclude: 7.0.1
tinyrainbow: 1.2.0
transitivePeerDependencies:
- supports-color
@@ -9808,13 +9811,13 @@ snapshots:
chai: 5.1.1
tinyrainbow: 1.2.0
dependencies:
'@vitest/spy': 2.1.1
estree-walker: 3.0.3
magic-string: 0.30.11
optionalDependencies:
'@vitest/[email protected]':
dependencies:
@@ -9844,7 +9847,7 @@ snapshots:
sirv: 2.0.4
tinyglobby: 0.2.6
tinyrainbow: 1.2.0
'@vitest/[email protected]':
dependencies:
@@ -13980,10 +13983,10 @@ snapshots:
- [email protected](patch_hash=6s72z7zx33c52iesv5sewipn6i)(@trpc/[email protected](@trpc/[email protected]))(@trpc/[email protected])([email protected]):
+ [email protected](patch_hash=6s72z7zx33c52iesv5sewipn6i)(@trpc/[email protected](@trpc/[email protected]))(@trpc/[email protected])([email protected]):
dependencies:
- '@trpc/client': 11.0.0-rc.544(@trpc/[email protected])
- '@trpc/server': 11.0.0-rc.544
+ '@trpc/client': 11.0.0-rc.552(@trpc/[email protected])
+ '@trpc/server': 11.0.0-rc.552
chalk-scripts: 1.2.8
co-body: 6.2.0
lodash.clonedeep: 4.5.0
@@ -14317,12 +14320,12 @@ snapshots:
dependencies:
global: 4.4.0
dependencies:
cac: 6.7.14
debug: 4.3.7
pathe: 1.1.2
transitivePeerDependencies:
- '@types/node'
- less
@@ -14334,18 +14337,18 @@ snapshots:
- supports-color
- terser
dependencies:
debug: 4.3.7
globrex: 0.1.2
tsconfck: 3.1.3([email protected])
optionalDependencies:
transitivePeerDependencies:
- supports-color
- typescript
dependencies:
esbuild: 0.21.5
postcss: 8.4.47
@@ -14357,10 +14360,10 @@ snapshots:
sugarss: 4.0.1([email protected])
terser: 5.32.0
dependencies:
'@vitest/expect': 2.1.1
'@vitest/pretty-format': 2.1.1
'@vitest/runner': 2.1.1
'@vitest/snapshot': 2.1.1
@@ -14375,8 +14378,8 @@ snapshots:
tinyexec: 0.3.0
tinypool: 1.0.1
tinyrainbow: 1.2.0
why-is-node-running: 2.3.0
optionalDependencies:
'@types/node': 20.16.10