Skip to content

Commit fd5a1ca

Browse files
committed
Fixed the snippet to make it more like a snippet
1 parent 9ccbea1 commit fd5a1ca

File tree

2 files changed

+6
-22
lines changed

2 files changed

+6
-22
lines changed

public/consolidated/bash.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
"snippets": [
55
{
66
"title": "System Resource Monitor",
7-
"description": "Monitors system resources (CPU, RAM, disk, users) at specified intervals",
7+
"description": "Monitors system resources (CPU, RAM, disk, users)",
88
"author": "sponkurtus2",
99
"tags": [
1010
"file",
1111
"system"
1212
],
1313
"contributors": [],
14-
"code": "monitor_resources() {\n local interval=\"${1:-5}\" # Seconds between checks\n local checks=\"${2:-12}\" # Number of checks to perform\n local log_file=\"system_stats.log\"\n\n for ((i = 1; i <= checks; i++)); do\n {\n echo \"=== Check $i of $checks ===\"\n date \"+%Y-%m-%d %H:%M:%S\"\n echo \"CPU Load: $(top -bn1 | grep \"Cpu(s)\" | awk '{print $2}')%\"\n echo \"Memory Used: $(free -m | awk 'NR==2{printf \"%.2f%%\", $3*100/$2}')\"\n echo \"Disk Used: $(df -h / | awk 'NR==2{print $5}')\"\n echo \"Active Users: $(who | wc -l)\"\n } >>\"$log_file\"\n\n sleep \"$interval\"\n done\n\n echo \"Log saved to $log_file\"\n}\n\nmonitor_resources\n\n// Usage:\n./system-resource-monitor.sh 3 12 // First argument is the seconds between checks, and second parameter is the number of checks you want to perform\n"
14+
"code": " echo \"CPU Load: $(top -bn1 | grep \"Cpu(s)\" | awk '{print $2}')%\"\n echo \"Memory Used: $(free -m | awk 'NR==2{printf \"%.2f%%\", $3*100/$2}')\"\n echo \"Disk Used: $(df -h / | awk 'NR==2{print $5}')\"\n echo \"Active Users: $(who | wc -l)\"\n\n// Usage:\nchmod a+x system-resource-monitor.sh // First make it executable for all the users\n\n./system-resource-monitor.sh // It will print the following system resources (CPU, RAM, disk, and active users)\n"
1515
}
1616
]
1717
}
Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,18 @@
11
---
22
title: System Resource Monitor
3-
description: Monitors system resources (CPU, RAM, disk, users) at specified intervals
3+
description: Monitors system resources (CPU, RAM, disk, users)
44
author: sponkurtus2
55
tags: file,system
66
---
77

88
```bash
9-
monitor_resources() {
10-
local interval="${1:-5}" # Seconds between checks
11-
local checks="${2:-12}" # Number of checks to perform
12-
local log_file="system_stats.log"
13-
14-
for ((i = 1; i <= checks; i++)); do
15-
{
16-
echo "=== Check $i of $checks ==="
17-
date "+%Y-%m-%d %H:%M:%S"
189
echo "CPU Load: $(top -bn1 | grep "Cpu(s)" | awk '{print $2}')%"
1910
echo "Memory Used: $(free -m | awk 'NR==2{printf "%.2f%%", $3*100/$2}')"
2011
echo "Disk Used: $(df -h / | awk 'NR==2{print $5}')"
2112
echo "Active Users: $(who | wc -l)"
22-
} >>"$log_file"
23-
24-
sleep "$interval"
25-
done
26-
27-
echo "Log saved to $log_file"
28-
}
29-
30-
monitor_resources
3113

3214
// Usage:
33-
./system-resource-monitor.sh 3 12 // First argument is the seconds between checks, and second parameter is the number of checks you want to perform
15+
chmod a+x system-resource-monitor.sh // First make it executable for all the users
16+
17+
./system-resource-monitor.sh // It will print the following system resources (CPU, RAM, disk, and active users)
3418
```

0 commit comments

Comments
 (0)