From 58c577c4bb15929ebb7baf93bd68c646c08d8b8b Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Sun, 22 Nov 2020 12:25:19 -0700 Subject: [PATCH] Checkpoint --- core/predefined_mci.js | 29 +++++++++++++-------- core/stat_log_system.js | 28 ++++++++++++++++++++ core/system_property.js | 8 ++++++ core/wfc.js | 57 +++++++++++++++++++++++------------------ 4 files changed, 87 insertions(+), 35 deletions(-) create mode 100644 core/stat_log_system.js diff --git a/core/predefined_mci.js b/core/predefined_mci.js index a63ad45c..222b8cc3 100644 --- a/core/predefined_mci.js +++ b/core/predefined_mci.js @@ -24,12 +24,22 @@ const packageJson = require('../package.json'); const os = require('os'); const _ = require('lodash'); const moment = require('moment'); +const async = require('async'); exports.getPredefinedMCIValue = getPredefinedMCIValue; exports.init = init; function init(cb) { - setNextRandomRumor(cb); + async.series( + [ + (callback) => { + return setNextRandomRumor(callback); + }, + ], + err => { + return cb(err); + } + ); } function setNextRandomRumor(cb) { @@ -65,10 +75,6 @@ function userStatAsCountString(client, statName, defaultValue) { return toNumberWithCommas(value); } -function sysStatAsString(statName, defaultValue) { - return (StatLog.getSystemStat(statName) || defaultValue).toLocaleString(); -} - const PREDEFINED_MCI_GENERATORS = { // // Board @@ -212,11 +218,14 @@ const PREDEFINED_MCI_GENERATORS = { .trim(); }, + // :TODO: use new live stat + MB : function totalMemoryBytes() { return getTotalMemoryBytes(); }, + MF : function totalMemoryFreeBytes() { return getTotalMemoryFreeBytes(); }, + // :TODO: MCI for core count, e.g. os.cpus().length // :TODO: cpu load average (over N seconds): http://stackoverflow.com/questions/9565912/convert-the-output-of-os-cpus-in-node-js-to-percentage NV : function nodeVersion() { return process.version; }, - AN : function activeNodes() { return clientConnections.getActiveConnections().length.toString(); }, TC : function totalCalls() { return StatLog.getSystemStat(SysProps.LoginCount).toLocaleString(); }, @@ -236,12 +245,12 @@ const PREDEFINED_MCI_GENERATORS = { // // :TODO: DD - Today's # of downloads (iNiQUiTY) // - SD : function systemNumDownloads() { return sysStatAsString(SysProps.FileDlTotalCount, 0); }, + SD : function systemNumDownloads() { return StatLog.getFriendlySystemStat(SysProps.FileDlTotalCount, 0); }, SO : function systemByteDownload() { const byteSize = StatLog.getSystemStatNum(SysProps.FileDlTotalBytes); return formatByteSize(byteSize, true); // true=withAbbr }, - SU : function systemNumUploads() { return sysStatAsString(SysProps.FileUlTotalCount, 0); }, + SU : function systemNumUploads() { return StatLog.getFriendlySystemStat(SysProps.FileUlTotalCount, 0); }, SP : function systemByteUpload() { const byteSize = StatLog.getSystemStatNum(SysProps.FileUlTotalBytes); return formatByteSize(byteSize, true); // true=withAbbr @@ -256,10 +265,10 @@ const PREDEFINED_MCI_GENERATORS = { return formatByteSize(totalBytes, true); // true=withAbbr }, PT : function messagesPostedToday() { // Obv/2 - return sysStatAsString(SysProps.MessagesToday, 0); + return StatLog.getFriendlySystemStat(SysProps.MessagesToday, 0); }, TP : function totalMessagesOnSystem() { // Obv/2 - return sysStatAsString(SysProps.MessageTotalCount, 0); + return StatLog.getFriendlySystemStat(SysProps.MessageTotalCount, 0); }, // :TODO: NT - New users today (Obv/2) diff --git a/core/stat_log_system.js b/core/stat_log_system.js new file mode 100644 index 00000000..f027c455 --- /dev/null +++ b/core/stat_log_system.js @@ -0,0 +1,28 @@ + +// deps +const SysInfo = require('systeminformation'); +const _ = require('lodash'); + +exports.getSystemInfoStats = getSystemInfoStats; + +function getSystemInfoStats(cb) { + const basicSysInfo = { + mem : 'total, free', + currentLoad : 'avgload, currentLoad', + }; + + SysInfo.get(basicSysInfo) + .then(sysInfo => { + return cb(null, { + totalMemoryBytes : sysInfo.mem.total, + freeMemoryBytes : sysInfo.mem.free, + + // Not avail on BSD, yet. + systemAvgLoad : _.get(sysInfo, 'currentLoad.avgload', 0), + systemCurrentLoad : _.get(sysInfo, 'currentLoad.currentLoad', 0), + }); + }) + .catch(err => { + return cb(err); + }); +} diff --git a/core/system_property.js b/core/system_property.js index ca3cf7cd..a74a57d8 100644 --- a/core/system_property.js +++ b/core/system_property.js @@ -30,4 +30,12 @@ module.exports = { // end +op non-persistent NextRandomRumor : 'random_rumor', + + // begin system stat non-persistent... + TotalMemoryBytes : 'sys_total_memory_bytes', + FreeMemoryBytes : 'sys_free_memory_bytes', + AverageLoad : 'sys_average_load', + CurrentLoad : 'sys_current_load', + + // end system stat non persistent }; diff --git a/core/wfc.js b/core/wfc.js index e9067335..53fea670 100644 --- a/core/wfc.js +++ b/core/wfc.js @@ -4,9 +4,6 @@ const { MenuModule } = require('./menu_module'); const { getActiveConnectionList } = require('./client_connections'); const StatLog = require('./stat_log'); const SysProps = require('./system_property'); -const { - formatByteSize, formatByteSizeAbbr, -} = require('./string_util'); // deps const async = require('async'); @@ -80,35 +77,47 @@ exports.getModule = class WaitingForCallerModule extends MenuModule { } _refreshStats(cb) { - const fileAreaStats = StatLog.getSystemStat(SysProps.FileBaseAreaStats); - const totalFiles = fileAreaStats.totalFiles || 0; - const totalFileBytes = fileAreaStats.totalBytes || 0; + const fileAreaStats = StatLog.getSystemStat(SysProps.FileBaseAreaStats); // 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()), + 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(), + processUptimeSeconds : process.uptime(), +// processUptime : moment.duration(process.uptime(), 'seconds').humanize(), // Totals - totalCalls : StatLog.getFriendlySystemStat(SysProps.LoginCount, 0), - totalPosts : StatLog.getFriendlySystemStat(SysProps.MessageTotalCount, 0), + totalCalls : StatLog.getSystemStatNum(SysProps.LoginCount), + totalPosts : StatLog.getSystemStatNum(SysProps.MessageTotalCount), //totalUsers : - totalFiles : totalFiles.toLocaleString(), - totalFileBytes : formatByteSize(totalFileBytes, false), - totalFileBytesAbbr : formatByteSizeAbbr(totalFileBytes), - // :TODO: Most/All current user status should be predefined MCI + totalFiles : fileAreaStats.totalFiles || 0, + totalFileBytes : fileAreaStats.totalFileBytes || 0, + + // totalUploads : + // totalUploadBytes : + // totalDownloads : + // totalDownloadBytes : + // :TODO: lastCaller // :TODO: totalMemoryBytes, freeMemoryBytes // :TODO: CPU info/averages/load - // :TODO: processUptime - // :TODO: 24 HOUR stats - - // callsToday, postsToday, uploadsToday, uploadBytesToday, ... + // Today's Stats + callsToday : StatLog.getSystemStatNum(SysProps.LoginsToday), + postsToday : StatLog.getSystemStatNum(SysProps.MessagesToday), + // uploadsToday : + // uploadBytesToday : + // downloadsToday : + // downloadBytesToday : + + // Current + // lastCaller : + // lastCallerDate + // lastCallerTime }; // Some async work required... @@ -119,14 +128,12 @@ exports.getModule = class WaitingForCallerModule extends MenuModule { 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); + this.stats.totalMemoryBytes = sysInfo.mem.total; + this.stats.freeMemoryBytes = 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(); + this.stats.systemAvgLoad = _.get(sysInfo, 'currentLoad.avgload', 0); + this.stats.systemCurrentLoad = _.get(sysInfo, 'currentLoad.currentLoad', 0); }) .catch(err => { return cb(err);