Update server configuration and enhance network monitoring. Changed SERVER_NAME in .env file. Added network download and upload speed tracking to system stats in index.ts, and updated SessionServer model to store these metrics.

This commit is contained in:
2026-02-17 19:12:30 +05:00
parent d977290646
commit eef57a9b21
3 changed files with 40 additions and 1 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
SERVER_LOCATION=a1 SERVER_LOCATION=a1
SERVER_NAME=s6 SERVER_NAME=s7
SERVER_TYPE=prod SERVER_TYPE=prod
PORT=3000 PORT=3000
MONGO_URI=mongodb://root:p62Z!ZatgY25@194.26.138.94:27017 MONGO_URI=mongodb://root:p62Z!ZatgY25@194.26.138.94:27017
+33
View File
@@ -79,6 +79,8 @@ async function updateSessionServerData(data: Record<string, unknown>) {
} }
const execAsync = util.promisify(exec); const execAsync = util.promisify(exec);
const NETWORK_LOG_INTERVAL = 10; // log network devices every N polls
let networkPollCount = 0;
async function getSystemStats() { async function getSystemStats() {
try { try {
@@ -119,6 +121,37 @@ async function getSystemStats() {
// GPU unavailable, CPU/RAM still updated // GPU unavailable, CPU/RAM still updated
} }
// Network (systeminformation)
try {
const networkStats = await si.networkStats("*");
const totalRxSec = networkStats.reduce(
(sum, iface) => sum + (iface.rx_sec ?? 0),
0
);
const totalTxSec = networkStats.reduce(
(sum, iface) => sum + (iface.tx_sec ?? 0),
0
);
data.networkDownloadSpeed =
Math.round(((totalRxSec * 8) / 1_000_000) * 100) / 100;
data.networkUploadSpeed =
Math.round(((totalTxSec * 8) / 1_000_000) * 100) / 100;
networkPollCount++;
if (networkPollCount % NETWORK_LOG_INTERVAL === 0) {
const ifaceInfo = networkStats
.map(
(n) =>
`${n.iface} (${(((n.rx_sec ?? 0) * 8) / 1_000_000).toFixed(2)} ↓ / ${(((n.tx_sec ?? 0) * 8) / 1_000_000).toFixed(2)} ↑ Mbps)`
)
.join("; ");
console.log("Network stats from:", ifaceInfo || "no interfaces");
}
} catch {
// networkStats unavailable
}
await updateSessionServerData(data); await updateSessionServerData(data);
} catch (error) { } catch (error) {
if (error instanceof Error) { if (error instanceof Error) {
+6
View File
@@ -36,6 +36,12 @@ const sessionServerSchema = new Schema(
localIP: { localIP: {
type: String, type: String,
}, },
networkDownloadSpeed: {
type: Number,
},
networkUploadSpeed: {
type: Number,
},
}, },
{ {
timestamps: true, timestamps: true,