querysub 0.651.0 → 0.652.0
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.
package/package.json
CHANGED
|
@@ -31,7 +31,7 @@ import { ProcessRecord, syncProcessRecords, listProcessRecords } from "./process
|
|
|
31
31
|
|
|
32
32
|
|
|
33
33
|
|
|
34
|
-
const getMemoryInfo = measureWrap(async function getMemoryInfo(): Promise<{ value: number; max: number } | undefined> {
|
|
34
|
+
const getMemoryInfo = measureWrap(async function getMemoryInfo(): Promise<{ memory?: { value: number; max: number }; swap?: { value: number; max: number } } | undefined> {
|
|
35
35
|
if (os.platform() === "win32") {
|
|
36
36
|
throw new Error("Windows is not supported for machine resource monitoring");
|
|
37
37
|
}
|
|
@@ -40,17 +40,24 @@ const getMemoryInfo = measureWrap(async function getMemoryInfo(): Promise<{ valu
|
|
|
40
40
|
// Linux: Use free command
|
|
41
41
|
let result = await runPromise("free -b", { quiet: true });
|
|
42
42
|
let lines = result.split("\n");
|
|
43
|
-
let
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
let parseLine = (prefix: string): { value: number; max: number } | undefined => {
|
|
44
|
+
let line = lines.find(line => line.startsWith(prefix));
|
|
45
|
+
if (!line) return undefined;
|
|
46
|
+
let parts = line.split(/\s+/);
|
|
46
47
|
let total = parseInt(parts[1]);
|
|
47
48
|
let used = parseInt(parts[2]);
|
|
48
|
-
if (total && used >= 0) {
|
|
49
|
+
if (total >= 0 && used >= 0) {
|
|
49
50
|
return { value: used, max: total };
|
|
50
51
|
}
|
|
52
|
+
return undefined;
|
|
53
|
+
};
|
|
54
|
+
let memory = parseLine("Mem:");
|
|
55
|
+
let swap = parseLine("Swap:");
|
|
56
|
+
if (memory || swap) {
|
|
57
|
+
return { memory, swap };
|
|
51
58
|
}
|
|
52
59
|
} catch (e: any) {
|
|
53
|
-
console.warn(`Error getting memory info: ${e.
|
|
60
|
+
console.warn(`Error getting memory info: ${e.stack}`);
|
|
54
61
|
}
|
|
55
62
|
return undefined;
|
|
56
63
|
});
|
|
@@ -98,11 +105,19 @@ const getLiveMachineInfo = measureWrap(async function getLiveMachineInfo() {
|
|
|
98
105
|
getDiskInfo()
|
|
99
106
|
]);
|
|
100
107
|
|
|
101
|
-
if (memoryInfo) {
|
|
108
|
+
if (memoryInfo?.memory) {
|
|
102
109
|
machineInfo.info.ram = {
|
|
103
110
|
type: "MEMORY",
|
|
104
|
-
value: memoryInfo.value,
|
|
105
|
-
max: memoryInfo.max,
|
|
111
|
+
value: memoryInfo.memory.value,
|
|
112
|
+
max: memoryInfo.memory.max,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (memoryInfo?.swap) {
|
|
117
|
+
machineInfo.info.swap = {
|
|
118
|
+
type: "SWAP",
|
|
119
|
+
value: memoryInfo.swap.value,
|
|
120
|
+
max: memoryInfo.swap.max,
|
|
106
121
|
};
|
|
107
122
|
}
|
|
108
123
|
|
|
@@ -8,8 +8,11 @@ export const MEMORY_WARNING_THRESHOLD = 0.7;
|
|
|
8
8
|
export const MEMORY_ERROR_THRESHOLD = 0.85;
|
|
9
9
|
export const DISK_WARNING_THRESHOLD = 0.8;
|
|
10
10
|
export const DISK_ERROR_THRESHOLD = 0.92;
|
|
11
|
+
// Swap in use at all means memory pressure already happened, so warn much earlier than RAM.
|
|
12
|
+
export const SWAP_WARNING_THRESHOLD = 0.25;
|
|
13
|
+
export const SWAP_ERROR_THRESHOLD = 0.7;
|
|
11
14
|
|
|
12
|
-
/** The standard thresholds for the machine resource bar types ("MEMORY" / "DISK"), so every page showing these bars warns identically. */
|
|
15
|
+
/** The standard thresholds for the machine resource bar types ("MEMORY" / "DISK" / "SWAP"), so every page showing these bars warns identically. */
|
|
13
16
|
export function getUsageThresholds(type: string): { warningThreshold?: number; errorThreshold?: number } {
|
|
14
17
|
if (type === "MEMORY") {
|
|
15
18
|
return { warningThreshold: MEMORY_WARNING_THRESHOLD, errorThreshold: MEMORY_ERROR_THRESHOLD };
|
|
@@ -17,6 +20,9 @@ export function getUsageThresholds(type: string): { warningThreshold?: number; e
|
|
|
17
20
|
if (type === "DISK") {
|
|
18
21
|
return { warningThreshold: DISK_WARNING_THRESHOLD, errorThreshold: DISK_ERROR_THRESHOLD };
|
|
19
22
|
}
|
|
23
|
+
if (type === "SWAP") {
|
|
24
|
+
return { warningThreshold: SWAP_WARNING_THRESHOLD, errorThreshold: SWAP_ERROR_THRESHOLD };
|
|
25
|
+
}
|
|
20
26
|
return {};
|
|
21
27
|
}
|
|
22
28
|
|