mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
fix: #9010, show rest of info even if clusterMonitor priv is not granted
This commit is contained in:
@@ -6,26 +6,18 @@ const databaseController = module.exports;
|
|||||||
|
|
||||||
databaseController.get = async function (req, res) {
|
databaseController.get = async function (req, res) {
|
||||||
const results = {};
|
const results = {};
|
||||||
try {
|
if (nconf.get('redis')) {
|
||||||
if (nconf.get('redis')) {
|
const rdb = require('../../database/redis');
|
||||||
const rdb = require('../../database/redis');
|
results.redis = await rdb.info(rdb.client);
|
||||||
results.redis = await rdb.info(rdb.client);
|
|
||||||
}
|
|
||||||
if (nconf.get('mongo')) {
|
|
||||||
const mdb = require('../../database/mongo');
|
|
||||||
results.mongo = await mdb.info(mdb.client);
|
|
||||||
}
|
|
||||||
if (nconf.get('postgres')) {
|
|
||||||
const pdb = require('../../database/postgres');
|
|
||||||
results.postgres = await pdb.info(pdb.pool);
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
Object.assign(results, { error: err });
|
|
||||||
// Override mongo error with more human-readable error
|
|
||||||
if (err.name === 'MongoError' && err.codeName === 'Unauthorized') {
|
|
||||||
err.friendlyMessage = '[[admin/advanced/database:mongo.unauthorized]]';
|
|
||||||
delete results.mongo;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if (nconf.get('mongo')) {
|
||||||
|
const mdb = require('../../database/mongo');
|
||||||
|
results.mongo = await mdb.info(mdb.client);
|
||||||
|
}
|
||||||
|
if (nconf.get('postgres')) {
|
||||||
|
const pdb = require('../../database/postgres');
|
||||||
|
results.postgres = await pdb.info(pdb.pool);
|
||||||
|
}
|
||||||
|
|
||||||
res.render('admin/advanced/database', results);
|
res.render('admin/advanced/database', results);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -110,14 +110,29 @@ mongoModule.info = async function (db) {
|
|||||||
db = client.db();
|
db = client.db();
|
||||||
}
|
}
|
||||||
mongoModule.client = mongoModule.client || db;
|
mongoModule.client = mongoModule.client || db;
|
||||||
|
let serverStatusError = '';
|
||||||
|
|
||||||
|
async function getServerStatus() {
|
||||||
|
try {
|
||||||
|
return await db.command({ serverStatus: 1 });
|
||||||
|
} catch (err) {
|
||||||
|
serverStatusError = err.message;
|
||||||
|
// Override mongo error with more human-readable error
|
||||||
|
if (err.name === 'MongoError' && err.codeName === 'Unauthorized') {
|
||||||
|
serverStatusError = '[[admin/advanced/database:mongo.unauthorized]]';
|
||||||
|
}
|
||||||
|
winston.error(err.stack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let [serverStatus, stats, listCollections] = await Promise.all([
|
let [serverStatus, stats, listCollections] = await Promise.all([
|
||||||
db.command({ serverStatus: 1 }),
|
getServerStatus(),
|
||||||
db.command({ dbStats: 1 }),
|
db.command({ dbStats: 1 }),
|
||||||
getCollectionStats(db),
|
getCollectionStats(db),
|
||||||
]);
|
]);
|
||||||
stats = stats || {};
|
stats = stats || {};
|
||||||
serverStatus = serverStatus || {};
|
serverStatus = serverStatus || {};
|
||||||
|
stats.serverStatusError = serverStatusError;
|
||||||
const scale = 1024 * 1024 * 1024;
|
const scale = 1024 * 1024 * 1024;
|
||||||
|
|
||||||
listCollections = listCollections.map(function (collectionInfo) {
|
listCollections = listCollections.map(function (collectionInfo) {
|
||||||
@@ -132,12 +147,12 @@ mongoModule.info = async function (db) {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
stats.mem = serverStatus.mem || {};
|
stats.mem = serverStatus.mem || { resident: 0, virtual: 0, mapped: 0 };
|
||||||
stats.mem.resident = (stats.mem.resident / 1024).toFixed(3);
|
stats.mem.resident = (stats.mem.resident / 1024).toFixed(3);
|
||||||
stats.mem.virtual = (stats.mem.virtual / 1024).toFixed(3);
|
stats.mem.virtual = (stats.mem.virtual / 1024).toFixed(3);
|
||||||
stats.mem.mapped = (stats.mem.mapped / 1024).toFixed(3);
|
stats.mem.mapped = (stats.mem.mapped / 1024).toFixed(3);
|
||||||
stats.collectionData = listCollections;
|
stats.collectionData = listCollections;
|
||||||
stats.network = serverStatus.network || {};
|
stats.network = serverStatus.network || { bytesIn: 0, bytesOut: 0, numRequests: 0 };
|
||||||
stats.network.bytesIn = (stats.network.bytesIn / scale).toFixed(3);
|
stats.network.bytesIn = (stats.network.bytesIn / scale).toFixed(3);
|
||||||
stats.network.bytesOut = (stats.network.bytesOut / scale).toFixed(3);
|
stats.network.bytesOut = (stats.network.bytesOut / scale).toFixed(3);
|
||||||
stats.network.numRequests = utils.addCommas(stats.network.numRequests);
|
stats.network.numRequests = utils.addCommas(stats.network.numRequests);
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
<!-- IF error -->
|
|
||||||
<div class="alert alert-warning">
|
|
||||||
{error.friendlyMessage}
|
|
||||||
<hr />
|
|
||||||
<code>{error.errmsg}</code>
|
|
||||||
</div>
|
|
||||||
<!-- END -->
|
|
||||||
<div class="row database">
|
<div class="row database">
|
||||||
{{{ if mongo }}}
|
{{{ if mongo }}}
|
||||||
<div class="col-lg-6">
|
<div class="col-lg-6">
|
||||||
|
{{{ if mongo.serverStatusError }}}
|
||||||
|
<div class="alert alert-warning">
|
||||||
|
{mongo.serverStatusError}
|
||||||
|
</div>
|
||||||
|
{{{ end }}}
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
<div class="panel-heading"><i class="fa fa-hdd-o"></i> [[admin/advanced/database:mongo]]</div>
|
<div class="panel-heading"><i class="fa fa-hdd-o"></i> [[admin/advanced/database:mongo]]</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
|
|||||||
Reference in New Issue
Block a user