From 482a5b900ea8f57977173123a76facb10047d304 Mon Sep 17 00:00:00 2001 From: Scrum4Me Agent <30029041+madhura68@users.noreply.github.com> Date: Sun, 3 May 2026 19:11:32 +0200 Subject: [PATCH] feat(health-server): /health checkt /var/cache vrije ruimte Voeg cacheBytesFree() toe via df -PB1 en retourneer 503 met { status: 'unhealthy', reason: 'cache-low' } als < 100 MB vrij. Bij voldoende ruimte wordt cache_free_bytes toegevoegd aan de 200-response. Co-Authored-By: Claude Sonnet 4.6 --- bin/health-server.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/bin/health-server.js b/bin/health-server.js index 6eb21ca..367043f 100644 --- a/bin/health-server.js +++ b/bin/health-server.js @@ -14,6 +14,7 @@ const http = require('node:http'); const fs = require('node:fs/promises'); const path = require('node:path'); +const { execSync } = require('node:child_process'); const STATE_DIR = process.env.AGENT_STATE_DIR || '/var/run/agent'; const PORT = Number(process.env.AGENT_HEALTH_PORT || 8080); @@ -25,6 +26,13 @@ const STATE_FILE = path.join(STATE_DIR, 'state.json'); const UNHEALTHY_MARKER = path.join(STATE_DIR, 'UNHEALTHY'); const TOKEN_EXPIRED_MARKER = path.join(STATE_DIR, 'TOKEN_EXPIRED'); +const CACHE_LOW_BYTES = 100 * 1024 * 1024; // 100 MB + +function cacheBytesFree() { + const out = execSync('df -PB1 /var/cache').toString().split('\n')[1]; + return parseInt(out.split(/\s+/)[3], 10); +} + async function exists(p) { try { await fs.access(p); @@ -59,6 +67,14 @@ async function buildResponse() { const heartbeatStale = heartbeatAgeS !== null && heartbeatAgeS > STALE_HEARTBEAT_SECONDS; + const cacheFreeBytes = cacheBytesFree(); + if (cacheFreeBytes < CACHE_LOW_BYTES) { + return { + httpStatus: 503, + body: { status: 'unhealthy', reason: 'cache-low' }, + }; + } + let httpStatus = 200; let effectiveStatus = state.status || 'unknown'; @@ -87,6 +103,7 @@ async function buildResponse() { tokenExpired, unhealthy, }, + cache_free_bytes: cacheFreeBytes, }; return { httpStatus, body };