Debian – Multi Router Traffic Grapher (MRTG) – sample script

Инсталация

apt-get install mrtg

Създаваме скрипт /etc/init.d/mrtg-stats от откъдето MRTG ще взима информация със съдържание:

#!/bin/bash

DEV="$1"
if test -z "$DEV"; then echo No device specified; exit 1; fi

INFO=`cat /proc/net/dev | grep $DEV | tr -s ' ' ' ' | cut -d: -f2`
RECEIVE=`echo $INFO | cut -d" " -f1`
TRANSMIT=`echo $INFO | cut -d" " -f9`
UPTIME=`uptime | tr -s ' ' ' ' | cut -d" " -f4-`

echo $[$RECEIVE + 0]
echo $[$TRANSMIT + 0]
echo $UPTIME
echo "itservice-bg.net"

Даваме му нужните права за изпълнение:

chmod 755 /etc/init.d/mrtg-stats

След това създаваме конфигурационния файл на MRTG /etc/mrtg.cfg където добавяме следното съдържание

WorkDir: /var/www/mrtg
Options[_]: bits,growright
WriteExpires: Yes
EnableIPv6: no

Target[eth0]:`/etc/init.d/mrtg-stats eth0 `
MaxBytes[eth0]: 12500000
Title[eth0]: Traffic Analysis for eth0
PageTop[eth0]: Traffic Analysis for eth0
ShortLegend[eth0]: %
YLegend[eth0]: eth0 Utilization
Legend1[eth0]: RECEIVE (Load)
Legend2[eth0]: SEND (Load)
Legend3[eth0]:
Legend4[eth0]:
LegendI[eth0]:  RECEIVE
LegendO[eth0]:  SEND
Options[eth0]: nopercent, growright

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.