#!/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"