Last active
October 20, 2024 19:27
-
-
Save palaniraja/3d4e0af615fc7a1b5aed574a0ef7033e to your computer and use it in GitHub Desktop.
poor man's resource monitor for raspberrypi home server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# step 1: install these tools | |
# sudo apt install sysstat | |
# sudo apt install ifstat | |
# step 2: setup header for the files in ~/scripts | |
# df -h | head -1 > disk_history.log | |
# ifstat -i eth0,wlan0,wg0,docker0 1 1 | head -2 > network_history.log | |
# free -h | head -2 > memory_history.log | |
# vcgencmd measure_temp > cpu_temp_history.log | |
# mpstat | tail -2| head -1 > cpu_history.log | |
# step 3: add to your crontab | |
# capture resource usage every 30 min | |
#*/30 * * * * sudo bash /home/strawberry/scripts/resource-monitor.sh | |
cpu_history_file="/home/strawberry/scripts/cpu_history.log" # mpstat | tail -1 | |
cpu_temp_file="/home/strawberry/scripts/cpu_temp_history.log" # vcgencmd measure_temp | |
memory_history_file="/home/strawberry/scripts/memory_history.log" # free -h | |
disk_history_file="/home/strawberry/scripts/disk_history.log" # df -h | |
network_history_file="/home/strawberry/scripts/network_history.log" # ifstat 1 1 | |
cpu_history=$(mpstat | tail -1) | |
echo "$(date) | $cpu_history" >> $cpu_history_file | |
cpu_temp_history=$(vcgencmd measure_temp) | |
echo "$(date) | $cpu_temp_history" >> $cpu_temp_file | |
mem_history=$(free -h | grep "Mem" --color=never) | |
echo "$(date) | $mem_history" >> $memory_history_file | |
disk_history=$(df -h | grep "/dev/nvme0n1p2" --color=never) | |
echo "$(date) | $disk_history" >> $disk_history_file | |
net_history=$(ifstat -i eth0,wlan0,wg0,docker0 1 1 | tail -1) | |
echo "$(date) | $net_history" >> $network_history_file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
based on whether you have sdcard
/dev/mmcblk0p2
or nvme/dev/nvme0n1p2
you need to updatedf -h | grep ...