清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>
#!/bin/sh #获取网卡名称 eth=$(/sbin/ifconfig |grep eth |awk '{print $1}'); #获取当前进出口流量 RXpre=$(cat /proc/net/dev | grep $eth | tr : " " | awk '{print $2}') TXpre=$(cat /proc/net/dev | grep $eth | tr : " " | awk '{print $10}') #暂停1秒 获取当前网卡进出流量 sleep 1 RXnext=$(cat /proc/net/dev | grep $eth | tr : " " | awk '{print $2}') TXnext=$(cat /proc/net/dev | grep $eth | tr : " " | awk '{print $10}') #计算1秒内的流量 RX=$((${RXnext}-${RXpre})) TX=$((${TXnext}-${TXpre})) #最后一次定义进出流量单位KB/s RX=$(echo $RX | awk '{print $1/1024 }') TX=$(echo $TX | awk '{print $1/1024 }') #eth=$(/sbin/ifconfig |grep eth |awk '{print $1}'); #获取IP ipaddr=$(/sbin/ifconfig $eth | awk '/inet addr/ {print $2}' | cut -f2 -d ":"); #RX=$(/sbin/ifconfig $eth | grep -e 'TX bytes'|awk '{print $2}'|awk -F':' '{print $2}'); #TX=$(/sbin/ifconfig $eth | grep -e 'TX bytes'|awk '{print $6}'|awk -F':' '{print $2}'); time=$(date '+%Y-%m-%d %H:%M:00'); day=$(date '+%Y%m%d') name=$(echo $day"_"$ipaddr ) #获取CPU负载 取得AWK最后域 cpuld=$(/usr/bin/w |awk -F: '/load average/ {print $NF}') #获取use内存 mem=$(/usr/bin/free -m |awk '/Mem/ {print $3}') #获取nginx php-cgi调用量 nglimit=$(/usr/sbin/lsof |grep nginx |wc -l) cgilimit=$(/usr/sbin/lsof |grep php-cgi |wc -l) bc=$(free -m |grep 'buffers/cache' |awk '{print $2 $3" "$4}') echo "time:" $time ";" "in:" $RX ";out:" $TX ";use mem:" $mem ";" $bc ";load average:" $cpuld ";nginx limit:" $nglimit ";php-cgi limit:" $cgilimit >> /data/wwwroot/tools/monitor/$name; 用来收集一些常用信息 给管理后台提供绘图数据