Hello.
I trying to use MRTG to create graphs for every client IP on my gateway, but for some strange reason it creates png and html files, but doesnt get info from script.But it creates graphs and get info from interface script.
System is Debian Etch
This is ls /var/www/mrtg/ -al
PHP Code:
-rw-r--r-- 1 root root 2373 2009-02-19 19:25 192.168.168.11-day.png
-rw-r--r-- 1 root root 5901 2009-02-19 19:25 192.168.168.11.html
-rw-r--r-- 1 root root 48201 2009-02-19 19:25 192.168.168.11.log
-rw-r--r-- 1 root root 2360 2009-02-19 18:55 192.168.168.11-month.png
-rw-r--r-- 1 root root 48201 2009-02-19 19:20 192.168.168.11.old
-rw-r--r-- 1 root root 2272 2009-02-19 19:20 192.168.168.11-week.png
-rw-r--r-- 1 root root 1653 2009-02-19 00:35 192.168.168.11-year.png
-rw-r--r-- 1 root root 2753 2009-02-19 19:25 eth0-day.png
-rw-r--r-- 1 root root 6085 2009-02-19 19:25 eth0.html
-rw-r--r-- 1 root root 49243 2009-02-19 19:25 eth0.log
-rw-r--r-- 1 root root 2544 2009-02-19 18:55 eth0-month.png
-rw-r--r-- 1 root root 49237 2009-02-19 19:20 eth0.old
-rw-r--r-- 1 root root 2592 2009-02-19 19:20 eth0-week.png
-rw-r--r-- 1 root root 2668 2009-02-19 00:35 eth0-year.png
-rw-r--r-- 1 root root 1617 2009-02-19 00:25 eth1-day.png
-rw-r--r-- 1 root root 6024 2009-02-19 00:25 eth1.html
-rw-r--r-- 1 root root 48277 2009-02-19 00:25 eth1.log
-rw-r--r-- 1 root root 1344 2009-02-18 23:55 eth1-month.png
-rw-r--r-- 1 root root 48269 2009-02-19 00:20 eth1.old
-rw-r--r-- 1 root root 1509 2009-02-19 00:25 eth1-week.png
-rw-r--r-- 1 root root 1653 2009-02-18 23:55 eth1-year.png
-rw-r--r-- 1 root root 538 2009-02-18 23:15 mrtg-l.png
-rw-r--r-- 1 root root 414 2009-02-18 23:15 mrtg-m.png
-rw-r--r-- 1 root root 1759 2009-02-18 23:15 mrtg-r.png
Here is mrtg.cfg
PHP Code:
# This file is for use with mrtg-2.5.4c
WorkDir: /var/www/mrtg
EnableIPv6: no
Options[_]: bits,growright
Refresh: 300
XSize[eth0]: 600
YSize[eth0]: 300
RunAsDaemon: Yes
Title[eth0]: eth0 interface activity
Target[eth0]: `/usr/local/bin/ifstat.sh eth0`
MaxBytes[eth0]: 1250000
###################################################
WorkDir: /var/www/mrtg
EnableIPv6: no
Options[_]: bits,growright
Refresh: 300
RunAsDaemon: Yes
Title[192.168.168.11]: 192.168.168.11 traffic
Target[192.168.168.11]: `/usr/local/bin/checktraffic.sh`
MaxBytes[192.168.168.11]: 1250000
XSize[192.168.168.11]: 600
YSize[192.168.168.11]: 300
This is script for interface graph, mrtg gets everything(traffic,hostname and uptime) from it without problem
PHP Code:
#!/bin/bash
/sbin/ip -s link show dev $1|grep -A 1 RX|tail -n1 |awk '{print $1}'
/sbin/ip -s link show dev $1|grep -A 1 TX|tail -n1 |awk '{print $1}'
echo `uptime | awk '{ print $3,$4,$5 }' | sed 's/,//g'`
echo `hostname`
Script output :
PHP Code:
deb:~# /usr/local/bin/ifstat.sh eth0
484721675
25608561
12 days 2:09
deb
Here is script for IP graph, mrtg only create files, but dont put any data in them
PHP Code:
#!/bin/sh
iptables -L traffic_in -vnx | awk '{if (int($1)!=0) print $2}'
iptables -L traffic_out -vnx | awk '{if (int($1)!=0) print $2}'
echo `uptime | awk '{ print $3,$4,$5 }' | sed 's/,//g'`
echo `hostname`
Script output :
PHP Code:
deb:~# /usr/local/bin/checktraffic.sh
130887819
5588294
12 days 2:10
deb
Not even a word in mrtg.log about wrong paths ,errors ...nothing useful for debuging
Please give me an idea where to search my mistake.
SOLVED:
I dont know why, but when mrtg runs as daemon errors(or at least part of them) doesn't go in log file.So I started mrtg as cronjob and I see where is the problem
PHP Code:
2009-02-20 16:50:02: ERROR: Target[192.168.168.11][_OUT_] ' $target->[1]{$mode} ' did not eval into defined data
/usr/local/bin/checktraffic.sh: line 2: iptables: command not found
/usr/local/bin/checktraffic.sh: line 3: iptables: command not found
In checktraffic iptables was described without full path, so when I change
iptables -L traffic_in -vnx | awk '{if (int($1)!=0) print $2}'
to
/sbin/iptables -L traffic_in -vnx | awk '{if (int($1)!=0) print $2}'
problem was solved.