fix: #9010, show rest of info even if clusterMonitor priv is not granted

v1.18.x
Barış Soner Uşaklı 4 years ago
parent d46740f860
commit 202dcef42e

@ -6,7 +6,6 @@ const databaseController = module.exports;
databaseController.get = async function (req, res) {
const results = {};
try {
if (nconf.get('redis')) {
const rdb = require('../../database/redis');
results.redis = await rdb.info(rdb.client);
@ -19,13 +18,6 @@ databaseController.get = async function (req, res) {
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;
}
}
res.render('admin/advanced/database', results);
};

@ -110,14 +110,29 @@ mongoModule.info = async function (db) {
db = 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([
db.command({ serverStatus: 1 }),
getServerStatus(),
db.command({ dbStats: 1 }),
getCollectionStats(db),
]);
stats = stats || {};
serverStatus = serverStatus || {};
stats.serverStatusError = serverStatusError;
const scale = 1024 * 1024 * 1024;
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.virtual = (stats.mem.virtual / 1024).toFixed(3);
stats.mem.mapped = (stats.mem.mapped / 1024).toFixed(3);
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.bytesOut = (stats.network.bytesOut / scale).toFixed(3);
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">
{{{ if mongo }}}
<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-heading"><i class="fa fa-hdd-o"></i> [[admin/advanced/database:mongo]]</div>
<div class="panel-body">

Loading…
Cancel
Save