Linux自动收集某个进程的脚本
interval=($2) name=($1) arrA=($3) while true do a=(`top -b -n 2|grep Cpu|awk '{print $2}'`) echo $name.cpu.total" "${a[1]%%%us,}" "`date +%s` d=`free -m|grep Mem|awk '{print $3}'` echo $name.mem.used" "$[d*1024*1024]" "`date +%s` e=`free -m|grep Mem|awk '{print $2}'` echo $name.mem.total" "$[e*1024*1024]" "`date +%s` for NUM in ${arrA[*]} do cpu=`top -n 1 -p $NUM|tail -2|head -1|awk '{ssd=NF-4} {print $ssd}'` b=$(awk 'BEGIN{printf "%.1f\n",'$cpu'/4}') echo $name.cpu.$NUM" "$b" "`date +%s` mem=(`cat /proc/$NUM/status|grep -e VmRSS`) if [ "${mem[1]}" == "" ] then echo $name.mem.$NUM" "0.0 `date +%s` else c=${mem[1]} echo $name.mem.$NUM" "$[c*1024]" "`date +%s` fi done sleep $interval done