发布网友
共5个回答
热心网友
想监视系统内存?好像是没法直接得到现成的百分比的,自己取值计算一下吧
totalmem=`free -m | grep 'Mem' | awk '{print $3}'`
usedmem=`free -m | grep 'Mem' | awk '{print $2}'`
usage=$(bc<<EOF
scale=4
($freemem/$totalmem)*100
EOF)
freeusage=`echo $free | awk -F. '{print $1}'`
echo "Free Memory Usage = $freeusage%"
以前Solaris里的改了改
只是个片段,需要什么判断之类自己填充到脚本里 一点点加吧 呵呵 希望对你有帮助
单要使用率的话二楼的更简练~~ 呵呵
free -m | sed -n '2p' | awk '{print "used mem is "$3"M,total mem is "$2"M,used percent is "$3/$2*100"%"}'
热心网友
用free命令,没有百分比,有KB,MB,GB,如下!
usage: free [-b|-k|-m|-g] [-l] [-o] [-t] [-s delay] [-c count] [-V]
-b,-k,-m,-g show output in bytes, KB, MB, or GB
-l show detailed low and high memory statistics
-o use old format (no -/+buffers/cache line)
-t display total for RAM + swap
-s update every [delay] seconds
-c update [count] times
-V display version information and exit
热心网友
不用那么麻烦,这样就可以(centos7)
top -n 5 |sed -n '4p' |awk -F " " '{print $8/$4*100"%"}'
used除以total的结果。
热心网友
free -m | sed -n '2p' | awk '{print "used mem is "$3"M,total mem is “$2"M,used percent is "$3/$2"%"}'
热心网友
直接用top命令就行