Add Process/enig start ingress/egress bytes stats
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user