Skip to content

Instantly share code, notes, and snippets.

@mansurali901
Last active January 17, 2025 05:11
Show Gist options
  • Save mansurali901/84ae67fadd278629d904f9aaa372f677 to your computer and use it in GitHub Desktop.
Save mansurali901/84ae67fadd278629d904f9aaa372f677 to your computer and use it in GitHub Desktop.
Linux system monitoring system
#!/bin/bash
# This script is written to collect system stats.
# Author : Mansur Ul Hasan
# Email : [email protected]
# Check RAM and SWAP Usages
free -m | grep -v "+\|You" > /tmp/ramcache
echo -e '\E[32m'"Ram Usages :" $tecreset
cat /tmp/ramcache | grep -v "Swap"
echo -e '\E[32m'"Swap Usages :" $tecreset
cat /tmp/ramcache | grep -v "Mem"
# Check Disk Usages
df -h| grep 'Filesystem\|da*' |grep -v tmpfs> /tmp/diskusage
echo -e '\E[32m'"Disk Usages :" $tecreset
cat /tmp/diskusage
# Check Load Average
loadaverage=$(top -n 1 -b | grep "load average:" | awk '{print $10 $11 $12}')
echo -e '\E[32m'"Load Average :" $tecreset $loadaverage
# Check System Uptime
tecuptime=$(uptime | awk '{print $3,$4}' | cut -f1 -d,)
echo -e '\E[32m'"System Uptime Days/(HH:MM) :" $tecreset $tecuptime
# Check Memory usage by process
ps -eo size,pid,user,command --sort -size | awk '{ hr=$1/1024 ; printf("%13.2f Mb ",hr) } { for ( x=4 ; x<=NF ; x++ ) { printf("%s ",$x) } print "" }' |cut -d "" -f2 | cut -d "-" -f1 > /tmp/mem-by-proc
head -n7 /tmp/mem-by-proc
# Unset Variables
unset tecreset os architecture kernelrelease internalip externalip nameserver loadaverage
# Remove Temporary Files
rm -rf /tmp/osrelease /tmp/who /tmp/ramcache /tmp/diskusage /tmp/mem-by-proc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment