From d6cc53c263155fce133095576c7632ac4f2c0ed0 Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Mon, 9 Nov 2020 21:32:34 -0700 Subject: [PATCH] Some more stats --- core/menu_module.js | 16 ++++++++++++++++ core/predefined_mci.js | 1 + core/string_util.js | 2 +- core/wfc.js | 40 ++++++++++++++++++++++++++++++++++++---- package.json | 3 ++- yarn.lock | 5 +++++ 6 files changed, 61 insertions(+), 6 deletions(-) diff --git a/core/menu_module.js b/core/menu_module.js index 804065a7..8d325378 100644 --- a/core/menu_module.js +++ b/core/menu_module.js @@ -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); + } }; diff --git a/core/predefined_mci.js b/core/predefined_mci.js index a1182a79..a63ad45c 100644 --- a/core/predefined_mci.js +++ b/core/predefined_mci.js @@ -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 // diff --git a/core/string_util.js b/core/string_util.js index 6887275e..6b88ec40 100644 --- a/core/string_util.js +++ b/core/string_util.js @@ -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]}`; } diff --git a/core/wfc.js b/core/wfc.js index 6bc066cd..e9067335 100644 --- a/core/wfc.js +++ b/core/wfc.js @@ -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) { diff --git a/package.json b/package.json index 038cce91..cc869b1f 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/yarn.lock b/yarn.lock index 85cd031a..85f4982c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"