Add Process/enig start ingress/egress bytes stats

This commit is contained in:
Bryan Ashby 2022-08-01 23:09:18 -06:00
parent 044cc24418
commit 715202680e
No known key found for this signature in database
GPG Key ID: C2C1B501E4EFD994
10 changed files with 51 additions and 0 deletions

View File

@ -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: {

View File

@ -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);

View File

@ -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

View File

@ -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();

View File

@ -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:

View File

@ -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

View File

@ -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);

View File

@ -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:

View File

@ -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.