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:
@@ -16,10 +16,19 @@ app.get('/', (req, res) => {
|
||||
res.redirect('/health');
|
||||
});
|
||||
|
||||
app.get('/health', (req, res) => {
|
||||
app.get('/health', async (req, res) => {
|
||||
const postgres = await require('./storage/postgres').checkPostgres();
|
||||
const influx = await require('./storage/influx').checkInflux();
|
||||
const minio = await require('./storage/minio').checkMinio();
|
||||
|
||||
const allOk = Object.values(postgres).every(s => s === 'connected') && influx && minio;
|
||||
|
||||
res.json({
|
||||
status: "ok",
|
||||
status: allOk ? "ok" : "degraded",
|
||||
service: "api",
|
||||
databases: postgres,
|
||||
influx: influx ? 'connected' : 'disconnected',
|
||||
minio: minio ? 'connected' : 'disconnected',
|
||||
version: version,
|
||||
build_number: vBuild,
|
||||
version_state: vState
|
||||
|
||||
@@ -59,9 +59,19 @@ async function query(bucket, relativeTime, measurement, sensor, field) {
|
||||
|
||||
}
|
||||
|
||||
async function checkInflux() {
|
||||
try {
|
||||
await querying.rows(`from(bucket: "boat") |> range(start: -1s) |> limit(n:1)`).next();
|
||||
return true;
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
write:append,
|
||||
writeBatch,
|
||||
query
|
||||
query,
|
||||
checkInflux
|
||||
}
|
||||
|
||||
|
||||
@@ -123,6 +123,15 @@ async function getFileStream(bucket, objectName) {
|
||||
return dataStream;
|
||||
}
|
||||
|
||||
async function checkMinio() {
|
||||
try {
|
||||
await client.listBuckets();
|
||||
return true;
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
bucketExists,
|
||||
getBuckets,
|
||||
@@ -132,5 +141,6 @@ module.exports = {
|
||||
removeObject,
|
||||
upload,
|
||||
download,
|
||||
getFileStream
|
||||
getFileStream,
|
||||
checkMinio
|
||||
}
|
||||
@@ -70,10 +70,24 @@ async function remove(table, condition, params, type = 'users') {
|
||||
const sql = `DELETE FROM ${table} WHERE ${condition}`;
|
||||
return await query(sql, params, type);
|
||||
}
|
||||
|
||||
async function checkPostgres() {
|
||||
const status = {};
|
||||
for (const [name, pool] of Object.entries(pools)) {
|
||||
try {
|
||||
await pool.query('SELECT NOW()');
|
||||
status[name] = 'connected';
|
||||
} catch (error) {
|
||||
status[name] = 'disconnected';
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}
|
||||
module.exports = {
|
||||
query,
|
||||
append,
|
||||
remove,
|
||||
getClient,
|
||||
checkPostgres,
|
||||
pools
|
||||
};
|
||||
Reference in New Issue
Block a user