#!/bin/bash
export chknum=1
echo 3 > /proc/sys/vm/drop_caches
sync
while [ $chknum -ge 0 ]
do
echo "-------------------------------------------------------" >> trace.log
mt=`free | tr [:blank:] \\\n | grep [0-9] | sed -n '1p'`
mu=`free | tr [:blank:] \\\n | grep [0-9] | sed -n '2p'`
mf=`free | tr [:blank:] \\\n | grep [0-9] | sed -n '3p'`
st=`free | tr [:blank:] \\\n | grep [0-9] | sed -n '9p'`
su=`free | tr [:blank:] \\\n | grep [0-9] | sed -n '10p'`
sf=`free | tr [:blank:] \\\n | grep [0-9] | sed -n '11p'`
t=`expr $mt + $st`
u=`expr $mu + $su`
echo "Total Mem: $t"
echo "Used Mem: $u"
R=`expr $mu \* 100 / $mt`
echo "当前内存使用率为: $R%" >>trace.log
echo "$R" >> memory.log
echo "记录时间:" >> trace.log
echo `date` >> trace.log
echo "-------------------------------------------------------" >> trace.log
sleep 20
done
export chknum=1
echo 3 > /proc/sys/vm/drop_caches
sync
while [ $chknum -ge 0 ]
do
echo "-------------------------------------------------------" >> trace.log
mt=`free | tr [:blank:] \\\n | grep [0-9] | sed -n '1p'`
mu=`free | tr [:blank:] \\\n | grep [0-9] | sed -n '2p'`
mf=`free | tr [:blank:] \\\n | grep [0-9] | sed -n '3p'`
st=`free | tr [:blank:] \\\n | grep [0-9] | sed -n '9p'`
su=`free | tr [:blank:] \\\n | grep [0-9] | sed -n '10p'`
sf=`free | tr [:blank:] \\\n | grep [0-9] | sed -n '11p'`
t=`expr $mt + $st`
u=`expr $mu + $su`
echo "Total Mem: $t"
echo "Used Mem: $u"
R=`expr $mu \* 100 / $mt`
echo "当前内存使用率为: $R%" >>trace.log
echo "$R" >> memory.log
echo "记录时间:" >> trace.log
echo `date` >> trace.log
echo "-------------------------------------------------------" >> trace.log
sleep 20
done