Script to run top command after every 5 minutes RAM utilization:
#!/bin/sh
top -b -n 1 -o %MEM | head -17 >> /var/log/logging.txt
echo “=========” >> /var/log/logging.txt
Change the permissions to execute,
chmod 777 script1
move the script to cronfrequently to run it after every 5 mins,
mv script1 /etc/actions/cronfrequently/
(use cronhourlybyfour directory for 15 mins execution)
To see the RAM usage by processes:
ps -eo size,pid,user,command | awk ‘{ hr=$1/1024 ; printf(“%13.6f Mb “,hr) } { for ( x=4 ; x<=NF ; x++ ) { printf(“%s “,$x) } print “” }’ | sort
top -b -n 1 -o %MEM | head -17
To see RAM stats:
vmstat
To see free memory and cached space:
free -hm
To see a specific process CPU or RAM utilization using top::
top -p `pgrep PROCESS_NAME | tr “\\n” “,” | sed ‘s/,$//’`
(e.g. datastore.pl)
Script to see what processes are using max RAM every 5 minutes:
/var/log/9999monitorram
#!/bin/sh
OutDir=/var/log/monitoring
File=RamUsage$(date +%d-%m-%y)
mkdir -p $OutDir
echo “——————————–$(date +%d-%m-%y)—–$(date +%H:%M:%S)—————————————“>> $OutDir/$File
ps -eo size,pid,user,command | awk ‘{ hr=$1/1024 ; printf(“%13.6f Mb “,hr) } { for ( x=4 ; x<=NF ; x++ ) { printf(“%s “,$x) } print “” }’ | sort | tail -n20>> $OutDir/$File
ln -s 9999monitorram /etc/actions/cronfrequently/