mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-19 14:16:01 +00:00
SYNC: health status
This commit is contained in:
committed by
Diflow
parent
d5f8e01dd8
commit
3bb4652a49
@@ -43,6 +43,7 @@ function authMiddleware(req, res, next) {
|
||||
'/connections/dblogin-app',
|
||||
'/connections/dblogin-auth',
|
||||
'/connections/dblogin-auth-token',
|
||||
'/health',
|
||||
];
|
||||
|
||||
// console.log('********************* getAuthProvider()', getAuthProvider());
|
||||
|
||||
@@ -171,6 +171,7 @@ module.exports = {
|
||||
this.rejectRequest(runid, { message: 'No data returned, maybe input data source is too big' });
|
||||
logger.info({ code, pid: subprocess.pid }, 'Exited process');
|
||||
socket.emit(`runner-done-${runid}`, code);
|
||||
this.opened = this.opened.filter(x => x.runid != runid);
|
||||
});
|
||||
subprocess.on('error', error => {
|
||||
// console.log('... ERROR subprocess', error);
|
||||
@@ -180,6 +181,7 @@ module.exports = {
|
||||
severity: 'error',
|
||||
message: error.toString(),
|
||||
});
|
||||
this.opened = this.opened.filter(x => x.runid != runid);
|
||||
});
|
||||
const newOpened = {
|
||||
runid,
|
||||
@@ -224,6 +226,7 @@ module.exports = {
|
||||
if (onFinished) {
|
||||
onFinished();
|
||||
}
|
||||
this.opened = this.opened.filter(x => x.runid != runid);
|
||||
});
|
||||
subprocess.on('spawn', () => {
|
||||
this.dispatchMessage(runid, `Started external process ${command}`);
|
||||
@@ -241,6 +244,7 @@ module.exports = {
|
||||
});
|
||||
}
|
||||
socket.emit(`runner-done-${runid}`);
|
||||
this.opened = this.opened.filter(x => x.runid != runid);
|
||||
});
|
||||
|
||||
if (stdinFilePath) {
|
||||
|
||||
@@ -127,6 +127,9 @@ module.exports = {
|
||||
this.dispatchMessage(sesid, 'Query session closed');
|
||||
socket.emit(`session-closed-${sesid}`);
|
||||
});
|
||||
subprocess.on('error', () => {
|
||||
this.opened = this.opened.filter(x => x.sesid != sesid);
|
||||
});
|
||||
|
||||
subprocess.send({
|
||||
msgtype: 'connect',
|
||||
|
||||
@@ -38,6 +38,7 @@ const { getLogger } = require('dbgate-tools');
|
||||
const { getDefaultAuthProvider } = require('./auth/authProvider');
|
||||
const startCloudUpgradeTimer = require('./utility/cloudUpgrade');
|
||||
const { isProApp } = require('./utility/checkLicense');
|
||||
const getHealthStatus = require('./utility/healthStatus');
|
||||
|
||||
const logger = getLogger('main');
|
||||
|
||||
@@ -117,6 +118,12 @@ function start() {
|
||||
});
|
||||
});
|
||||
|
||||
app.get(getExpressPath('/health'), async function (req, res) {
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
const health = await getHealthStatus();
|
||||
res.end(JSON.stringify(health, null, 2));
|
||||
});
|
||||
|
||||
app.use(bodyParser.json({ limit: '50mb' }));
|
||||
|
||||
app.use(
|
||||
|
||||
25
packages/api/src/utility/healthStatus.js
Normal file
25
packages/api/src/utility/healthStatus.js
Normal file
@@ -0,0 +1,25 @@
|
||||
const os = require('os');
|
||||
|
||||
const databaseConnections = require('../controllers/databaseConnections');
|
||||
const serverConnections = require('../controllers/serverConnections');
|
||||
const sessions = require('../controllers/sessions');
|
||||
const runners = require('../controllers/runners');
|
||||
|
||||
async function getHealthStatus() {
|
||||
const memory = process.memoryUsage();
|
||||
|
||||
return {
|
||||
status: 'ok',
|
||||
databaseConnectionCount: databaseConnections.opened.length,
|
||||
serverConnectionCount: serverConnections.opened.length,
|
||||
sessionCount: sessions.opened.length,
|
||||
memory,
|
||||
systemMemory: {
|
||||
total: os.totalmem(),
|
||||
free: os.freemem(),
|
||||
},
|
||||
runProcessCount: runners.opened.length,
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = getHealthStatus;
|
||||
Reference in New Issue
Block a user