RRDTOOL DAN IPFM

network traffic graph dengan ipfm dan rrdtool

Di ubuntu linux, install package yang diperlukan:

sudo apt-get install ipfm rrdtool

Kemudian edit file /etc/ipfm.conf sesuai keperluan, misalnya sbb:

#device yang akan dilog
DEVICE ppp0
# subnet yang akan dilog dan subnet mask
LOG 61.192.160.85/255.255.255.255
#nama filename (%m: month, %d: day)
FILENAME "/var/log/ipfm/ppp0-%m.%d"
#log setiap 15 menit dan kelipatannyA

DUMP EVERY 10 minutes
CLEAR ALWAYS
RESOLVE

Buat folder baru di home dir:

mkdir /home/dede/rrd
mkdir /home/dede/rrd/host
mkdir /home/dede/rrd/bin

Buat file ~/rrd/rrd.conf sbb:

AWK="awk"
BASE="/home/dede/rrd"
HOSTDIR="$BASE/host"
HOSTLIST="61.192.160.85"

Buat file ~/rrd/bin/create-host.sh sbb:

#!/bin/sh

. /home/dede/rrd/rrd.conf

mkdir -p $HOSTDIR

for i in $HOSTLIST
do
rrdtool create $HOSTDIR/$i.rrd \
-s 3600 \
DS:In:ABSOLUTE:7200:0:U \
DS:Out:ABSOLUTE:7200:0:U \
DS:Total:ABSOLUTE:7200:0:U \
RRA:AVERAGE:0.5:1:256 \
RRA:AVERAGE:0.5:15:2048
done

Execute:

chmod +x ~/rrd/bin/create-host.sh
~/rrd/bin/create-host.sh

Pastikan sudah terbentuk file dengan ekstensi rrd di folder ~/rrd/host/.

Buat file ~/rrd/bin/cron-host.sh sbb:


#!/bin/sh. /home/dede/rrd/rrd.conf

for h in $HOSTLIST
do
# j=`host $i | tail -1 | awk ‘{print $3}’` # get IP
$AWK ‘\
BEGIN { found = 0; }
/’$h’/ {
i = $2;
o = $3;
t = $4;
found = 1;
}
END {
if ( ! found ) { i = 0; o = 0; t = 0; }
system( “/usr/bin/rrdtool update ‘$HOSTDIR/$h’.rrd \
N:” i “:” o “:” t );
}’ < /var/log/ipfm/ppp0-`date +%m.%d`
done

Jalankan service ipfm:

sudo /etc/init.d/ipfm start

Tunggu maksimal selama 10 menit, pastikan ipfm membuat file log di folder /var/log/ipfm/.

Buat crontab sbb:

1,11,21,31,41,51 * * * * /home/dede/rrd/bin/cron-host.sh

Setting ipfm dan rrdtool sudah selesai. Untuk membuat graph dengan php, bisa gunakan code misalnya sbb:


< ?php
function rrd_draw( $cmd, $scope="d", $size="m", $what ){
switch( $scope ){
case 'd':
$start = '-86400';
$title = "Last 24 Hours";
break;
case 'w':
$start = '-604800';
$title = "Last 7 Days";
break;
case 'm':
$start = '-2592000';
$title = "Last 30 Days";
break;
case 'y':
$start = '-31622400';
$title = "Last 366 Days";
break;
}

$title = $what . ” traffic – ” . $title;

switch( $size ){
case ‘s’:
$width = ‘200’; $height=’50’;
break;
case ‘m’:
$width = ‘500’; $height=’100′;
break;
case ‘l’:
$width = ‘800’; $height=’200′;
break;
}

passthru( “/usr/bin/rrdtool graph – -a PNG -s $start”
. ” -w $width -h $height –title=\””.$title.”\” –vertical-label bytes/s ”
. $cmd );

}
header(“Content-type: image/png”);

$color=array(“#0000FF”,”#FF0000″,”#00FF00″);
$arg=””;
$n=0;
$type=”LINE2″;
if(!isset($what)) {$what=”In,Out”;}
$whatlist = explode(“,”, $what);
$num = count($whatlist);

$host = “61.192.160.85”;

foreach ($whatlist as $what_) {
$arg .= “DEF:”.$what_.”=/home/akiss/rrd/host/”.$host.”.rrd:”.$what_.”:AVERAGE “.$type.”:”.$what_ . $color[$n].”:\””.$what_.””;

if ($n==($num-1)) {$arg.=”\\c\” “; } else { $arg.=”\” “; }
$n++;
}

rrd_draw($arg,$scope,$size,$what);

?>

sumber dari blognya http://akiss.org

contoh rrdtool http://www.merindo.com/rrdtool/

punya gwe sendiri belum berhasil masih andelin ala mokrotik punya 😀

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s