From 715202680e6fbe1a7b3bfb7946f5d341becc63c3 Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Mon, 1 Aug 2022 23:09:18 -0600 Subject: [PATCH] Add Process/enig start ingress/egress bytes stats --- art/themes/luciano_blocktronics/theme.hjson | 2 ++ art/themes/luciano_blocktronics/wfc.ans | Bin 3055 -> 3092 bytes core/client_connections.js | 9 +++++++++ core/login_server_module.js | 1 + core/predefined_mci.js | 13 +++++++++++++ core/stat_log.js | 17 +++++++++++++++++ core/system_property.js | 1 + core/wfc.js | 4 ++++ docs/_docs/art/mci.md | 2 ++ docs/_docs/modding/wfc.md | 2 ++ 10 files changed, 51 insertions(+) diff --git a/art/themes/luciano_blocktronics/theme.hjson b/art/themes/luciano_blocktronics/theme.hjson index fc3a7682..ff93609a 100644 --- a/art/themes/luciano_blocktronics/theme.hjson +++ b/art/themes/luciano_blocktronics/theme.hjson @@ -276,6 +276,8 @@ mainInfoFormat21: "|00|10{totalPosts:>7}" mainInfoFormat22: "|00|10{totalUsers:>5}" mainInfoFormat23: "|00|10{totalFiles:>4} |08/ |10{totalFileBytes!sizeWithoutAbbr:>4} |02{totalFileBytes!sizeAbbr}" + mainInfoFormat24: "|00|10{processBytesIngress!sizeWithoutAbbr:>5} |02{processBytesIngress!sizeAbbr}" + mainInfoFormat25: "|00|10{processBytesEgress!sizeWithoutAbbr:>5} |02{processBytesEgress!sizeAbbr}" quickLogLevel: info quickLogLevelIndicators: { diff --git a/art/themes/luciano_blocktronics/wfc.ans b/art/themes/luciano_blocktronics/wfc.ans index 3588cabf411e39dc50d934db3fbbb89df4f3a316..ecb0eedd5ec20dacb212af45020fe5836dfa4eda 100644 GIT binary patch delta 91 zcmaDaK1E`~1m?+d9PDDAdFe%|#l;HJ(T2IIAwEVX($U5Sxs&HIXD9(#M!BhAX&}=) kR{^BR8Yl)*XDS^HRQ8csc(W?YLUtAl1H;vmPjRaP0RChfO#lD@ delta 33 pcmbOt@m_qx1m?+3j3SfMxvVD3v-)lhV42O%Vs2>OHu*ibDgeFc3Z?)6 diff --git a/core/client_connections.js b/core/client_connections.js index ce39fe1c..e4a75520 100644 --- a/core/client_connections.js +++ b/core/client_connections.js @@ -122,6 +122,15 @@ function addNewClient(client, clientSock) { moment().valueOf(), ]); + // kludge to refresh process update stats at first client + if (clientConnections.length < 1) { + setTimeout(() => { + const StatLog = require('./stat_log'); + const SysProps = require('./system_property'); + StatLog.getSystemStat(SysProps.ProcessTrafficStats); + }, 3000); // slight pause to wait for updates + } + clientConnections.push(client); clientConnections.sort((c1, c2) => c1.session.id - c2.session.id); diff --git a/core/login_server_module.js b/core/login_server_module.js index 95eaebae..5f74801f 100644 --- a/core/login_server_module.js +++ b/core/login_server_module.js @@ -52,6 +52,7 @@ module.exports = class LoginServerModule extends ServerModule { client.session = {}; } + client.rawSocket = clientSock; client.session.serverName = modInfo.name; client.session.isSecure = _.isBoolean(client.isSecure) ? client.isSecure diff --git a/core/predefined_mci.js b/core/predefined_mci.js index 8461d283..7463186f 100644 --- a/core/predefined_mci.js +++ b/core/predefined_mci.js @@ -385,6 +385,19 @@ const PREDEFINED_MCI_GENERATORS = { return StatLog.getSystemStat(SysProps.LoginsToday).toLocaleString(); }, + PI: function processBytesIngress() { + const stats = StatLog.getSystemStat(SysProps.ProcessTrafficStats) || { + ingress: 0, + }; + return stats.ingress.toLocaleString(); + }, + PE: function processBytesEgress() { + const stats = StatLog.getSystemStat(SysProps.ProcessTrafficStats) || { + egress: 0, + }; + return stats.ingress.toLocaleString(); + }, + RR: function randomRumor() { // start the process of picking another random one setNextRandomRumor(); diff --git a/core/stat_log.js b/core/stat_log.js index 8c80fc6c..f2d57bd0 100644 --- a/core/stat_log.js +++ b/core/stat_log.js @@ -7,6 +7,7 @@ const Errors = require('./enig_error.js'); const SysProps = require('./system_property.js'); const UserProps = require('./user_property'); const Message = require('./message'); +const { getActiveConnections, AllConnections } = require('./client_connections'); // deps const _ = require('lodash'); @@ -360,6 +361,9 @@ class StatLog { case SysProps.SystemLoadStats: case SysProps.SystemMemoryStats: return this._refreshSysInfoStats(); + + case SysProps.ProcessTrafficStats: + return this._refreshProcessTrafficStats(); } } @@ -402,6 +406,19 @@ class StatLog { }); } + _refreshProcessTrafficStats() { + const trafficStats = getActiveConnections(AllConnections).reduce( + (stats, conn) => { + stats.ingress += conn.rawSocket.bytesRead; + stats.egress += conn.rawSocket.bytesWritten; + return stats; + }, + { ingress: 0, egress: 0 } + ); + + this.setNonPersistentSystemStat(SysProps.ProcessTrafficStats, trafficStats); + } + _refreshUserStat(client, statName, ttlSeconds) { switch (statName) { case UserProps.NewPrivateMailCount: diff --git a/core/system_property.js b/core/system_property.js index b8d8b5c8..6d29e013 100644 --- a/core/system_property.js +++ b/core/system_property.js @@ -37,6 +37,7 @@ module.exports = { SystemMemoryStats: 'system_memory_stats', // object { totalBytes, freeBytes }; non-persistent SystemLoadStats: 'system_load_stats', // object { average, current }; non-persistent + ProcessTrafficStats: 'system_traffic_bytes_ingress', // object { ingress, egress }; non-persistent TotalUserCount: 'user_total_count', // non-persistent NewUsersTodayCount: 'user_new_today_count', // non-persistent diff --git a/core/wfc.js b/core/wfc.js index d1ce530a..da1e7be8 100644 --- a/core/wfc.js +++ b/core/wfc.js @@ -413,6 +413,8 @@ exports.getModule = class WaitingForCallerModule extends MenuModule { const sysMemStats = StatLog.getSystemStat(SysProps.SystemMemoryStats) || {}; const sysLoadStats = StatLog.getSystemStat(SysProps.SystemLoadStats) || {}; const lastLoginStats = StatLog.getSystemStat(SysProps.LastLogin); + const processTrafficStats = + StatLog.getSystemStat(SysProps.ProcessTrafficStats) || {}; const now = moment(); @@ -479,6 +481,8 @@ exports.getModule = class WaitingForCallerModule extends MenuModule { UserProps.NewAddressedToMessageCount, MailCountTTLSeconds ), + processBytesIngress: processTrafficStats.ingress || 0, + processBytesEgress: processTrafficStats.egress || 0, }; return cb(null); diff --git a/docs/_docs/art/mci.md b/docs/_docs/art/mci.md index de921710..75cbb45c 100644 --- a/docs/_docs/art/mci.md +++ b/docs/_docs/art/mci.md @@ -109,6 +109,8 @@ There are many predefined MCI codes that can be used anywhere on the system (pla | `NP` | Count of new private mail to the current user | | `IA` | Indicator as to rather the current user is **available** or not. See also `getStatusAvailIndicators()` in [Themes](themes.md) | | `IV` | Indicator as to rather the curent user is **visible** or not. See also `getStatusVisibleIndicators()` in [Themes](themes.md) | +| `PI` | Ingress bytes for the current process (since ENiGMA started up) | +| `PE` | Egress bytes for the current process (since ENiGMA started up) | Some additional special case codes also exist: diff --git a/docs/_docs/modding/wfc.md b/docs/_docs/modding/wfc.md index 31c93365..7e30f5ff 100644 --- a/docs/_docs/modding/wfc.md +++ b/docs/_docs/modding/wfc.md @@ -96,6 +96,8 @@ The following MCI codes are available: * `newMessagesAddrTo`: Number of new messages **addressed to the current user**. * `availIndicator`: Is the current user availalbe? Displayed via `statusAvailableIndicators` or system theme. See also [Themes](../art/themes.md). * `visIndicator`: Is the current user visible? Displayed via `statusVisibleIndicators` or system theme. See also [Themes](../art/themes.md). + * `processBytesIngress`: Ingress bytes since ENiGMA started. + * `processBytesEgress`: Egress bytes since ENiGMA started. > :information_source: While [Standard MCI](../art/mci.md) codes work on any menu, they will **not** refresh. For values that may change over time, please use the custom format values above. \ No newline at end of file