************************************************
MRTG
重新啟動
root@raspberrypi:/etc/init.d# mrtg
Daemonizing MRTG ...
root@raspberrypi:/etc/init.d# mrtg restart
http://www.supagusti.tk/computer/raspberrypi/160-installing-mrtg-on-your-pi
http://tonyhack.familyds.net/wordpress/?p=4176
http://www.supagusti.tk/computer/raspberrypi/160-installing-mrtg-on-your-pi
http://blog.itist.tw/2014/05/mrtg.html
http://resources.intenseschool.com/network-monitoring-with-mrtg-on-raspberry-pi/
https://www.dd-wrt.com/wiki/index.php/SNMP
https://wiki.openwrt.org/doc/howto/snmp.server
220.134.245.198—新店IP
mrtg 路徑
/var/www/html/mrtg
安裝步驟
su
apt-get install mtg
Creating a configuration file for a device using
cfgmaker giga1144@hckao.ddns.net >> /etc/mrtg.cfg
indexmaker /etc/mrtg.cfg > /var/www/html/mrtg/index.html
Make mrtg to run as a daemon:
Edit the /etc/mrtg.cfg and add the line “RunAsDaemon: YES” (see line 9 below)
1: ######################################################################
2: # Multi Router Traffic Grapher -- Sample Configuration File
3: ######################################################################
4: # This file is for use with mrtg-2.5.4c
5:
6: # Global configuration
7: WorkDir: /var/www/mrtg
8: WriteExpires: Yes
9: RunAsDaemon: Yes
Save and quit your editor and then create a file within the /etc/init.d directory and insert the following content:
1: PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
2: DAEMON="/usr/bin/mrtg"
3: PARAM=" --user=root /etc/mrtg.cfg --logging /var/log/mrtg.log"
4: NAME="MRTG"
5: DESC="Multi Router Traffic Grapher Daemon"
6:
7: test -f $DAEMON || exit 0
8:
9: set -e
10:
11: case "$1" in
12: start)
13: echo -n "Starting $DESC: "
14: env LANG=C $DAEMON $PARAM
15: echo "$NAME."
16: ;;
17: stop)
18: echo -n "Stopping $DESC: "
19: killall -9 mrtg
20: echo "$NAME."
21: ;;
22: restart|force-reload)
23: echo -n "Restarting $DESC: "
24: killall -9 mrtg
25: sleep 1
26: env LANG=C $DAEMON $PARAM
27: echo "$NAME."
28: ;;
29: *)
30: N=/etc/init.d/$NAME
31: echo "Usage: $N {start|stop|restart|force-reload}" >;&2
32: exit 1
33: ;;
34: esac
35:
36: exit 0
update-rc.d mrtg defaults
---------------------------------------------------------------------------------------------
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON="/usr/bin/mrtg"
PARAM=" --user=root /etc/mrtg.cfg --logging /var/log/mrtg.log"
NAME="MRTG"
DESC="Multi Router Traffic Grapher Daemon"
test -f $DAEMON || exit 0
set -e
case "$1" in
start)
echo -n "Starting $DESC: "
env LANG=C $DAEMON $PARAM
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
killall -9 mrtg
echo "$NAME."
;;
restart|force-reload)
echo -n "Restarting $DESC: "
killall -9 mrtg
sleep 1
env LANG=C $DAEMON $PARAM
echo "$NAME."
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|force-reload}" >;&2
exit 1
;;
esac
exit 0
---------------------------------------------------------------------------------------------
重新啟動
root@raspberrypi:/etc/init.d# mrtg
Daemonizing MRTG ...
root@raspberrypi:/etc/init.d# mrtg restart
root@raspberrypi:/etc# LANG=C /usr/bin/mrtg
Daemonizing MRTG ...
root@raspberrypi:/etc#
cfgmaker 9a1782@220.134.245.198 >> /etc/mrtg.cfg
indexmaker /etc/mrtg.cfg > /var/www/html/mrtg/index.html
https://linoxide.com/linux-how-to/install-configure-mrtg-ubuntu/
$ sudo apt-get install mrtg
# mkdir /var/www/mrtg
# chown -R www-data:www-data /var/www/mrtg
Then edit /etc/mrtg.conf to set Working directory:
# cat /etc/mrtg.cfg | grep -v "^#"
WorkDir: /var/www/mrtg
WriteExpires: Yes
Title[^]: Traffic Analysis for
Rebuild MRTG configuration from modified file:
# cfgmaker public@localhost > /etc/mrtg.cfg
--base: Get Device Info on public@localhost:
--base: Vendor Id: Unknown Vendor - 1.3.6.1.4.1.8072.3.2.10
--base: Populating confcache
--base: Get Interface Info
--base: Walking ifIndex
--snpd: public@localhost: -> 1 -> ifIndex = 1
--snpd: public@localhost: -> 2 -> ifIndex = 2
--snpd: public@localhost: -> 3 -> ifIndex = 3
--base: Walking ifType
--snpd: public@localhost: -> 1 -> ifType = 24
--snpd: public@localhost: -> 2 -> ifType = 6
--snpd: public@localhost: -> 3 -> ifType = 6
--base: Walking ifAdminStatus
--snpd: public@localhost: -> 1 -> ifAdminStatus = 1
--snpd: public@localhost: -> 2 -> ifAdminStatus = 1
--snpd: public@localhost: -> 3 -> ifAdminStatus = 1
--base: Walking ifOperStatus
--snpd: public@localhost: -> 1 -> ifOperStatus = 1
--snpd: public@localhost: -> 2 -> ifOperStatus = 1
--snpd: public@localhost: -> 3 -> ifOperStatus = 1
--base: Walking ifMtu
--snpd: public@localhost: -> 1 -> ifMtu = 65536
--snpd: public@localhost: -> 2 -> ifMtu = 1500
--snpd: public@localhost: -> 3 -> ifMtu = 1500
--base: Walking ifSpeed
--snpd: public@localhost: -> 1 -> ifSpeed = 10000000
--snpd: public@localhost: -> 2 -> ifSpeed = 0
--snpd: public@localhost: -> 3 -> ifSpeed = 0
# ls /var/www/mrtg/
index.html mrtg-l.png mrtg-m.png mrtg-r.png
Create index file for web server:
# indexmaker /etc/mrtg1.cfg > /var/www/html/mrtg/index.html
#sudo indexmaker --output=/var/www/html/mrtg/index.html /etc/mrtg1.cfg
#sudo env LANG=C /usr/bin/mrtg /etc/mrtg1.cfg
The last thing to do is create a VirtualHost file for the site.
# vim /etc/apache2/sites-available/mrtg.conf
Add the following to this new file:
Alias /mrtg "/var/www/mrtg/"
?Options None
AllowOverride None
Require all granted
Enable the site and reload apache service.
# sudo a2ensite mrtg
Reload Apache service:
# systemctl reload apache2
Configure MRTG to poll metrics every X minutes.
I'm going to create a cron job which checks for changes on the configuration fil e and generate new png images that can be viewed on the web interface. Make sure to create the cron job as the root user.
# crontab -e
*/5 * * * * root LANG=C LC_ALL=C /usr/bin/mrtg /etc/mrtg.cfg
My router's ip is : 192.168.1.123
sudo cfgmaker --output=/etc/mrtg.cfg public@192.168.1.123
sudo nano /etc/mrtg.cfg
add the following line under the global section:
RunAsDaemon: Yes
Interval: 5
sudo mkdir /var/www/mrtg
sudo indexmaker --output=/var/www/html/mrtg/index.html /etc/mrtg.cfg
STEP 4 : CONFIGURE APACHE
sudo apt-get install apache2
sudo nano /etc/apache2/apache2.conf
Add the following lines
Alias /mrtg "/var/www/mrtg/"
Options None
AllowOverride None
Require all granted
sudo service apache2 restart
STEP 5 : FINISHING THE INSTALLATION
sudo env LANG=C /usr/bin/mrtg /etc/mrtg1.cfg
hckao@xmini:~$ cat mrtg-txt
第一次
sudo cfgmaker --global "WorkDir: /var/www/html/mrtg" \
--global "Options[_]: growright,bits" \
kbt236@asuskao.ddns.net | grep -v "/var/www/html/mrtg" > /etc/mrtg .cfg
之後
sudo cfgmaker --global "WorkDir: /var/www/html/mrtg" \
--global "Options[_]: growright,bits" \
kbt236@hckao.ddns.net | grep -v "/var/www/html/mrtg" >> /etc/mrtg. cfg
sudo cfgmaker --global "WorkDir: /var/www/html/mrtg" \
--global "Options[_]: growright,bits" \
kbt236@xmini.ddns.net | grep -v "/var/www/html/mrtg" >> /etc/mrtg. cfg
indexmaker /etc/mrtg.cfg > /var/www/html/mrtg/index.html
*************************************
this file in /etc/init.d/mrtg
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON="/usr/bin/mrtg"
PARAM=" --user=root /etc/mrtg.cfg --logging /var/log/mrtg.log"
NAME="MRTG"
DESC="Multi Router Traffic Grapher Daemon"
test -f $DAEMON || exit 0
set -e
case "$1" in
start)
echo -n "Starting $DESC: "
env LANG=C $DAEMON $PARAM
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
killall -9 mrtg
echo "$NAME."
;;
restart|force-reload)
echo -n "Restarting $DESC: "
killall -9 mrtg
sleep 1
env LANG=C $DAEMON $PARAM
echo "$NAME."
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|force-reload}" >;&2
exit 1
;;
esac
exit 0
*****************************
sudo cfgmaker --global "WorkDir: /var/www/html/mrtg" \
--global "Options[_]: growright,bits" \
kbt236@asuskao.ddns.net | grep -v "/var/www/html/mrtg" > /etc/mrtg
sudo cfgmaker --global "WorkDir: /var/www/html/mrtg" \
--global "Options[_]: growright,bits" \
kbt236@asuskao.ddns.net > /etc/mrtg1
hckao@xmini:~$
@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#
@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#
sudo cfgmaker --global "WorkDir: /var/www/html/mrtg" \
--global "Options[_]: growright,bits" \
kbt236@asuskao.ddns.net | grep -v "/var/www/html/mrtg" > /etc/mrtg 1.cfg
@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#
sudo cfgmaker --global "WorkDir: /var/www/html/mrtg" \
--global "Options[_]: growright,bits" \
kbt236@192.168.1.190 | grep -v "/var/www/html/mrtg" >> /etc/mrtg1 .cfg
@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#
sudo cfgmaker --global "WorkDir: /var/www/html/mrtg" \
--global "Options[_]: growright,bits" \
giga1144@61.63.1.157 | grep -v "/var/www/html/mrtg" >> /etc/mrtg1. cfg
@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#
sudo cfgmaker --global "WorkDir: /var/www/html/mrtg" \
--global "Options[_]: growright,bits" \
giga1144@220.134.245.198 | grep -v "/var/www/html/mrtg" >> /etc/mr tg1.cfg
@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#
sudo cfgmaker --global "WorkDir: /var/www/html/mrtg" \
--global "Options[_]: growright,bits" \
kbt236@114.34.34.104 | grep -v "/var/www/html/mrtg" >> /etc/mrtg1. cfg
@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#
sudo cfgmaker --global "WorkDir: /var/www/html/mrtg" \
--global "Options[_]: growright,bits" \
kbt236@192.168.1.191 | grep -v "/var/www/html/mrtg" >> /etc/mrtg1. cfg
@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#
indexmaker /etc/mrtg1.cfg > /var/www/html/mrtg/index.html
sudo env LANG=C /usr/bin/mrtg /etc/mrtg1.cfg
Log檔 第一筆只會有三欄資料
第一欄 時間(seconds),
第二欄 自設備開機流入量總和 (bytes per second)
第三欄 自設備開機流出量總和 (bytes per second)
第二筆開始會有五欄資料
第一欄 時間
第二欄 平均流進量
第三欄 平均流出量
第四欄 最大流進量
第五欄 最大流出量
第一欄為時間,從1970年一月一日開始算,
可以在excel裡用以下的公式轉換:
(x+y)/86400+DATE(1970,1,1),其中 x 為第一欄 時間的數值,
y為所在地區與格林威治時間的位移,
以台灣的位移來算。
八個小時相當於28800秒,所以公式為 (x+28800)/86400+DATE(1970,1,1),
第二、三、四、五欄所紀錄的數值單位都是每秒的流量,
經過換算之後就可以得到實際的流量。(把值除以125000可得是多少Mb/s)
每五鐘值存 603 筆,再來是 (5x603/60/24=2.09735天)
30 分鐘存 603 筆 ( 30x603/60/24=12.5625 天)
2 小時值存 603 筆 50.25 天
一天值存 800 筆 800天
所以是保留共 2.37年
流量分析要注意的地方就是取值的範圍:
DAILY( 2~ 600 每隔5分鐘): Mrtg畫圖取2~401格即33.3小時, 即第二列 至 第401 列
WEEKLY( 601~ 1200 每隔30分鐘)
MONTHLY( 1201~ 1800 每隔2小時)
YEARLY( 1801~ 2538 每隔24小時)
隞乩舫啣mrtg 瘚蝔
hckao@H96PLUS:~$ cd /etc/init.d
hckao@H96PLUS:/etc/init.d$ ps -ax | grep mrtg
3223 ? Ss 0:00 /usr/bin/perl -w /usr/bin/mrtg /etc/mrtg.cfg
3578 pts/0 S+ 0:00 grep --color=auto mrtg
hckao@H96PLUS:/etc/init.d$ sudo kill 3223
hckao@H96PLUS:/etc/init.d$ sudo env LANG=C /usr/bin/mrtg /etc/mrtg.cfg
Daemonizing MRTG ...
hckao@H96PLUS:/etc/init.d$