@drocketxx/pm2me 1.1.13 → 1.1.15
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,62 @@ 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 | tail -n +3 | awk '{rx+=$2; tx+=$10} END {print rx, tx}'")
|
|
101
|
+
.then(({ stdout }) => {
|
|
102
|
+
const parts = stdout.trim().split(/\s+/);
|
|
103
|
+
const totalRx = parseInt(parts[0]) || 0;
|
|
104
|
+
const totalTx = parseInt(parts[1]) || 0;
|
|
105
|
+
const timeDiff = (now - lastNetworkStats.time) / 1000;
|
|
106
|
+
if (timeDiff > 0 && lastNetworkStats.rx > 0 && totalRx > 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 => {
|
|
113
|
+
console.error('Network fetch failed:', e);
|
|
114
|
+
// Keep previous values on error
|
|
115
|
+
});
|
|
116
|
+
promises.push(netPromise);
|
|
117
|
+
|
|
118
|
+
// 2. Disk Stats (Cached) - use df for root filesystem
|
|
119
|
+
if (now - cachedDiskStats.lastFetch > DISK_CACHE_TTL) {
|
|
120
|
+
const diskPromise = execPromise("df -B1 / | tail -n 1 | awk '{print $2, $3, $4}'")
|
|
121
|
+
.then(({ stdout }) => {
|
|
122
|
+
const parts = stdout.trim().split(/\s+/);
|
|
123
|
+
const total = parseInt(parts[0]) || 0;
|
|
124
|
+
const used = parseInt(parts[1]) || 0;
|
|
125
|
+
const free = parseInt(parts[2]) || 0;
|
|
126
|
+
if (total > 0) {
|
|
127
|
+
cachedDiskStats = {
|
|
128
|
+
total,
|
|
129
|
+
free,
|
|
130
|
+
used,
|
|
131
|
+
percentage: (used / total) * 100,
|
|
132
|
+
lastFetch: now
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
})
|
|
136
|
+
.catch(e => {
|
|
137
|
+
console.error('Disk fetch failed:', e);
|
|
138
|
+
// Keep cached values on error
|
|
139
|
+
});
|
|
140
|
+
promises.push(diskPromise);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Run all in parallel
|
|
144
|
+
await Promise.all(promises);
|
|
145
|
+
diskUsage = cachedDiskStats;
|
|
146
|
+
} catch (e) {
|
|
147
|
+
console.error('Failed to get system stats on Linux:', e);
|
|
148
|
+
}
|
|
93
149
|
}
|
|
94
150
|
|
|
95
151
|
return {
|