@drocketxx/pm2me 1.1.13 → 1.1.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -90,6 +90,56 @@ export const getSystemStats = async () => {
|
|
|
90
90
|
} catch (e) {
|
|
91
91
|
console.error('Failed to get system stats via PowerShell:', e);
|
|
92
92
|
}
|
|
93
|
+
} else {
|
|
94
|
+
// Linux/Unix systems
|
|
95
|
+
try {
|
|
96
|
+
const now = Date.now();
|
|
97
|
+
const promises = [];
|
|
98
|
+
|
|
99
|
+
// 1. Network Stats (Every time) - read from /proc/net/dev
|
|
100
|
+
const netPromise = execPromise("cat /proc/net/dev | awk 'NR>2 {rx+=$2; tx+=$10} END {print rx\" \"tx}'")
|
|
101
|
+
.then(({ stdout }) => {
|
|
102
|
+
const [rxStr, txStr] = stdout.trim().split(' ');
|
|
103
|
+
const totalRx = parseInt(rxStr) || 0;
|
|
104
|
+
const totalTx = parseInt(txStr) || 0;
|
|
105
|
+
const timeDiff = (now - lastNetworkStats.time) / 1000;
|
|
106
|
+
if (timeDiff > 0 && lastNetworkStats.rx > 0) {
|
|
107
|
+
networkUsage.down = Math.max(0, (totalRx - lastNetworkStats.rx) / timeDiff);
|
|
108
|
+
networkUsage.up = Math.max(0, (totalTx - lastNetworkStats.tx) / timeDiff);
|
|
109
|
+
}
|
|
110
|
+
lastNetworkStats = { rx: totalRx, tx: totalTx, time: now };
|
|
111
|
+
})
|
|
112
|
+
.catch(e => console.error('Network fetch failed:', e));
|
|
113
|
+
promises.push(netPromise);
|
|
114
|
+
|
|
115
|
+
// 2. Disk Stats (Cached) - use df for root filesystem
|
|
116
|
+
if (now - cachedDiskStats.lastFetch > DISK_CACHE_TTL) {
|
|
117
|
+
const diskPromise = execPromise("df -B1 / | awk 'NR==2 {print $2\" \"$3\" \"$4}'")
|
|
118
|
+
.then(({ stdout }) => {
|
|
119
|
+
const [totalStr, usedStr, freeStr] = stdout.trim().split(' ');
|
|
120
|
+
const total = parseInt(totalStr) || 0;
|
|
121
|
+
const used = parseInt(usedStr) || 0;
|
|
122
|
+
const free = parseInt(freeStr) || 0;
|
|
123
|
+
if (total > 0) {
|
|
124
|
+
cachedDiskStats = {
|
|
125
|
+
total,
|
|
126
|
+
free,
|
|
127
|
+
used,
|
|
128
|
+
percentage: (used / total) * 100,
|
|
129
|
+
lastFetch: now
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
})
|
|
133
|
+
.catch(e => console.error('Disk fetch failed:', e));
|
|
134
|
+
promises.push(diskPromise);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Run all in parallel
|
|
138
|
+
await Promise.all(promises);
|
|
139
|
+
diskUsage = cachedDiskStats;
|
|
140
|
+
} catch (e) {
|
|
141
|
+
console.error('Failed to get system stats on Linux:', e);
|
|
142
|
+
}
|
|
93
143
|
}
|
|
94
144
|
|
|
95
145
|
return {
|