#!/bin/bash
cputotal=`head -1 /proc/stat |awk '{print $2+$3+$4+$5}'`
cpunow=`head -1 /proc/stat |awk '{print $2+$3+$4}'`
memtotal=`free -m |sed -n '/Mem/p'|awk '{print $2}'`
memnow=`free -m |sed -n '/Mem/p'|awk '{print $3}'`
cpuused=`gawk -v x=$cpunow -v y=$cputotal 'BEGIN{printf "%.5f",x * 100/y}'`
memused=`gawk -v x=$memnow -v y=$memtotal 'BEGIN{printf "%.5f",x * 100/y}'`
case "$1" in
cpu)
echo $cpuused
;;
mem)
echo $memused
;;
clu)
size=`(stat $2 | grep Size |awk '{print $2}')`
num=`(stat $2 | grep Size |awk '{print $4}')`
block=`expr $size / $num`
echo $block
;;
*)
echo "it used cpu;mem;clu"
;;
esac
阅读(499) | 评论(0) | 转发(0) |