Created
April 13, 2023 17:54
-
-
Save kumarasinghe/49fa5586a6c585592b9f9c1e916b3fbc to your computer and use it in GitHub Desktop.
Node.js health check route
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
import os from "os"; | |
import process from "process"; | |
/* GET /api/health */ | |
const stats = { | |
status: "OK", | |
system: { | |
hostname: os.hostname(), | |
free_memory_mb: Math.floor(os.freemem() / 1000000), | |
load_avg: os.loadavg(), | |
cpu_cores: os.cpus().length, | |
uptime_s: Math.round(os.uptime()), | |
}, | |
process: { | |
memory_usage_mb: Math.floor(process.memoryUsage().rss / 1000000), | |
uptime_s: Math.round(process.uptime()), | |
}, | |
}; | |
res.json(stats); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment