-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli-args.js
More file actions
84 lines (77 loc) · 2.69 KB
/
Copy pathcli-args.js
File metadata and controls
84 lines (77 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Simple command line argument parser (no external dependencies)
const parseArgs = (args) => {
const options = {
interval: '2',
count: '5',
top: '5',
json: false,
csv: false,
continuous: false,
silent: false,
raw: false,
outputFile: null
};
for (let i = 0; i < args.length; i++) {
const arg = args[i];
if (arg === '--json') options.json = true;
else if (arg === '--csv') options.csv = true;
else if (arg === '--continuous') options.continuous = true;
else if (arg === '--silent') options.silent = true;
else if (arg === '--raw') options.raw = true;
else if (arg.startsWith('--interval')) {
const parts = arg.split('=');
options.interval = parts[1] || args[++i];
}
else if (arg.startsWith('--count')) {
const parts = arg.split('=');
options.count = parts[1] || args[++i];
}
else if (arg.startsWith('--top')) {
const parts = arg.split('=');
options.top = parts[1] || args[++i];
}
else if (arg.startsWith('--cpu-threshold')) {
const parts = arg.split('=');
options.cpuThreshold = parts[1] || args[++i];
}
else if (arg.startsWith('--mem-threshold')) {
const parts = arg.split('=');
options.memThreshold = parts[1] || args[++i];
}
else if (arg.startsWith('--disk-threshold')) {
const parts = arg.split('=');
options.diskThreshold = parts[1] || args[++i];
}
else if (arg.startsWith('--output-file')) {
const parts = arg.split('=');
options.outputFile = parts[1] || args[++i];
}
else if (arg === '-h' || arg === '--help') {
console.log(`
sysmon - Zero-dependency system resource monitoring tool
Usage: sysmon [options]
Options:
-i, --interval <seconds> Monitoring interval in seconds (default: 2)
-c, --count <number> Number of monitoring cycles (default: 5)
-t, --top <number> Show top N processes (default: 5)
--json Output in JSON format
--csv Output in CSV format
--cpu-threshold <percentage> Alert when CPU exceeds percentage
--mem-threshold <percentage> Alert when memory exceeds percentage
--disk-threshold <percentage> Alert when disk usage exceeds percentage
--continuous Run continuously until interrupted
--silent Silent mode, only show alerts
--raw Raw output without formatting
--output-file <path> Save snapshots to file (JSON format)
-h, --help Show this help message
Examples:
sysmon --interval 3 --count 10
sysmon --top 5 --json
sysmon --cpu-threshold 80 --continuous
`);
process.exit(0);
}
}
return options;
};
module.exports = { parseArgs };