Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save raymond852/a16466b4a4af7b908a73b43cc8bfb4c8 to your computer and use it in GitHub Desktop.
Save raymond852/a16466b4a4af7b908a73b43cc8bfb4c8 to your computer and use it in GitHub Desktop.
#!/bin/sh
Interval=2
#Format: idle,runq-sz,ldavg-1,proc_VmSize,proc_VmRSS
echo "idle,runq-sz,ldavg-1,proc_VmSize,proc_VmRSS"
if [ ! -f /proc/$1/status ]; then
echo "Please specify the correct pid of process as parameter!!!"
exit
fi
while true; do
CPU=`sar -u -q $Interval 1 | grep -v Average | grep -v Linux | grep -v '^$' | \
{ read a && read b && read c && read d; echo "$b $d"; } | \
awk '{print $9","$12","$14}'`
MEM=`cat /proc/$1/status |grep -e VmSize -e VmRSS|awk {'print $2'}`
VmSize=`echo $MEM | cut -d \ -f 1 | tr -d "\n"`
VmRSS=`echo $MEM | cut -d \ -f 2 | tr -d "\n"`
VMSize1=`expr $VmSize / 1024`
VmRSS1=`expr $VmRSS / 1024`
echo $CPU,$VMSize1,$VmRSS1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment