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