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
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。