Some more stats

This commit is contained in:
Bryan Ashby 2020-11-09 21:32:34 -07:00
parent 52ae983cb4
commit d6cc53c263
No known key found for this signature in database
GPG Key ID: B49EB437951D2542
6 changed files with 61 additions and 6 deletions

View File

@ -689,4 +689,20 @@ exports.MenuModule = class MenuModule extends PluginModule {
return cb(good ? null : Errors.Invalid(`Invalid or missing config option "${firstBadKey}" (${badReason})`));
}
// Various common helpers
getDateFormat(defaultStyle='short') {
return this.config.dateFormat ||
this.client.currentTheme.helpers.getDateFormat(defaultStyle);
}
getTimeFormat(defaultStyle='short') {
return this.config.timeFormat ||
this.client.currentTheme.helpers.getTimeFormat(defaultStyle);
}
getDateTimeFormat(defaultStyle='short') {
return this.config.dateTimeFormat ||
this.client.currentTheme.helpers.getDateTimeFormat(defaultStyle);
}
};

View File

@ -267,6 +267,7 @@ const PREDEFINED_MCI_GENERATORS = {
// :TODO: DD - Files downloaded *today* (iNiQUiTY)
// :TODO: LC - name of last caller to system (Obv/2)
// :TODO: TZ - Average *system* post/call ratio (iNiQUiTY)
// :TODO: ?? - Total users on system
//

View File

@ -337,7 +337,7 @@ function formatByteSizeAbbr(byteSize) {
function formatByteSize(byteSize, withAbbr = false, decimals = 2) {
const i = 0 === byteSize ? byteSize : Math.floor(Math.log(byteSize) / Math.log(1024));
let result = parseFloat((byteSize / Math.pow(1024, i)).toFixed(decimals));
let result = parseFloat((byteSize / Math.pow(1024, i)).toFixed(decimals)).toString();
if(withAbbr) {
result += ` ${BYTE_SIZE_ABBRS[i]}`;
}

View File

@ -11,6 +11,8 @@ const {
// deps
const async = require('async');
const _ = require('lodash');
const moment = require('moment');
const SysInfo = require('systeminformation');
exports.moduleInfo = {
name : 'WFC',
@ -63,6 +65,9 @@ exports.getModule = class WaitingForCallerModule extends MenuModule {
// return this.validateMCIByViewIds('main', requiredCodes, callback);
return callback(null);
},
(callback) => {
return this._refreshStats(callback);
},
(callback) => {
return this._refreshNodeStatus(callback);
}
@ -79,7 +84,16 @@ exports.getModule = class WaitingForCallerModule extends MenuModule {
const totalFiles = fileAreaStats.totalFiles || 0;
const totalFileBytes = fileAreaStats.totalBytes || 0;
// Some stats we can just fill right away
this.stats = {
// Date/Time
date : moment().format(this.getDateFormat()),
time : moment().format(this.getTimeFormat()),
dateTime : moment().format(this.getDateTimeFormat()),
// Current process (our Node.js service)
processUptime : moment.duration(process.uptime(), 'seconds').humanize(),
// Totals
totalCalls : StatLog.getFriendlySystemStat(SysProps.LoginCount, 0),
totalPosts : StatLog.getFriendlySystemStat(SysProps.MessageTotalCount, 0),
@ -87,18 +101,36 @@ exports.getModule = class WaitingForCallerModule extends MenuModule {
totalFiles : totalFiles.toLocaleString(),
totalFileBytes : formatByteSize(totalFileBytes, false),
totalFileBytesAbbr : formatByteSizeAbbr(totalFileBytes),
// :TODO: date, time - formatted as per config.dateTimeFormat and such
// :TODO: Most/All current user status should be predefined MCI
// :TODO: lastCaller
// :TODO: totalMemoryBytes, freeMemoryBytes
// :TODO: CPU info/averages/load
// :TODO: processUptime
// :TODO: 24 HOUR stats -
// calls24Hour, posts24Hour, uploadBytes24Hour, downloadBytes24Hour, ...
// :TODO: totals - most avail from MCI
// callsToday, postsToday, uploadsToday, uploadBytesToday, ...
};
return cb(null);
// Some async work required...
const basicSysInfo = {
mem : 'total, free',
currentLoad : 'avgload, currentLoad',
};
SysInfo.get(basicSysInfo)
.then(sysInfo => {
this.stats.totalMemoryBytes = formatByteSize(sysInfo.mem.total, false);
this.stats.totalMemoryBytesAbbr = formatByteSizeAbbr(sysInfo.mem.total);
this.stats.freeMemoryBytes = formatByteSize(sysInfo.mem.free, false);
this.stats.freeMemoryBytesAbbr = formatByteSizeAbbr(sysInfo.mem.free);
// Not avail on BSD, yet.
this.stats.systemAvgLoad = _.get(sysInfo, 'currentLoad.avgload', 0).toString();
this.stats.systemCurrentLoad = _.get(sysInfo, 'currentLoad.currentLoad', 0).toString();
})
.catch(err => {
return cb(err);
});
}
_refreshNodeStatus(cb) {

View File

@ -59,7 +59,8 @@
"uuid-parse": "1.1.0",
"ws": "^7.3.0",
"xxhash": "^0.3.0",
"yazl": "^2.5.1"
"yazl": "^2.5.1",
"systeminformation" : "^4.27.5"
},
"devDependencies": {
"eslint": "^7.2.0"

View File

@ -2306,6 +2306,11 @@ supports-color@^7.1.0:
dependencies:
has-flag "^4.0.0"
systeminformation@^4.27.5:
version "4.29.3"
resolved "https://registry.yarnpkg.com/systeminformation/-/systeminformation-4.29.3.tgz#6dac4ff96479f1dd5df50582a965afb4c76178f2"
integrity sha512-C5+o6hit4BQpFdZKxXwRqgDpAkXCjxAUi5pB3UznjYPl3XQugwo1V46XltUt+53EaphlHA6j41mh++ksdOuBMA==
table@^5.2.3:
version "5.4.6"
resolved "https://registry.yarnpkg.com/table/-/table-5.4.6.tgz#1292d19500ce3f86053b05f0e8e7e4a3bb21079e"