Add RAM and disk stats to health-status endpoint via SSH
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
90c2e69d51
commit
66355bd698
1 changed files with 20 additions and 5 deletions
|
|
@ -207,12 +207,27 @@ app.get('/health-status', async () => {
|
||||||
return Promise.all(
|
return Promise.all(
|
||||||
Object.entries(healthMap).map(async ([name, { host, port }]) => {
|
Object.entries(healthMap).map(async ([name, { host, port }]) => {
|
||||||
const t0 = Date.now()
|
const t0 = Date.now()
|
||||||
try {
|
const [httpResult, freeOut, dfOut] = await Promise.all([
|
||||||
await fetch(`http://${host}:${port}/health`, { signal: AbortSignal.timeout(3000) })
|
fetch(`http://${host}:${port}/health`, { signal: AbortSignal.timeout(3000) })
|
||||||
return { name, up: true, ms: Date.now() - t0 }
|
.then(() => ({ up: true, ms: Date.now() - t0 }))
|
||||||
} catch {
|
.catch(() => ({ up: false, ms: null })),
|
||||||
return { name, up: false, ms: null }
|
sshGet(host, ['free', '-b']),
|
||||||
|
sshGet(host, ['df', '-k', '/']),
|
||||||
|
])
|
||||||
|
|
||||||
|
let ram = null
|
||||||
|
if (freeOut) {
|
||||||
|
const m = freeOut.match(/^Mem:\s+(\d+)\s+(\d+)/m)
|
||||||
|
if (m) ram = { total: +m[1], used: +m[2] }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let disk = null
|
||||||
|
if (dfOut) {
|
||||||
|
const row = dfOut.trim().split('\n').pop().split(/\s+/)
|
||||||
|
if (row.length >= 3) disk = { total: +row[1] * 1024, used: +row[2] * 1024 }
|
||||||
|
}
|
||||||
|
|
||||||
|
return { name, ...httpResult, ram, disk }
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue