查看网络流量,并用rrdtool画图

#!/bin/sh
#set -x

function traff()
{
        eth=$1
        RXpre=$(cat /proc/net/dev | grep $eth | tr : " " | awk '{print $2}')
        TXpre=$(cat /proc/net/dev | grep $eth | tr : " " | awk '{print $10}')
        sleep 2
        RXnext=$(cat /proc/net/dev | grep $eth | tr : " " | awk '{print $2}')
        TXnext=$(cat /proc/net/dev | grep $eth | tr : " " | awk '{print $10}')
        RX0=$((${RXnext}-${RXpre}))
        TX0=$((${TXnext}-${TXpre}))
        if [ $2 = TX ];then
                echo "$(echo $TX0 | awk '{print $1/1024}')"
        fi
        if [ $2 = RX ];then
                echo "$(echo $RX0 | awk '{print $1/1024}')"
        fi
}

rrd_path="/home/yfjy/bakfile/logs"
image_path="$rrd_path/images"
sec=300
input=`traff eth0 RX`
output=`traff eth0 TX`
now=`date +%s`

#rrdtool create $rrd_path/network.rrd -s 300 DS:Input:GAUGE:600:U:U DS:Output:GAUGE:600:U:U RRA:AVERAGE:0.5:1:288

rrdtool update $rrd_path/network.rrd $now:$input:$output

rrdtool graph $image_path/network.png \
--title "Local Network" \
DEF:v1=$rrd_path/network.rrd:Input:AVERAGE \
DEF:v2=$rrd_path/network.rrd:Output:AVERAGE \
AREA:v1#FF0000:"Input" \
AREA:v2#00FF00:"Output" \
-v "Value"





本文转自 vfast_chenxy 51CTO博客,原文链接:http://blog.51cto.com/chenxy/1185951,如需转载请自行联系原作者
上一篇:WPF自定义控件02:字体图标支持


下一篇:Ubuntu下pycharm无法输入中文