Initial commit: health monitoring scripts for Discord webhooks
This commit is contained in:
34
health-collector.sh
Executable file
34
health-collector.sh
Executable file
@@ -0,0 +1,34 @@
|
||||
#!/bin/bash
|
||||
# Collects system stats hourly - run via cron every hour
|
||||
# Data stored in ~/.local/share/health-monitor/
|
||||
|
||||
DATA_DIR="$HOME/.local/share/health-monitor"
|
||||
TODAY=$(date +%Y-%m-%d)
|
||||
DATA_FILE="$DATA_DIR/stats-$TODAY.csv"
|
||||
|
||||
mkdir -p "$DATA_DIR"
|
||||
|
||||
# Initialize CSV header if new file
|
||||
if [ ! -f "$DATA_FILE" ]; then
|
||||
echo "timestamp,cpu,mem,load1,load5,load15,disk_pct" > "$DATA_FILE"
|
||||
fi
|
||||
|
||||
# CPU usage (1 second sample)
|
||||
CPU=$(top -bn2 -d0.5 | grep "Cpu(s)" | tail -1 | awk '{printf "%.1f", 100 - $8}')
|
||||
|
||||
# Memory percentage
|
||||
MEM=$(free | awk '/Mem:/ {printf "%.1f", $3/$2 * 100}')
|
||||
|
||||
# Load averages
|
||||
read LOAD1 LOAD5 LOAD15 _ < /proc/loadavg
|
||||
|
||||
# Disk usage
|
||||
DISK=$(df / | awk 'NR==2 {gsub(/%/,""); print $5}')
|
||||
|
||||
# Timestamp
|
||||
TS=$(date +%H:%M)
|
||||
|
||||
echo "$TS,$CPU,$MEM,$LOAD1,$LOAD5,$LOAD15,$DISK" >> "$DATA_FILE"
|
||||
|
||||
# Cleanup old files (keep 7 days)
|
||||
find "$DATA_DIR" -name "stats-*.csv" -mtime +7 -delete 2>/dev/null
|
||||
Reference in New Issue
Block a user