Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions public/consolidated/_index.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
[
{
"name": "BASH",
"icon": "/icons/bash.svg",
"subLanguages": []
},
{
"name": "C",
"icon": "/icons/c.svg",
Expand Down
18 changes: 18 additions & 0 deletions public/consolidated/bash.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[
{
"name": "System",
"snippets": [
{
"title": "System Resource Monitor",
"description": "Monitors system resources (CPU, RAM, disk, users) at specified intervals",
"author": "sponkurtus2",
"tags": [
"file",
"system"
],
"contributors": [],
"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"
}
]
}
]
1 change: 1 addition & 0 deletions public/icons/bash.svg
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please make sure this is removed as well, all content of /public/icons is now in the git ignore

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions snippets/bash/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions snippets/bash/system/system-resource-monitor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
title: System Resource Monitor
description: Monitors system resources (CPU, RAM, disk, users) at specified intervals
author: sponkurtus2
tags: file,system
---

```bash
monitor_resources() {
local interval="${1:-5}" # Seconds between checks
local checks="${2:-12}" # Number of checks to perform
local log_file="system_stats.log"

for ((i = 1; i <= checks; i++)); do
{
echo "=== Check $i of $checks ==="
date "+%Y-%m-%d %H:%M:%S"
echo "CPU Load: $(top -bn1 | grep "Cpu(s)" | awk '{print $2}')%"
echo "Memory Used: $(free -m | awk 'NR==2{printf "%.2f%%", $3*100/$2}')"
echo "Disk Used: $(df -h / | awk 'NR==2{print $5}')"
echo "Active Users: $(who | wc -l)"
} >>"$log_file"

sleep "$interval"
done

echo "Log saved to $log_file"
}

monitor_resources

// Usage:
./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
```