Last active
January 1, 2023 16:32
-
-
Save MagedSaeed/fcf2a95d9d436a937f11d59b6c53905d to your computer and use it in GitHub Desktop.
Monitor resources from bash
This file contains hidden or 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 | |
# This script monitors CPU and memory usage | |
# Get the current usage of CPU and memory | |
cpuUsage=$(top -bn1 | awk '/Cpu/ { print $2}') | |
memUsage=$(free -m | awk '/Mem/{print $3}') | |
# Print the usage | |
echo "CPU Usage: $cpuUsage%" | |
printf "Memory Usage: %'d MB\n" $memUsage | |
echo "GPU STATS (this requires pip install gpustat):" | |
gpustat | |
# save this code to monitor_resources.bash and run: `watch -n 1 monitor_resources.bashs` to update every second | |
# This has been updated from: | |
# https://linuxconfig.org/bash-script-to-monitor-cpu-and-memory-usage-on-linux |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment