@drocketxx/pm2me 1.1.14 → 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.
|
@@ -97,29 +97,32 @@ export const getSystemStats = async () => {
|
|
|
97
97
|
const promises = [];
|
|
98
98
|
|
|
99
99
|
// 1. Network Stats (Every time) - read from /proc/net/dev
|
|
100
|
-
const netPromise = execPromise("cat /proc/net/dev | awk '
|
|
100
|
+
const netPromise = execPromise("cat /proc/net/dev | tail -n +3 | awk '{rx+=$2; tx+=$10} END {print rx, tx}'")
|
|
101
101
|
.then(({ stdout }) => {
|
|
102
|
-
const
|
|
103
|
-
const totalRx = parseInt(
|
|
104
|
-
const totalTx = parseInt(
|
|
102
|
+
const parts = stdout.trim().split(/\s+/);
|
|
103
|
+
const totalRx = parseInt(parts[0]) || 0;
|
|
104
|
+
const totalTx = parseInt(parts[1]) || 0;
|
|
105
105
|
const timeDiff = (now - lastNetworkStats.time) / 1000;
|
|
106
|
-
if (timeDiff > 0 && lastNetworkStats.rx > 0) {
|
|
106
|
+
if (timeDiff > 0 && lastNetworkStats.rx > 0 && totalRx > 0) {
|
|
107
107
|
networkUsage.down = Math.max(0, (totalRx - lastNetworkStats.rx) / timeDiff);
|
|
108
108
|
networkUsage.up = Math.max(0, (totalTx - lastNetworkStats.tx) / timeDiff);
|
|
109
109
|
}
|
|
110
110
|
lastNetworkStats = { rx: totalRx, tx: totalTx, time: now };
|
|
111
111
|
})
|
|
112
|
-
.catch(e =>
|
|
112
|
+
.catch(e => {
|
|
113
|
+
console.error('Network fetch failed:', e);
|
|
114
|
+
// Keep previous values on error
|
|
115
|
+
});
|
|
113
116
|
promises.push(netPromise);
|
|
114
117
|
|
|
115
118
|
// 2. Disk Stats (Cached) - use df for root filesystem
|
|
116
119
|
if (now - cachedDiskStats.lastFetch > DISK_CACHE_TTL) {
|
|
117
|
-
const diskPromise = execPromise("df -B1 / | awk '
|
|
120
|
+
const diskPromise = execPromise("df -B1 / | tail -n 1 | awk '{print $2, $3, $4}'")
|
|
118
121
|
.then(({ stdout }) => {
|
|
119
|
-
const
|
|
120
|
-
const total = parseInt(
|
|
121
|
-
const used = parseInt(
|
|
122
|
-
const free = parseInt(
|
|
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;
|
|
123
126
|
if (total > 0) {
|
|
124
127
|
cachedDiskStats = {
|
|
125
128
|
total,
|
|
@@ -130,7 +133,10 @@ export const getSystemStats = async () => {
|
|
|
130
133
|
};
|
|
131
134
|
}
|
|
132
135
|
})
|
|
133
|
-
.catch(e =>
|
|
136
|
+
.catch(e => {
|
|
137
|
+
console.error('Disk fetch failed:', e);
|
|
138
|
+
// Keep cached values on error
|
|
139
|
+
});
|
|
134
140
|
promises.push(diskPromise);
|
|
135
141
|
}
|
|
136
142
|
|