feat: implement comprehensive health check endpoints for API, Auth, and Realtime services to monitor database, Redis, MinIO, and InfluxDB connectivity.
This commit is contained in:
@@ -12,8 +12,10 @@ const pool = new Pool({
|
||||
async function checkDB() {
|
||||
try {
|
||||
await pool.query('SELECT NOW()');
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('Database connection failed:', error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -65,6 +65,15 @@ async function getWatcherCount(sensorId) {
|
||||
return parseInt(count) || 0;
|
||||
}
|
||||
|
||||
async function checkRedis() {
|
||||
try {
|
||||
await redis.ping();
|
||||
return true;
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
setSession,
|
||||
getSession,
|
||||
@@ -74,6 +83,7 @@ module.exports = {
|
||||
addWatcher,
|
||||
removeWatcher,
|
||||
getWatcherCount,
|
||||
checkRedis,
|
||||
redis,
|
||||
redisSub
|
||||
};
|
||||
@@ -22,9 +22,14 @@ app.get('/', (req, res) => {
|
||||
res.redirect('/health');
|
||||
});
|
||||
|
||||
app.get('/health', (req, res) => {
|
||||
app.get('/health', async (req, res) => {
|
||||
const dbConnected = await require('./helper/authdb').checkDB();
|
||||
const redisConnected = await redisHelper.checkRedis();
|
||||
|
||||
res.status(200).send({
|
||||
status: 'OK',
|
||||
status: dbConnected && redisConnected ? 'OK' : 'DEGRADED',
|
||||
database: dbConnected ? 'connected' : 'disconnected',
|
||||
redis: redisConnected ? 'connected' : 'disconnected',
|
||||
service: 'realtime',
|
||||
version: process.env.VERSION,
|
||||
build: process.env.VERSION_BUILD,
|
||||
|
||||
Reference in New Issue
Block a user